📦 Update dependencies and enhance functionality for markdown rendering

The changes include updates to dependencies in `Cargo.lock` and `Cargo.toml`, along with enhancements to the markdown rendering script:

1. Added new dependencies: `reqwest` for HTTP requests and `rust_util` for utility functions.
2. Modified `main.rs` to support reading from both local files and URLs, improving flexibility.
3. Updated metadata files (`script-meta-v2.json` and `script-meta.json`) to reflect changes in script size and hash.

These updates expand the script's capabilities while ensuring compatibility with existing features.
This commit is contained in:
2026-04-12 23:59:23 +08:00
parent 1f052b8b32
commit 5ec214b923
6 changed files with 1777 additions and 20 deletions

13
justfile Normal file
View File

@@ -0,0 +1,13 @@
_:
@just --list
alias pub:=publish
alias p:=publish
# Publish
publish:
ls | grep -v update-meta-rs | grep '\-rs$' > file-meta.txt
./update-meta-rs/src/main.rs
./update-meta-v1.rs
commit.ts --auto-commit

1724
md-rs/Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@@ -4,4 +4,6 @@ version = "0.1.0"
edition = "2024"
[dependencies]
reqwest = { version = "0.13.2", features = ["blocking"] }
rust_util = "0.6.51"
termimad = "0.34.1"

View File

@@ -2,6 +2,8 @@
//! ```cargo
//! [dependencies]
//! reqwest = { version = "0.13.2", features = ["blocking"] }
//! rust_util = "0.6.51"
//! termimad = "0.34.1"
//! ```
@@ -12,22 +14,20 @@
// skin.italic.add_attr(Underlined);
// println!("\nand now {}\n", skin.inline("a little *too much* **style!** (and `some(code)` too)"));
use std::fs;
use rust_util::{opt_result, warning, XResult};
use std::io::Read;
use std::{fs, io};
// https://github.com/Canop/termimad
fn main() {
let args = std::env::args().skip(1).collect::<Vec<_>>();
if args.is_empty() {
println!("Usage: md.rs <path>");
return;
}
if args.len() > 1 {
println!("[ERROR] Only support 1 md file");
println!("[ERROR] Only support 1 md URL or file");
return;
}
match fs::read_to_string(&args[0]) {
let first_arg = args.first();
match read_to_string(first_arg) {
Ok(md) => {
// termimad::print_inline(&md);
termimad::print_text(&md);
}
Err(e) => {
@@ -36,5 +36,33 @@ fn main() {
}
}
// @SCRIPT-SIGNATURE-V1: yk-r1.ES256.20260411T233243+08:00.MEUCIDN8Gn/U6U95quVMM2wU
// XhZj2nIQmDzmtQ3gSjrVT0SdAiEAlFYvzjgxODM2dPiYVUsCcIwgMpNQbDXk9n67b5wq0J8=
fn read_to_string(path_opt: Option<&String>) -> XResult<String> {
match path_opt {
None => {
let mut buffer = String::new();
io::stdin().read_to_string(&mut buffer)?;
Ok(buffer)
}
Some(path) => {
let is_http_path = path.starts_with("http://");
let is_https_path = path.starts_with("https://");
if is_http_path || is_https_path {
if is_http_path {
warning!("Unsecure path: ${path}")
}
Ok(opt_result!(
reqwest::blocking::get(path)?.text(),
"Get {path} failed: {}"
))
} else {
Ok(opt_result!(
fs::read_to_string(path),
"Read {path} failed: {}"
))
}
}
}
}
// @SCRIPT-SIGNATURE-V1: yk-r1.ES256.20260412T235541+08:00.MEUCID7zWIZ1zyjpISPbbROS
// X+wrb0hfpeWaan8mYIaG9hoaAiEAw1jj2TvjDx0Y6egXTfpIQD5XzW91sutNjSz62Nc9taI=

View File

@@ -82,11 +82,11 @@
},
"md.rs": {
"script_name": "md.rs",
"script_length": 1131,
"script_sha256": "7e58d843fc03cb35eba917a4d1f32be55d4f66e24ef776769d7cd50b6ab3a5ba",
"script_length": 2081,
"script_sha256": "d4723b7f59bd9e805a4a482e3107f2f30ec70d24d8efb3717b7bc7008a1cc67b",
"script_full_url": "https://git.hatter.ink/rust-scripts/scriptbase/raw/branch/main/md-rs/src/main.rs",
"publish_time": 1775921621093,
"update_time": 1775921621093
"update_time": 1776009548379
},
"myip.rs": {
"script_name": "myip.rs",

View File

@@ -46,8 +46,8 @@
},
"md-rs": {
"script_name": "md-rs",
"script_length": 1131,
"script_sha256": "7e58d843fc03cb35eba917a4d1f32be55d4f66e24ef776769d7cd50b6ab3a5ba"
"script_length": 2081,
"script_sha256": "d4723b7f59bd9e805a4a482e3107f2f30ec70d24d8efb3717b7bc7008a1cc67b"
},
"myip-rs": {
"script_name": "myip-rs",