From 1bcd7de0d09c8fa9af78811479a0ac8195ca566e Mon Sep 17 00:00:00 2001 From: SouthFox Date: Mon, 6 Jan 2025 16:56:24 +0800 Subject: [PATCH] [feat] build font subset file --- utils.hy | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/utils.hy b/utils.hy index 2b248f9..29e9d25 100644 --- a/utils.hy +++ b/utils.hy @@ -1,6 +1,7 @@ #!/usr/bin/env hy (import requests) +(import argparse) (import sys) (import os) (import json) @@ -18,6 +19,24 @@ (let [file (os.path.join root -file)] (when (and (in "posts" file) (file.endswith ".md")) (markdown-files.append file)))) - (print markdown-files)) + (return markdown-files)) -(get-post-files) +(defn subset-font-file [post-files] + (let [str-set #{}] + (for [f post-files] + (with [o (open f "r" :encoding "utf-8")] + (for [w (o.read)] + (str-set.add w)))) + + (print f"{(len str-set)} characters in all files.") + (print (.join "" str-set)) + (with [f (open "strdb.txt" "w")] + (f.write (.join "" str-set))))) + +(setv parser (argparse.ArgumentParser)) +(parser.add_argument "-d" :dest "deploy" :action "store_true") +(setv args (parser.parse_args)) + +(when args.deploy + (let [post-files (get-post-files)] + (subset-font-file post-files)))