Verified Commit 7ce4d965 authored by Aral Balkan's avatar Aral Balkan
Browse files

Save last updated timestamp to metadata

parent 9396de9d
......@@ -166,20 +166,21 @@ class Blockdown
@useContentCache = false
break
# Set up the content cache if we’re using it.
if @useContentCache
contentCacheCurrentModifiedTimesFile = path.join cacheDirectory, 'current-modified-times', 'content.json'
contentCachePreviousModifiedTimesFile = path.join cacheDirectory, 'previous-modified-times', 'content.json'
# Set up the content cache (we will use it, if nothing else, to calculate
# the last modified time for the metadata).
contentCacheCurrentModifiedTimesFile = path.join cacheDirectory, 'current-modified-times', 'content.json'
contentCachePreviousModifiedTimesFile = path.join cacheDirectory, 'previous-modified-times', 'content.json'
_contentCurrentModifiedTimes = fs.readFileSync contentCacheCurrentModifiedTimesFile, 'utf-8'
_contentPreviousModifiedTimes = fs.readFileSync contentCachePreviousModifiedTimesFile, 'utf-8'
_contentCurrentModifiedTimes = fs.readFileSync contentCacheCurrentModifiedTimesFile, 'utf-8'
_contentPreviousModifiedTimes = fs.readFileSync contentCachePreviousModifiedTimesFile, 'utf-8'
@contentHasNotChanged = _contentCurrentModifiedTimes == _contentPreviousModifiedTimes
@contentHasNotChanged = _contentCurrentModifiedTimes == _contentPreviousModifiedTimes
@contentCurrentModifiedTimes = JSON.parse(_contentCurrentModifiedTimes)
@contentPreviousModifiedTimes = JSON.parse(_contentPreviousModifiedTimes)
@contentCurrentModifiedTimes = JSON.parse(_contentCurrentModifiedTimes)
@contentPreviousModifiedTimes = JSON.parse(_contentPreviousModifiedTimes)
# Inform person if we are using the content cache.
if @useContentCache
console.log "\t✓ No changes to theme templates; using cache."
......@@ -804,10 +805,25 @@ Better is a Safari content blocker for <a href='https://itunes.apple.com/us/app/
args = if app.isRunningInDevelopment then [@rules, null, 4] else [@rules]
output = JSON.stringify.apply @, args
hash = checksum(output)
#
# Prepare metadata
#
# Calculate the last update time based on the content cache.
# Since timestamps have lexographical order, we can use a reduce
# on the values of the cache dictionary to achieve this.
# (Using ES6) as it is easier. (And we will move the codebase to ES6 eventually.)
lastModifiedTimes = `Object.values(this.contentCurrentModifiedTimes)`
lastModifiedTime = `lastModifiedTimes.reduce ((x,y) => { return (x > y ? x : y) })`
metadata = JSON.stringify({
md5: hash,
# timestamp:
lastUpdated: lastModifiedTime
})
# Save the blocker list file and its metadata.
(fs.outputFileAsync blockerListJSONFilePath, output).then =>
fs.outputFileAsync metadataFilePath, metadata
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment