diff --git a/Cargo.lock b/Cargo.lock index a0f9269..5b6582f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -872,6 +872,7 @@ dependencies = [ "axum", "futures-util", "getrandom 0.2.17", + "pulldown-cmark", "rusqlite", "serde", "serde_json", diff --git a/doc/roadmap/ext-web.md b/doc/roadmap/ext-web.md index cf98e43..45f2b7a 100644 --- a/doc/roadmap/ext-web.md +++ b/doc/roadmap/ext-web.md @@ -2,7 +2,7 @@ | | | |---|---| -| 状态 | **W0–W3.5 + 安全硬化已落地;内容标配 W4 进行中** | +| 状态 | **W0–W3.5 + 安全硬化 + 内容标配 W4c 已落地;Postgres/Redis W4 待** | | 日期 | 2026-08-11 | | **锁定设计** | [design/ext-web.md](../design/ext-web.md) | | 相关 | [ext-cli.md](../design/ext-cli.md) · [ext-abi.md](../design/ext-abi.md) · [ext-llm.md](../design/ext-llm.md) | @@ -29,7 +29,7 @@ | **W3s** | 安全硬化:argon2 密码哈希、CSRF、SQLite 会话持久化、CSPRNG、登录限速 | **done** | | **W3.5** | 人写面首版:`web.assemble` + `` `表`.`字段` `` + `examples/man-write-site` | **done**(编排袋仍可再瘦) | | **W4** | Postgres;Redis / S3 驱动 | pending | -| **W4c** | 内容标配:SEO / Markdown / RSS / 分页 UI(见 [web-net-capabilities.md](../design/web-net-capabilities.md)) | in progress | +| **W4c** | 内容标配:SEO / Markdown / RSS / 分页 UI(见 [web-net-capabilities.md](../design/web-net-capabilities.md)) | **done** | 验收金样:`tests/ext/web-smoke.mq.md`、`tests/ext/web-security-smoke.mq.md`、`ext_cli_add_web`。 diff --git a/ext/web/web.mq.md b/ext/web/web.mq.md index 6a0b3d9..b0971fb 100644 --- a/ext/web/web.mq.md +++ b/ext/web/web.mq.md @@ -90,6 +90,22 @@ of a list of cards. Set on the dynamic post page so `/post/{slug}` shows one pos **> web_page_detail page=`self` detail=`detail`** +## meta + + `meta` + +SEO / OpenGraph metadata as a data table (`|key|value|`). Keys such as `title`, `description`, `canonical`, `og:type` become `
` tags at render time. + +**> web_page_meta page=`self` meta=`meta`** + +## paginate + + `offset`=0 + + `limit`=10 + + `path`=/ + +List pagination for the main bind: sets DB `limit`/`offset` and renders previous/next navigation. + +**> web_page_paginate page=`self` offset=`offset` limit=`limit` path=`path`** + ## compose_form + `form` + `id` @@ -419,6 +435,19 @@ Keep the app's `admin=True`, and gate `/admin*` behind a login page. `users` is **> web_app_auth app=`self` users=`users` session_ttl=`session_ttl`** +## route_rss + + `path` + + `table` + + `limit`=20 + + `order`=-created_at + + `title`=Feed + + `link`=/ + + `description`="" + +Register an RSS 2.0 feed at `path` (e.g. `/feed.xml`) backed by a DB table. + +**> web_app_route_rss app=`self` path=`path` table=`table` limit=`limit` order=`order` title=`title` link=`link` description=`description`** + # auth + `users` + `session_ttl`=3600 diff --git a/ext/web/网页.mq.md b/ext/web/网页.mq.md index 05b0366..f64cbd1 100644 --- a/ext/web/网页.mq.md +++ b/ext/web/网页.mq.md @@ -81,6 +81,22 @@ import sys:lib/sys.mq.md **> web_page_detail page=`self` detail=`详情`** +## 元数据 + + `元数据` + +SEO / OpenGraph 元数据表(`|键|值|`)。如 `title`、`description`、`canonical`、`og:type` 等会在渲染时写入 ``。 + +**> web_page_meta page=`self` meta=`元数据`** + +## 分页 + + `偏移`=0 + + `上限`=10 + + `路径`=/ + +为主体列表绑定设置 DB 分页(`limit`/`offset`),并渲染上一页/下一页导航。 + +**> web_page_paginate page=`self` offset=`偏移` limit=`上限` path=`路径`** + ## 表单装配 + `表单` + `id` @@ -401,6 +417,19 @@ import sys:lib/sys.mq.md **> web_app_auth app=`self` users=`用户表` session_ttl=`会话时长`** +## 路由订阅 + + `路径` + + `表` + + `上限`=20 + + `排序`=-created_at + + `标题`=Feed + + `链接`=/ + + `描述`="" + +在 `路径`(如 `/feed.xml`)注册 RSS 2.0 订阅源,数据来自数据库表。 + +**> web_app_route_rss app=`self` path=`路径` table=`表` limit=`上限` order=`排序` title=`标题` link=`链接` description=`描述`** + # 鉴权 + `用户表` + `会话时长`=3600 diff --git a/lib/net.mq.md b/lib/net.mq.md index 806ce58..f78aa73 100644 --- a/lib/net.mq.md +++ b/lib/net.mq.md @@ -71,3 +71,10 @@ Parse a `Cookie` request header (default) or one or more `Set-Cookie` response h Parse a `multipart/form-data` request body (given its `boundary`) into a list of `{name, filename?, content_type?, value}` parts. **> host_multipart_parse body=`body` boundary=`boundary`** + +## markdown_parse + + `text` + +Parse Markdown / GFM into HTML (pure transform, no network I/O). + +**> host_markdown_parse text=`text`** diff --git a/lib/网络.mq.md b/lib/网络.mq.md index e7c98e4..e68e1cf 100644 --- a/lib/网络.mq.md +++ b/lib/网络.mq.md @@ -71,3 +71,10 @@ POST 并消费 OpenAI 兼容 SSE。返回 `{status, events}`(`delta` / `done` 解析 `multipart/form-data` 请求体(给定 `boundary`)为 `{name, filename?, content_type?, value}` 部件列表。 **> host_multipart_parse body=`正文` boundary=`边界`** + +## 解析Markdown + + `文本` + +将 Markdown / GFM 解析为 HTML(纯转换,无网络 I/O)。 + +**> host_markdown_parse text=`文本`** diff --git a/plugins/web/Cargo.toml b/plugins/web/Cargo.toml index 389f677..dcc5ee2 100644 --- a/plugins/web/Cargo.toml +++ b/plugins/web/Cargo.toml @@ -21,3 +21,4 @@ tokio-tungstenite = "0.24" futures-util = "0.3" argon2 = "0.5" getrandom = "0.2" +pulldown-cmark = "0.12" diff --git a/plugins/web/src/http.rs b/plugins/web/src/http.rs index 7998349..50fed80 100644 --- a/plugins/web/src/http.rs +++ b/plugins/web/src/http.rs @@ -19,6 +19,7 @@ use crate::form; use crate::middleware::Middleware; use crate::rate_limit; use crate::render; +use crate::rss; use crate::session; #[derive(Clone)] @@ -71,6 +72,7 @@ pub fn listen( session_ttl: u64, cookie_secure: bool, ws_routes: HashMapno database
")).into_response(); + }; + let table = cfg + .get("table") + .and_then(|v| v.as_str()) + .unwrap_or("posts"); + let limit = cfg + .get("limit") + .and_then(|v| v.as_i64()) + .unwrap_or(20); + let order = cfg.get("order").and_then(|v| v.as_str()); + let title = cfg + .get("title") + .and_then(|v| v.as_str()) + .unwrap_or("Feed"); + let link = cfg.get("link").and_then(|v| v.as_str()).unwrap_or("/"); + let description = cfg + .get("description") + .and_then(|v| v.as_str()) + .unwrap_or(""); + let rows = db::select_order(url, table, limit, None, order, None, None) + .ok() + .and_then(|v| v.get("rows").and_then(|r| r.as_array()).cloned()) + .unwrap_or_default(); + let xml = rss::build_rss(title, link, description, &rows); + ( + [(axum::http::header::CONTENT_TYPE, "application/rss+xml; charset=utf-8")], + xml, + ) + .into_response() +} + async fn home(State(st): State