Skip to content

Commit a2596b0

Browse files
authored
update
1 parent e6326c9 commit a2596b0

11 files changed

Lines changed: 145 additions & 53 deletions

File tree

_config.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ include:
5050
exclude:
5151
- README.md
5252
- LICENSE
53+
- tsconfig.json
5354
- tsconfig.node.json
5455
- package.json
5556
- package-lock.json
@@ -336,7 +337,6 @@ post_process:
336337
/assets/js/main.min.js:
337338
- /assets/js/settings.js
338339
- /assets/js/theme.js
339-
- /assets/js/meta.js
340340
- /assets/js/vendor/jquery/jquery-3.6.0.js
341341
- /assets/js/plugins/gumshoe.js
342342
- /assets/js/plugins/jquery.ba-throttle-debounce.js
@@ -345,15 +345,16 @@ post_process:
345345
- /assets/js/plugins/jquery.magnific-popup.js
346346
- /assets/js/plugins/smooth-scroll.js
347347
- /assets/js/plugins/jquery.auto-redirect.js
348+
- /assets/js/meta.ts.js
348349
- /assets/js/_main.js
349350
remove_dirs:
350351
- /assets/images/
351352
- /assets/js/lunr/
352353
- /assets/js/vendor/
353354
- /assets/js/plugins/
354355
remove_files:
355-
- /assets/js/meta.js
356356
- /assets/js/_main.js
357357
- /assets/js/theme.js
358+
- /assets/js/meta.ts.js
358359
- /assets/js/settings.js
359360
- /assets/js/main.min.js.map

_plugins/kramdown_enhancer.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
module KramdownEnhancer
2+
CACHE = Jekyll::Cache.new("KramdownEnhancer")
23
GITHUB_LINK_REGEX = /\b(GP-\d+|GC-[0-9a-f]{7})\b/
34
BLOCKQUOTE_TYPES = {
45
note: "notice--info",
@@ -167,7 +168,6 @@ def relative_url(input)
167168
end
168169

169170
Jekyll::Hooks.register :site, :post_read do |site|
170-
cache = Jekyll::Cache.new("KramdownEnhancer")
171171
KramdownEnhancer.baseurl = site.config["baseurl"]
172172
webp_list = []
173173
site.each_site_file do |file|
@@ -181,15 +181,15 @@ def relative_url(input)
181181
elsif %w[.png .jpg .jpeg .tif .tiff].include?(file.extname.downcase)
182182
source_base64 = Base64.encode64(File.read(file.path, mode: "rb"))
183183
hash = Digest::SHA256.hexdigest(source_base64)
184-
if cache.key?("webp_#{hash}")
184+
if KramdownEnhancer::CACHE.key?("webp_#{hash}")
185185
Jekyll.logger.info "Kramdown Enhancer:", "[webp] Hit Cache #{url}"
186186
else
187187
destination_base64 = Script.call("webp", source: source_base64)
188-
cache["webp_#{hash}"] = Base64.decode64(destination_base64)
188+
KramdownEnhancer::CACHE["webp_#{hash}"] = Base64.decode64(destination_base64)
189189
Jekyll.logger.info "Kramdown Enhancer:", "[webp] Generated #{url}"
190190
end
191191
FileUtils.mkdir_p(File.dirname(destination))
192-
File.write(destination, cache["webp_#{hash}"], mode: "wb")
192+
File.write(destination, KramdownEnhancer::CACHE["webp_#{hash}"], mode: "wb")
193193
webp_list.push(KramdownEnhancer::WebpFile.new(site, site.dest, File.dirname(url), File.basename(url)))
194194
KramdownEnhancer.webp[file.url] = url
195195
end

_plugins/post_process.rb

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22
config = site.config["post_process"]
33
next unless config
44

5+
cache = nil
56
terser = config["terser"]
67
if terser.is_a?(Hash)
78
terser.each do |terser_output, terser_inputs|
89
next unless terser_output.is_a?(String) && terser_inputs.is_a?(Array)
910

11+
cache = Jekyll::Cache.new("PostProcess") unless cache
1012
terser_codes = []
1113
terser_inputs_all_exist = true
1214
terser_inputs.each do |file|
@@ -21,7 +23,12 @@
2123

2224
if terser_inputs_all_exist
2325
destination = File.join(site.dest, terser_output.to_s)
24-
File.write(destination, Script.call("terser", code: terser_codes.join(";")))
26+
code = terser_codes.join(";")
27+
hash = Digest::SHA256.hexdigest(code)
28+
unless cache.key?("terser_#{hash}")
29+
cache["terser_#{hash}"] = Script.call("terser", code: code)
30+
end
31+
File.write(destination, cache["terser_#{hash}"])
2532
Jekyll.logger.info "Post Process:", "[terser] #{terser_output}"
2633
end
2734
end
@@ -44,4 +51,23 @@
4451
Jekyll.logger.info "Post Process:", "[remove_dirs] #{dir}"
4552
end
4653
end
54+
55+
# clean history jekyll cache
56+
jekyll_cache_dir = File.dirname(site.cache_dir)
57+
current_cache_name = File.basename(site.cache_dir)
58+
if File.basename(jekyll_cache_dir) == ".jekyll-cache"
59+
Dir.entries(jekyll_cache_dir).select do |entry|
60+
next if entry == "." || entry == ".."
61+
entry_path = File.join(jekyll_cache_dir, entry)
62+
if File.file?(entry_path)
63+
File.delete(entry_path)
64+
Jekyll.logger.info "Post Process:", "[clean_history_jekyll_cache] #{entry}"
65+
elsif File.directory?(entry_path)
66+
if entry < current_cache_name
67+
FileUtils.rm_rf(entry_path)
68+
Jekyll.logger.info "Post Process:", "[clean_history_jekyll_cache] #{entry}"
69+
end
70+
end
71+
end
72+
end
4773
end

_plugins/script.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
module Script
22
class << self
3-
attr_reader :runtime
4-
53
def init
64
begin
75
stdout, _, status = Open3.capture3("bun", "-v")
@@ -27,7 +25,7 @@ def call(name, param)
2725
raise stderr unless status.success?
2826
log, _, result = stdout.rpartition(uuid)
2927
log.split("\n").map do |line|
30-
Jekyll.logger.info "Script:", "[log] #{line}"
28+
Jekyll.logger.info "Script:", "[#{name}] #{line}"
3129
end
3230
JSON.parse(result)
3331
end

_plugins/scripts/terser.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import fs from "fs";
2-
import path from "path";
31
import { minify } from "terser";
42

53
export default async function ({ code }) {

_plugins/scripts/typescript.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import ts from "typescript";
2+
3+
export default function ({ code }) {
4+
const input = "index.ts";
5+
const output = "index.js";
6+
7+
const sources = new Map([[input, code]]);
8+
const results = new Map();
9+
10+
ts.createProgram([input], {
11+
module: ts.ModuleKind.ESNext,
12+
target: ts.ScriptTarget.ESNext,
13+
noResolve: true,
14+
}, {
15+
getSourceFile: function (fileName, languageVersion, _onError) {
16+
const sourceText = this.readFile(fileName);
17+
return sourceText !== undefined
18+
? ts.createSourceFile(fileName, sourceText, languageVersion)
19+
: undefined;
20+
},
21+
getDefaultLibFileName: (defaultLibOptions) => "/" + ts.getDefaultLibFileName(defaultLibOptions),
22+
writeFile: (fileName, content) => results.set(fileName, content),
23+
getCurrentDirectory: () => "/",
24+
getDirectories: (_path) => [],
25+
fileExists: () => true,
26+
readFile: (fileName) => sources.get(fileName),
27+
getCanonicalFileName: (fileName) => fileName,
28+
useCaseSensitiveFileNames: () => true,
29+
getNewLine: () => "\n",
30+
getEnvironmentVariable: () => "",
31+
resolveModuleNames: () => [],
32+
}).emit();
33+
34+
return results.get(output);
35+
}

_plugins/typescript.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class TypescriptConverter < Jekyll::Converter
2+
CACHE = Jekyll::Cache.new("TypescriptConverter")
3+
4+
def matches(ext)
5+
ext =~ /^\.ts$/i
6+
end
7+
8+
def output_ext(ext)
9+
"#{ext}.js"
10+
end
11+
12+
def convert(content)
13+
hash = Digest::SHA256.hexdigest(content)
14+
unless TypescriptConverter::CACHE.key?(hash)
15+
TypescriptConverter::CACHE[hash] = Script.call("typescript", code: content)
16+
end
17+
TypescriptConverter::CACHE[hash]
18+
end
19+
end

assets/js/meta.js

Lines changed: 0 additions & 40 deletions
This file was deleted.

assets/js/meta.ts

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
---
2+
layout: null
3+
---
4+
5+
interface Window {
6+
$: JQueryStatic;
7+
appendMeta: (text: string, icon: string) => void;
8+
hits: (tag: string) => void;
9+
settings: {
10+
get: (key: string) => string;
11+
};
12+
}
13+
14+
(() => {
15+
const $header = $("#main article.page div.page__inner-wrap > header");
16+
if ($header.length !== 0) {
17+
let $metas = $header.children(".page__meta");
18+
if (!$metas.length) {
19+
$metas = $('<div class="page__meta"></div>');
20+
$header.append($metas);
21+
}
22+
window.appendMeta = (text, icon) => {
23+
if ($metas.children().length !== 0) {
24+
$metas.append('<span class="page__meta-sep"></span>');
25+
}
26+
const $meta = $("<span>");
27+
if (icon) {
28+
$meta.append($("<i>").addClass(icon), " ");
29+
}
30+
$meta.append(text.trim());
31+
$metas.append($meta);
32+
};
33+
window.hits = (tag) => {
34+
if (window.settings.get("miscellaneous_hits") === "disable") return;
35+
const hitsUrl = new URL("https://hits.zkitefly.eu.org");
36+
hitsUrl.searchParams.set("tag", tag);
37+
fetch(hitsUrl, { method: "HEAD" }).then((response) => {
38+
if (response.status !== 200) return;
39+
const { headers } = response;
40+
const total = headers.get("X-Total-Hits");
41+
const today = headers.get("X-Today-Hits");
42+
if (total !== null && today !== null) {
43+
window.appendMeta(today + " / " + total, "far fa-eye");
44+
}
45+
});
46+
};
47+
}
48+
})();

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"@types/jquery": "3.5.34",
55
"@types/node": "25.9.1",
66
"sharp": "0.34.5",
7-
"terser": "^5.48.0",
7+
"terser": "5.48.0",
88
"typescript": "6.0.3"
99
},
1010
"type": "module"

0 commit comments

Comments
 (0)