diff options
| author | nsfisis <nsfisis@gmail.com> | 2022-11-20 21:42:50 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2022-11-20 22:20:42 +0900 |
| commit | 75402b673c0f630b620904ce3153f8645d89d700 (patch) | |
| tree | 18dc3e091765267fbd59c4f76702a827c69c1eed /lib/command.rb | |
| parent | a0738cdd46d6e52463687b903b1e7d09a541aaa1 (diff) | |
| download | blog.nsfisis.dev-75402b673c0f630b620904ce3153f8645d89d700.tar.gz blog.nsfisis.dev-75402b673c0f630b620904ce3153f8645d89d700.tar.zst blog.nsfisis.dev-75402b673c0f630b620904ce3153f8645d89d700.zip | |
implement cache busting for stylesheets
Diffstat (limited to 'lib/command.rb')
| -rw-r--r-- | lib/command.rb | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/lib/command.rb b/lib/command.rb index 81692b3..5662eec 100644 --- a/lib/command.rb +++ b/lib/command.rb @@ -4,9 +4,11 @@ module NulDoc @config = config @content_dir = @config[:content_dir] @dest_dir = @config[:dest_dir] + @static_dir = @config[:static_dir] @template_dir = @config[:template_dir] @parser = NulDoc::Parser.new( { + 'stylesheets' => stylesheets, 'author' => @config[:author], 'site-copyright-year' => @config[:site_copyright_year], 'site-name' => @config[:site_name], @@ -43,7 +45,7 @@ module NulDoc end def parse_posts(post_file_paths) - post_file_paths.map { @parser.parse_file(_1) } + post_file_paths.map { @parser.parse_file(_1, 'post') } end def output_posts(posts) @@ -92,8 +94,9 @@ module NulDoc end def build_tag_doc(tag, posts) - erb = ERB.new(File.read(@template_dir + '/tag.html.erb')) + erb = ERB.new(File.read(@template_dir + '/tag.html.erb'), trim_mode: '<>') erb.result_with_hash({ + stylesheets: stylesheets, tag: tag, posts: posts, author: @config[:author], @@ -124,8 +127,9 @@ module NulDoc end def build_posts_list_doc(posts) - erb = ERB.new(File.read(@template_dir + '/posts_list.html.erb')) + erb = ERB.new(File.read(@template_dir + '/posts_list.html.erb'), trim_mode: '<>') erb.result_with_hash({ + stylesheets: stylesheets, posts: posts.reverse, author: @config[:author], site_copyright_year: @config[:site_copyright_year], @@ -148,5 +152,14 @@ module NulDoc f.puts(html) end end + + def stylesheets + stylesheet_file_names = %w[hl.css style.css custom.css] + stylesheet_file_names.map {|ss_file_name| + ss_file_path = "#{@static_dir}/#{ss_file_name}" + hash = Digest::MD5.file(ss_file_path).hexdigest + "/#{ss_file_name}?#{hash}" + } + end end end |
