|
3 | 3 | require "fileutils" |
4 | 4 | require "tmpdir" |
5 | 5 | require "uri" |
| 6 | +require "digest" |
6 | 7 |
|
7 | 8 | root = File.expand_path("..", __dir__) |
8 | 9 | cache = File.join(root, ".cloudflare") |
@@ -40,6 +41,15 @@ public_paths.each do |entry| |
40 | 41 | html = html.gsub(/^[ \t]*<script\b[^>]*src=["']https:\/\/plausible\.io\/[^"']+["'][^>]*>\s*<\/script>\s*\n?/i, "") |
41 | 42 | html = html.sub("</head>", " <meta name=\"robots\" content=\"noindex, nofollow\">\n </head>") |
42 | 43 | html = html.sub('<meta property="og:url" content="https://omarchy.org/">', '<meta property="og:url" content="https://omarchy.rudyr.com/">') if relative == "index.html" |
| 44 | + # Fingerprint entry URLs so existing preview visitors cannot mix an old |
| 45 | + # cached stylesheet/script with new HTML. Source filenames stay unchanged. |
| 46 | + html = html.gsub(/((?:href|src)=["'])(\/assets\/[^"'?#]+\.(?:css|js))(["'])/) do |
| 47 | + opening, path, closing = Regexp.last_match.captures |
| 48 | + asset = File.join(root, path) |
| 49 | + abort "Missing linked entry asset: #{path}" unless File.file?(asset) |
| 50 | + version = Digest::SHA256.file(asset).hexdigest[0, 12] |
| 51 | + "#{opening}#{path}?v=#{version}#{closing}" |
| 52 | + end |
43 | 53 | File.write(target, html) |
44 | 54 | else |
45 | 55 | FileUtils.cp(file, target) |
|
50 | 60 |
|
51 | 61 | File.write(File.join(output, "_headers"), <<~HEADERS) |
52 | 62 | /* |
| 63 | + Cache-Control: no-cache |
53 | 64 | X-Robots-Tag: noindex, nofollow |
54 | 65 | X-Content-Type-Options: nosniff |
55 | 66 | Referrer-Policy: strict-origin-when-cross-origin |
|
0 commit comments