Add bilingual public docs, keyword aliases, and frontmatter stdin for view.

English/Chinese user pages sit side by side; L0 builtins and lib/ text|表 dual APIs land with gold coverage. Capture/view input demos use stdin:/输入: so static export and first page load succeed.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
cflmyandCursor committed 2026-08-05 09:14:26 +08:00
1 parent fd36b92224
commit a5d30c00b3
68 files changed
+1812 -241

No files matched your search

+12 -2
View File
@@ -624,14 +624,24 @@ pub fn page_file(files: &[PathBuf], rel: &str, vm: &FileViewModel, links: &LinkM
LinkMode::Live => format!(
r#"<form class="stdin-form" method="get" action="/file">
<input type="hidden" name="path" value="{path}"/>
<label for="stdin">Preset input <span class="hint">one line per input call</span></label>
<label for="stdin">Preset input <span class="hint">one line per <code>input</code>; overrides frontmatter <code>stdin:</code> / <code>输入:</code></span></label>
<textarea id="stdin" name="stdin" rows="3" placeholder="Alice">{stdin}</textarea>
<button type="submit">Run with input</button>
</form>"#,
path = escape(rel),
stdin = escape(&vm.preset_stdin),
),
LinkMode::Static { .. } => String::new(),
LinkMode::Static { .. } => {
if vm.preset_stdin.is_empty() {
String::new()
} else {
format!(
r#"<p class="hint">Demo stdin from frontmatter (static export cannot re-run interactively):</p>
<pre class="source" style="margin-bottom:0.75rem">{stdin}</pre>"#,
stdin = escape(&vm.preset_stdin),
)
}
}
};
let title = Path::new(rel)
.file_name()
+11 -10
View File
@@ -14,7 +14,7 @@ use std::process::Command;
use anyhow::{bail, Context, Result};
use tiny_http::{Header, Method, Request, Response, Server, StatusCode};
use crate::input_feed::split_stdin_text;
use crate::input_feed::{effective_stdin, split_stdin_text};
use crate::view::html::{escape, page_file, page_index, LinkMode};
use crate::view::render::{render_module_structure, FileViewModel};
use crate::{run_file_capture, RunOptions};
@@ -172,8 +172,9 @@ pub(crate) fn build_file_view(
escape(&tidy_user_error(&format!("{e:#}"), abs, rel))
),
};
let effective = effective_stdin(&source, stdin_lines);
let opts = RunOptions {
stdin_lines: stdin_lines.to_vec(),
stdin_lines: effective.clone(),
..RunOptions::default()
};
let (stdout, stderr, ok) = match run_file_capture(abs, &opts) {
@@ -191,7 +192,7 @@ pub(crate) fn build_file_view(
stdout,
stderr,
ok,
preset_stdin: stdin_lines.join("\n"),
preset_stdin: effective.join("\n"),
})
}
@@ -277,33 +278,33 @@ fn query_param<'a>(query: &'a str, key: &str) -> Option<String> {
}
fn urlencoding_decode(s: &str) -> String {
// Minimal decode for %XX and +
let mut out = String::new();
// Minimal decode for %XX and + (UTF-8 byte sequences, not Latin-1 chars).
let mut out = Vec::new();
let bytes = s.as_bytes();
let mut i = 0;
while i < bytes.len() {
match bytes[i] {
b'+' => {
out.push(' ');
out.push(b' ');
i += 1;
}
b'%' if i + 2 < bytes.len() => {
let hex = &s[i + 1..i + 3];
if let Ok(v) = u8::from_str_radix(hex, 16) {
out.push(v as char);
out.push(v);
i += 3;
} else {
out.push('%');
out.push(b'%');
i += 1;
}
}
c => {
out.push(c as char);
out.push(c);
i += 1;
}
}
}
out
String::from_utf8_lossy(&out).into_owned()
}
fn files_json(files: &[PathBuf]) -> String {