Commit 484367d6 authored by Julius Volz's avatar Julius Volz

Merge pull request #374 from prometheus/cachebusting

Add cachebusting fingerprints to asset files.
parents 597dce44 e40149e3
...@@ -12,3 +12,4 @@ gem 'builder' ...@@ -12,3 +12,4 @@ gem 'builder'
gem 'rb-inotify', :require => false gem 'rb-inotify', :require => false
gem 'rb-fsevent', :require => false gem 'rb-fsevent', :require => false
gem 'rb-fchange', :require => false gem 'rb-fchange', :require => false
gem 'nanoc-cachebuster'
...@@ -42,6 +42,8 @@ GEM ...@@ -42,6 +42,8 @@ GEM
multi_json (1.11.2) multi_json (1.11.2)
nanoc (3.7.3) nanoc (3.7.3)
cri (~> 2.3) cri (~> 2.3)
nanoc-cachebuster (0.3.1)
nanoc (>= 3.3.0)
nokogiri (1.6.3.1) nokogiri (1.6.3.1)
mini_portile (= 0.6.0) mini_portile (= 0.6.0)
posix-spawn (0.3.9) posix-spawn (0.3.9)
...@@ -75,6 +77,7 @@ DEPENDENCIES ...@@ -75,6 +77,7 @@ DEPENDENCIES
guard-nanoc guard-nanoc
kramdown kramdown
nanoc nanoc
nanoc-cachebuster
nokogiri nokogiri
pygments.rb pygments.rb
rb-fchange rb-fchange
......
...@@ -17,8 +17,13 @@ compile '/assets/*' do ...@@ -17,8 +17,13 @@ compile '/assets/*' do
end end
route '/assets/*' do route '/assets/*' do
# /assets/foo.html/ → /foo.html # Cachebuster currently doesn't fingerprint all needed files (SVG and font
# extensions are missing), so we need to differentiate here.
if Nanoc::Cachebuster::FILETYPES_TO_FINGERPRINT.include?(item[:extension])
item.identifier[0..-(3 + item[:extension].length)] + fingerprint(item[:filename]) + '.' + item[:extension]
else
item.identifier[0..-2] item.identifier[0..-2]
end
end end
route '/README/' do route '/README/' do
...@@ -40,7 +45,6 @@ compile '*' do ...@@ -40,7 +45,6 @@ compile '*' do
if item[:title] == 'README.md' if item[:title] == 'README.md'
# Don't filter; this should propagate verbatim to the output GitHub repository. # Don't filter; this should propagate verbatim to the output GitHub repository.
elsif item[:extension] == 'md' elsif item[:extension] == 'md'
#filter :kramdown
filter :redcarpet, options: {filter_html: true, autolink: true, no_intraemphasis: true, fenced_code_blocks: true, gh_blockcode: true, tables: true}, renderer_options: {with_toc_data: true} filter :redcarpet, options: {filter_html: true, autolink: true, no_intraemphasis: true, fenced_code_blocks: true, gh_blockcode: true, tables: true}, renderer_options: {with_toc_data: true}
filter :add_anchors filter :add_anchors
filter :bootstrappify filter :bootstrappify
...@@ -61,6 +65,8 @@ compile '*' do ...@@ -61,6 +65,8 @@ compile '*' do
else else
layout 'default' layout 'default'
end end
filter :cache_buster
end end
route '/blog/' do route '/blog/' do
...@@ -78,7 +84,7 @@ end ...@@ -78,7 +84,7 @@ end
route '*' do route '*' do
if item[:extension] == 'css' if item[:extension] == 'css'
# Write item with identifier /foo/ to /foo.css # Write item with identifier /foo/ to /foo.css
item.identifier.chop + '.css' item.identifier.chop + fingerprint(item[:filename]) + '.css'
elsif item.binary? elsif item.binary?
# Write item with identifier /foo/ to /foo.ext # Write item with identifier /foo/ to /foo.ext
item.identifier.chop + '.' + item[:extension] item.identifier.chop + '.' + item[:extension]
......
...@@ -39,7 +39,7 @@ ...@@ -39,7 +39,7 @@
<link href="/assets/bootstrap-3.3.1/css/bootstrap.min.css" rel="stylesheet"> <link href="/assets/bootstrap-3.3.1/css/bootstrap.min.css" rel="stylesheet">
<!-- Custom styles for this template --> <!-- Custom styles for this template -->
<link href="/assets/docs.css" rel="stylesheet"> <link href="/css/docs.css" rel="stylesheet">
<!-- Custom Fonts --> <!-- Custom Fonts -->
<link href="/assets/font-awesome-4.2.0/css/font-awesome.min.css" rel="stylesheet" type="text/css"> <link href="/assets/font-awesome-4.2.0/css/font-awesome.min.css" rel="stylesheet" type="text/css">
......
# All files in the 'lib' directory will be loaded # All files in the 'lib' directory will be loaded
# before nanoc starts compiling. # before nanoc starts compiling.
require 'nanoc/cachebuster'
include Nanoc::Helpers::LinkTo include Nanoc::Helpers::LinkTo
include Nanoc::Helpers::Rendering include Nanoc::Helpers::Rendering
include Nanoc3::Helpers::Blogging include Nanoc3::Helpers::Blogging
include Nanoc3::Helpers::Tagging include Nanoc3::Helpers::Tagging
include Nanoc::Helpers::CacheBusting
module BlogHelper module BlogHelper
def get_pretty_date(post) def get_pretty_date(post)
......
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