Skip to content

Commit

Permalink
Bypass GitHub's image cache:
Browse files Browse the repository at this point in the history
The problem appears to be that GitHub replaces all external images with a cache
stored on their servers. When using the Markdown API, these image URLs are still
replaced, but image doesn't always resolve. The effect is that sometimes images
are shown, and sometimes not. This is probably why #50 appeared to be resolved.

This fix makes sure the image is shown from the source, so it'll always
resolve (as long as it still exists on the original servers). A slightly better
fix would be to only handle images that error out, but that optimization will
be in a future fix.
  • Loading branch information
joeyespo committed Jul 27, 2014
1 parent 88fcc3f commit 77267ce
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions grip/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,19 @@

{%- block scripts -%}
<script>
function showCanonicalImages() {
var images = document.getElementsByTagName('img');
if (!images) {
return;
}
console.log(images);
for (var index = 0; index < images.length; index++) {
var image = images[index];
if (image.getAttribute('data-canonical-src')) {
image.src = image.getAttribute('data-canonical-src');
}
}
}
function scrollToHash() {
if (location.hash && !document.querySelector(":target")) {
var elements = document.getElementsByName('user-content-' + location.hash.slice(1));
Expand All @@ -46,6 +59,7 @@
window.onload = function() {
scrollToHash();
}
showCanonicalImages();
</script>
{%- endblock -%}

Expand Down

0 comments on commit 77267ce

Please sign in to comment.