🔍 Enhance cheat sheet filtering and update script metadata hashes

This commit is contained in:
2026-04-13 00:45:48 +08:00
parent 124492d408
commit 50c949a910
3 changed files with 26 additions and 10 deletions

View File

@@ -72,8 +72,8 @@ fn read_to_string(path_opt: Option<&String>) -> XResult<String> {
}
let path = if let Some(cheat_sheet_name) = try_cheat_sheet(path) {
if cheat_sheet_name.is_empty() {
print_cheat_sheet_meta();
if cheat_sheet_name.is_empty() || cheat_sheet_name.starts_with("~") {
print_cheat_sheet_meta(&cheat_sheet_name);
}
format!(
"https://git.hatter.ink/hatter/cheatsheets/raw/branch/main/{cheat_sheet_name}/CHEATSHEET.md"
@@ -111,7 +111,7 @@ struct CheatSheetMeta {
description: String,
}
fn print_cheat_sheet_meta() -> ! {
fn print_cheat_sheet_meta(filter: &str) -> ! {
let cheat_sheet_meta_url =
"https://git.hatter.ink/hatter/cheatsheets/raw/branch/main/meta.json";
let cheat_sheet_meta_json = reqwest::blocking::get(cheat_sheet_meta_url)
@@ -121,11 +121,27 @@ fn print_cheat_sheet_meta() -> ! {
let cheat_sheet_meta: Vec<CheatSheetMeta> =
serde_json::from_str(&cheat_sheet_meta_json).expect("Parse cheat sheet meta failed");
let f = if !filter.is_empty() {
let f = filter.chars().skip(1).collect::<String>();
Some(f)
} else {
None
};
let mut cheat_sheet_md = String::new();
cheat_sheet_md.push_str("# Cheat Sheets\n\n");
if let Some(f) = &f {
cheat_sheet_md.push_str(&format!("Filter: `{f}`\n"));
}
cheat_sheet_md.push_str("| Name | Description |\n");
cheat_sheet_md.push_str("| ----- | ------ |\n");
for cheat_sheet in &cheat_sheet_meta {
if let Some(f) = &f {
if !cheat_sheet.name.contains(f) && !cheat_sheet.description.to_lowercase().contains(f)
{
continue;
}
}
cheat_sheet_md.push_str(&format!(
"| {} | {} |\n",
cheat_sheet.name, cheat_sheet.description
@@ -145,5 +161,5 @@ fn try_cheat_sheet(path: &str) -> Option<String> {
None
}
// @SCRIPT-SIGNATURE-V1: yk-r1.ES256.20260413T003557+08:00.MEYCIQCNWXiO8eSLj0FI/N9e
// 5tJcQ7u1d2oMPO11BpAalYvFoQIhAIm1pcCiGctYL2jeon/WL4ihKEnHv2WdJyE55Nye+m3U
// @SCRIPT-SIGNATURE-V1: yk-r1.ES256.20260413T004508+08:00.MEUCIFSnP/5Ur0loaT+kYccv
// gRy1LUFkfDxCy5FM3/kowRdIAiEAze5uUmB82aAayo2YxdGYsMyusp1D51v9J9bcam+6GJA=

View File

@@ -82,11 +82,11 @@
},
"md.rs": {
"script_name": "md.rs",
"script_length": 4585,
"script_sha256": "1e2f9c06d7eceb71f56c8d245815deb144e8ad70662cd0f3701430425a822c28",
"script_length": 5085,
"script_sha256": "9ea5b616c849e999d606753c039356290a4a8ca65a4d4eddd65b2ac6708f8dae",
"script_full_url": "https://git.hatter.ink/rust-scripts/scriptbase/raw/branch/main/md-rs/src/main.rs",
"publish_time": 1775921621093,
"update_time": 1776011776921
"update_time": 1776012346584
},
"myip.rs": {
"script_name": "myip.rs",

View File

@@ -46,8 +46,8 @@
},
"md-rs": {
"script_name": "md-rs",
"script_length": 4585,
"script_sha256": "1e2f9c06d7eceb71f56c8d245815deb144e8ad70662cd0f3701430425a822c28"
"script_length": 5085,
"script_sha256": "9ea5b616c849e999d606753c039356290a4a8ca65a4d4eddd65b2ac6708f8dae"
},
"myip-rs": {
"script_name": "myip-rs",