Skip to content
This repository has been archived by the owner on Jan 3, 2023. It is now read-only.

Commit

Permalink
Replace img version fragment with version query
Browse files Browse the repository at this point in the history
Also if an image was previewed and subsequently deleted the version
query takes the value `deleted`.
  • Loading branch information
Galadirith committed Aug 6, 2015
1 parent 22d1fdc commit ea938bd
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions lib/renderer.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -109,19 +109,22 @@ resolveImagePaths = (html, filePath) ->
src = path.resolve(path.dirname(filePath), src)

# Use most recent version of image
if imgVersion[src]?
if imgVersion[src] > 0
src = "#{src}##{imgVersion[src]}"
else
imgVersion[src] = 0
srcClosure = (src) ->
return _.debounce(((event, path) ->
imgVersion[src] += 1
for item in atom.workspace.getPaneItems()
if isMarkdownPreviewView(item)
item.renderMarkdown()
return), 250)
pathWatcher.watch src, srcClosure(src)

srcClosure = (src) ->
return _.debounce(((event, path) ->
imgVersion[src] += 1
for item in atom.workspace.getPaneItems()
if isMarkdownPreviewView(item)
item.renderMarkdown()
return), 250)

if fs.isFileSync(src)
if not imgVersion[src]?
imgVersion[src] = 0
pathWatcher.watch src, srcClosure(src)
src = "#{src}?v=#{imgVersion[src]}"
else if imgVersion[src]?
src = "#{src}?v=deleted"

img.attr('src', src)

Expand Down

0 comments on commit ea938bd

Please sign in to comment.