Skip to content

Commit

Permalink
Digest asset file
Browse files Browse the repository at this point in the history
  • Loading branch information
yaodong committed Aug 14, 2024
1 parent ca48b2d commit 7d36349
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion _includes/head.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Merriweather:ital,wght@0,300;0,400;0,700;0,900;1,300;1,400;1,700;1,900&family=Mulish:ital,wght@0,200..1000;1,200..1000&display=swap" rel="stylesheet">
<link rel="stylesheet" href="{{ "/assets/stylesheets/application.css" | relative_url }}">
<link rel="stylesheet" href="{{ "/assets/stylesheets/application.css" | asset_digest }}">
19 changes: 19 additions & 0 deletions _plugins/asset_digest.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module Jekyll
module AssetDigest
def asset_digest(input)
site = @context.registers[:site]
file_path = site.in_source_dir(input.sub(/^\//, ''))

if File.exist?(file_path)
content = File.read(file_path)
hash = Digest::MD5.hexdigest(content)
Jekyll.logger.info "AssetDigest", "Generated: #{input} => #{hash}"
"#{input}?v=#{hash}"
else
input
end
end
end
end

Liquid::Template.register_filter(Jekyll::AssetDigest)

0 comments on commit 7d36349

Please sign in to comment.