feat(web): Document/Endpoint/Resource artifact rewrite (ADR 0007)
Replace the monolithic compose_*/configure author surface with file-level
web|endpoint artifacts, split ext/{web,data,security,net}, and lock
no-degrade rules so the model cannot regress to God-object APIs.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
33f8b94bb0
commit
67bac1bf02
54 files changed
+4642
-2505
No files matched your search
@@ -1,54 +1,28 @@
|
||||
# examples/marqdo-blog
|
||||
|
||||
一个用 Marqdo 的 `ext/web` 网络扩展库搭建的博客系统示例:美观大气的现代化主题、
|
||||
SQLite 驱动的文章/标签、动态路由、WebSocket 实时终端、以及受会话门禁保护的后台 CRUD。
|
||||
Marqdo **Web Artifact** 示例(ADR 0007):`.mq.md` 即文档、即路由、即页面。
|
||||
|
||||
## 运行
|
||||
|
||||
```bash
|
||||
cargo build -p marqdo_plugin_web
|
||||
cargo run -- examples/marqdo-blog/index.mq.md
|
||||
bash scripts/build-web-plugin.sh
|
||||
# 若 ~/.marqdo/ext 仍是旧 compose_* 面:export MARQDO_EXT=$PWD/ext
|
||||
cargo run -- run examples/marqdo-blog/serve.mq.md
|
||||
```
|
||||
|
||||
打开 http://127.0.0.1:18085/:
|
||||
打开 http://127.0.0.1:18081/:
|
||||
|
||||
- `/` — 首页:文章卡片网格 + 实时 WebSocket 终端
|
||||
- `/post/{slug}` — 动态路由渲染单篇文章(标题/日期/标签/正文)
|
||||
- `/tags` — 标签归档;`/tag/{slug}` 查看某标签下的文章
|
||||
- `/about` — 关于页
|
||||
- `/admin` — 会话门禁后台,登录 `admin` / `marqdo`,可增删改文章与标签
|
||||
- `/live` — WebSocket 回显端点
|
||||
- `/static/*` — 静态资源(`public/` 下的 `live.js`、favicon、logo)
|
||||
- `/favicon.ico` — 站点图标(`应用.图标` 表装配)
|
||||
| 路径 | 来源 |
|
||||
|------|------|
|
||||
| `/` | `index.mq.md`(`type: web` / 本例中文 `serve` 扫描) |
|
||||
| `/about` | `pages/about.mq.md`(`类型: 网页`) |
|
||||
| `/api/ping` | `api/ping.mq.md`(`type: endpoint`) |
|
||||
|
||||
## 设计亮点(文档即代码)
|
||||
## 设计(代码即文档)
|
||||
|
||||
- **样式即数据表格,装配即函数**(`styles/theme.mq.md`):
|
||||
主题不再是一大段手写 CSS 字符串,而是由一张张 GFM 样式表组成 ——
|
||||
`|选择器|属性|值|` 规则行(同一选择器多行自动合并成一条规则),
|
||||
响应式用 `|媒体|选择器|属性|值|` 分组进 `@media` 块。
|
||||
每个 `## 段`(基础/顶栏/侧栏/主体/卡片/页脚/表单/响应式)导出一张样式表,
|
||||
`## 全局` 用 `网页.样式装配` 函数把每张表装配成 CSS 文本,再 `text.str_join` 拼成完整样式表,
|
||||
最后经 `页面.样式` 注入页面。样式保持可读的数据表格,不写胶水代码。
|
||||
- **图标 / 头资源 / 图片装配**(W8):`应用.图标` 表挂 `/favicon.ico` 与 SVG;
|
||||
`页面.头装配` 写 apple-touch-icon;`页面.图片装配` 把 logo 表注入主区(`mq-images`)。
|
||||
含 `/` 的路径与 MIME 单元格需加引号(如 `"/static/logo.svg"`、`"image/png"`)。
|
||||
- **页面 = 组件装配 + 主体绑定**(`index.mq.md`):
|
||||
导航/侧栏/页脚用 `|组件|样式|` 表装配,文章列表用 `|属性|值|` 绑定 SQLite 字段。
|
||||
- **动态路由**:`/post/{slug}` 的 `slug` 注入查询条件,`页面.详情` 把首行渲染成文章。
|
||||
- **数据模型**(`db/`):`schema.mq.md` 定义 `posts`/`tags`/`post_tags` 三张表,
|
||||
`seed.mq.md` 提供种子数据,`index.mq.md` 幂等建表 + 灌数据。
|
||||
- **Document** — frontmatter `type`/`类型` + Markdown 正文。
|
||||
- **Endpoint** — `type: endpoint` + 可执行正文。
|
||||
- **发现** — `网页.服务` / `web.serve root=` 扫描目录内 Artifact。
|
||||
- **Resource** — DB 等见 `ext/data`(本示例入口以 Document 为主)。
|
||||
|
||||
## 冒烟测试
|
||||
|
||||
服务器启动后(端口 18085),运行:
|
||||
|
||||
```bash
|
||||
bash examples/marqdo-blog/smoke.sh
|
||||
```
|
||||
|
||||
覆盖:首页/卡片/主题 CSS/媒体查询、静态资源、动态路由详情、标签归档、鉴权门禁、
|
||||
登录会话、后台表单、WebSocket 回显。全部通过时输出 `通过 N / N`。
|
||||
|
||||
可从仓库根目录或本目录运行:相对 `static_dir`(`public`)与相对数据库路径
|
||||
(`data/marqdo-blog.db`)都按**入口脚本所在目录**解析,不依赖终端工作目录。
|
||||
规范:[ext-web-artifact.md](../../doc/design/ext-web-artifact.md) · ADR [0007](../../doc/adr/0007-web-document-endpoint.md)。
|
||||
@@ -0,0 +1,9 @@
|
||||
---
|
||||
type: endpoint
|
||||
method: GET
|
||||
path: /api/ping
|
||||
request: none
|
||||
response: json
|
||||
---
|
||||
|
||||
Ping endpoint — documentation is the API.
|
||||
@@ -1,131 +1,26 @@
|
||||
---
|
||||
type: web
|
||||
title: Marqdo 博客
|
||||
description: 用 web 扩展库搭建的博客系统示例:首页列表、动态文章详情、标签归档、登录门禁后台。
|
||||
route: /
|
||||
method: GET
|
||||
description: >-
|
||||
Document Artifact 示例(ADR 0007):首页即文档。
|
||||
子页/API 见 pages/ 与 api/;入口可 web.serve 扫描注册。
|
||||
导入 网页:ext/web/网页.mq.md
|
||||
import theme:styles/theme.mq.md
|
||||
import nav:components/nav.mq.md
|
||||
import side:components/side.mq.md
|
||||
import foot:components/foot.mq.md
|
||||
import db:db/index.mq.md
|
||||
---
|
||||
|
||||
# main
|
||||
# Marqdo 博客
|
||||
|
||||
`首页` =
|
||||
可执行文档即网页。本站用 Artifact Metadata 声明路由,正文即内容。
|
||||
|
||||
| 组件 | 样式 |
|
||||
|------|------|
|
||||
| nav.`导航` | |
|
||||
| side.`侧栏` | |
|
||||
| foot.`页脚` | |
|
||||
## 文章
|
||||
|
||||
`列表` =
|
||||
从 `data_source`(元信息)或库表加载列表;本示例入口直接服务文档页。
|
||||
|
||||
| 属性 | 值 | 样式 |
|
||||
|------|-----|------|
|
||||
| title | posts.title | |
|
||||
| body | posts.summary | |
|
||||
| meta | posts.created_at | |
|
||||
| tag | posts.tag | |
|
||||
| href | posts.slug | |
|
||||
---
|
||||
|
||||
`详情绑定` =
|
||||
运行(仓库根目录):
|
||||
|
||||
| 属性 | 值 | 样式 |
|
||||
|------|-----|------|
|
||||
| title | posts.title | |
|
||||
| meta | posts.created_at | |
|
||||
| tag | posts.tag | |
|
||||
| body | posts.content | |
|
||||
|
||||
`标签列表` =
|
||||
|
||||
| 属性 | 值 | 样式 |
|
||||
|------|-----|------|
|
||||
| title | tags.name | |
|
||||
| meta | 点击查看该标签下的文章 | |
|
||||
| href | tags.slug | |
|
||||
|
||||
`文章条件` =
|
||||
|
||||
| 字段 | 操作 | 值 |
|
||||
|------|------|-----|
|
||||
| slug | = | {slug} |
|
||||
|
||||
`标签条件` =
|
||||
|
||||
| 字段 | 操作 | 值 |
|
||||
|------|------|-----|
|
||||
| tag | = | {slug} |
|
||||
|
||||
`管理员` =
|
||||
|
||||
| 行 | 用户名 | 密码 |
|
||||
|----|--------|------|
|
||||
| 1 | admin | marqdo |
|
||||
|
||||
`站点图标` =
|
||||
|
||||
| 路径 | 关系 | 类型 | 尺寸 | 地址 |
|
||||
|------|------|------|------|------|
|
||||
| "public/favicon.png" | icon | "image/png" | 32x32 | "/favicon.ico" |
|
||||
| "public/favicon.svg" | icon | "image/svg+xml" | any | "/static/favicon.svg" |
|
||||
|
||||
`头资源` =
|
||||
|
||||
| 关系 | 地址 | 类型 |
|
||||
|------|------|------|
|
||||
| apple-touch-icon | "/static/favicon.png" | "image/png" |
|
||||
|
||||
`品牌图` =
|
||||
|
||||
| 源 | 替代 | 类 | 链接 | 宽度 | 加载 |
|
||||
|----|------|----|------|------|------|
|
||||
| "/static/logo.svg" | Marqdo | brand-logo | "/" | 40 | eager |
|
||||
|
||||
**store = > db.打开**
|
||||
|
||||
**首页CSS = > theme.全局**
|
||||
|
||||
**page = > 网页.页面 标题="Marqdo 博客" 引言="<h1>Marqdo 博客</h1><p>用 web 扩展库搭建的博客:表格装配页面、SQLite 数据、动态路由、实时终端。</p><h2 id=\"live\">实时终端</h2><p id=\"live-status\" class=\"live-pill\">connecting…</p><input id=\"live-msg\" placeholder=\"输入一条消息…\"><button id=\"live-send\" disabled>发送</button><div id=\"live-out\"></div><script src=\"/static/live.js\"></script>"**
|
||||
**page = > page.组件装配 组件=`首页`**
|
||||
**page = > page.主体装配 主体=`列表`**
|
||||
**page = > page.排序 排序="-created_at"**
|
||||
**page = > page.样式 样式=`首页CSS`**
|
||||
**page = > page.头装配 表=`头资源`**
|
||||
**page = > page.图片装配 表=`品牌图`**
|
||||
|
||||
**about = > 网页.页面 标题="关于" 引言="<h1>关于本站</h1><p>一个用 Marqdo 的 web 扩展库(ext/web)写成的博客系统。</p><p>它演示了:GFM 表格装配导航与侧栏、SQLite 驱动的主体绑定、动态路由 /post/{slug}、标签归档、以及受 session 保护的后台 CRUD。</p>"**
|
||||
**about = > about.组件装配 组件=`首页`**
|
||||
**about = > about.样式 样式=`首页CSS`**
|
||||
|
||||
**post = > 网页.页面 标题="文章"**
|
||||
**post = > post.组件装配 组件=`首页`**
|
||||
**post = > post.主体装配 主体=`详情绑定`**
|
||||
**post = > post.查询条件 条件=`文章条件`**
|
||||
**post = > post.详情 详情=True**
|
||||
**post = > post.样式 样式=`首页CSS`**
|
||||
|
||||
**tags = > 网页.页面 标题="标签归档" 引言="<h1>标签归档</h1><p>点击标签查看该主题下的文章。</p>"**
|
||||
**tags = > tags.组件装配 组件=`首页`**
|
||||
**tags = > tags.主体装配 主体=`标签列表`**
|
||||
**tags = > tags.链接前缀 前缀="/tag/"**
|
||||
**tags = > tags.样式 样式=`首页CSS`**
|
||||
|
||||
**tagged = > 网页.页面 标题="标签"**
|
||||
**tagged = > tagged.组件装配 组件=`首页`**
|
||||
**tagged = > tagged.主体装配 主体=`列表`**
|
||||
**tagged = > tagged.查询条件 条件=`标签条件`**
|
||||
**tagged = > tagged.排序 排序="-created_at"**
|
||||
**tagged = > tagged.样式 样式=`首页CSS`**
|
||||
|
||||
**app = > 网页.应用 页面=page 数据库=store 后台=True 主机="127.0.0.1" 端口=18085**
|
||||
**app = > app.路由 路径="/about" 页面=about**
|
||||
**app = > app.路由 路径="/post/{slug}" 页面=post**
|
||||
**app = > app.路由 路径="/tags" 页面=tags**
|
||||
**app = > app.路由 路径="/tag/{slug}" 页面=tagged**
|
||||
**app = > app.静态 目录="public" 挂载="/static"**
|
||||
**app = > app.图标 表=`站点图标`**
|
||||
**app = > app.路由实时 路径="/live" 回显=True**
|
||||
**app = > app.鉴权 用户表=`管理员` 会话时长=3600**
|
||||
> `app`.监听
|
||||
```text
|
||||
marqdo run examples/marqdo-blog/serve.mq.md
|
||||
```
|
||||
@@ -0,0 +1,10 @@
|
||||
---
|
||||
类型: 网页
|
||||
路由: /about
|
||||
方法: GET
|
||||
标题: 关于
|
||||
---
|
||||
|
||||
# 关于 Marqdo
|
||||
|
||||
Marqdo 是可执行文档语言:文档即程序,程序即知识。
|
||||
@@ -0,0 +1,9 @@
|
||||
---
|
||||
title: marqdo-blog serve
|
||||
description: Scan Artifact .mq.md under this directory and listen (ADR 0007).
|
||||
导入 网页:ext/web/网页.mq.md
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
> 网页.服务 根="." 主机="127.0.0.1" 端口=18081
|
||||
@@ -1,20 +1,14 @@
|
||||
# web-client-site(路线 D)
|
||||
# examples/web-client-site
|
||||
|
||||
服务端 `ext/web` + 浏览器 WASM 会话;**作者零业务 JS**。
|
||||
SSR **Document Artifact** + `web.client_embed` auto-mount(零作者 JS)。ADR 0007。
|
||||
|
||||
```bash
|
||||
# 仓库根
|
||||
cargo build -p marqdo --release
|
||||
cargo build --release -p marqdo_plugin_web
|
||||
./target/release/marqdo ext add web
|
||||
|
||||
# 构建 WASM + bridge 到本示例 static/
|
||||
./target/release/marqdo wasm build -o examples/web-client-site/static
|
||||
# 保留 client.mq.md(wasm build 只写入 wasm/bridge)
|
||||
|
||||
cd examples/web-client-site
|
||||
marqdo run index.mq.md
|
||||
# 打开 http://127.0.0.1:18090/
|
||||
bash scripts/build-web-plugin.sh
|
||||
export MARQDO_EXT=$PWD/ext # 若本机 ~/.marqdo/ext 未同步
|
||||
marqdo wasm build -o examples/web-client-site/static
|
||||
cargo run -- run examples/web-client-site/serve.mq.md
|
||||
```
|
||||
|
||||
`index.mq.md` 用 `web.client_embed source="/static/client.mq.md"` 注入自启脚本;交互在 `static/client.mq.md`。
|
||||
- `index.mq.md` — `type: web` 文档页
|
||||
- `serve.mq.md` — `web.serve` + `static_dir`
|
||||
- `static/client.mq.md` — `lib/browser` wire(不变)
|
||||
@@ -1,19 +1,14 @@
|
||||
---
|
||||
title: web-client-site
|
||||
description: SSR shell + client_embed auto-mount; author zero JS (route D)
|
||||
type: web
|
||||
title: Marqdo client site
|
||||
route: /
|
||||
method: GET
|
||||
description: SSR Document + client_embed auto-mount; author zero JS (ADR 0007).
|
||||
import web:ext/web/web.mq.md
|
||||
---
|
||||
|
||||
# main
|
||||
# Marqdo client site
|
||||
|
||||
Server page with a counter UI. Client logic lives in `static/client.mq.md`
|
||||
(loaded by official bridge via `client_embed`).
|
||||
SSR shell with WASM session. Client logic lives in `static/client.mq.md`.
|
||||
|
||||
**`embed` = > web.client_embed bridge="/static/marqdo-bridge.js" wasm="/static/marqdo_wasm.wasm" source="/static/client.mq.md" boot=True**
|
||||
|
||||
**`intro` = "<h1>Marqdo client site</h1><p>SSR + WASM session. No author JS.</p><div id=\"count\">0</div><p><button id=\"bump\" type=\"button\" disabled>Bump</button> <button id=\"reset\" type=\"button\" disabled>Reset</button></p><pre id=\"log\">booting…</pre>" + embed**
|
||||
|
||||
**page = > web.page title="Marqdo client site" intro=intro**
|
||||
**app = > web.app page=page host="127.0.0.1" port=18090**
|
||||
**app = > app.static dir="static" mount="/static"**
|
||||
> `app`.listen
|
||||
To serve with static assets, run `serve.mq.md` in this directory.
|
||||
@@ -0,0 +1,10 @@
|
||||
---
|
||||
title: web-client-site serve
|
||||
import web:ext/web/web.mq.md
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
**`embed` = > web.client_embed source="/static/client.mq.md"**
|
||||
> print text=embed-ready
|
||||
> web.serve root="." host="127.0.0.1" port=18090 static_dir="static"
|
||||
Reference in new issue
Block a user