Skip to content
This repository has been archived by the owner on Dec 28, 2022. It is now read-only.

feat: invalidate image cache #192

Merged
merged 3 commits into from
Jul 9, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions lib/renderer.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -93,17 +93,20 @@ resolveImagePaths = (html, filePath) ->
for imgElement in o('img')
img = o(imgElement)
if src = img.attr('src')
continue if src.match /^(https?|atom):\/\//
continue if src.startsWith process.resourcesPath
continue if src.startsWith resourcePath
continue if src.startsWith packagePath

if src[0] is '/'
appenderChar = if src.indexOf('?') is -1 then "?" else "&"
invalidateCache = "#{appenderChar}atomcache=#{Date.now()}"

if src.match /^(https?|atom):\/\// or
src.startsWith process.resourcesPath or
src.startsWith resourcePath or
src.startsWith packagePath
img.attr 'src', src + invalidateCache
else if src[0] is '/'
unless fs.isFileSync src
if rootDirectory
img.attr('src', path.join(rootDirectory, src.substring(1)))
img.attr 'src', path.join(rootDirectory, src.substring(1) + invalidateCache)
else
img.attr('src', path.resolve(path.dirname(filePath), src))
img.attr 'src', path.resolve(path.dirname(filePath), "#{src}#{invalidateCache}")

o.html()

Expand Down