Add marqdo-blog example with GFM-table style assembly

Introduce web_style ABI (样式装配) so themes are GFM style tables
(|选择器|属性|值|, optional |媒体| column for @media) assembled by
functions instead of hand-written CSS strings — 文档即代码. The new
examples/marqdo-blog shows a full blog: card grid, dynamic /post/{slug},
tag archive, WebSocket live widget, and session-gated admin CRUD, plus a
smoke test (15 checks) and README.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
cflmyandCursor committed 2026-08-26 13:03:55 +08:00
1 parent 7645dd4c1f
commit da9fc75b1e
20 files changed
+1518 -93

No files matched your search

+50
View File
@@ -0,0 +1,50 @@
# examples/marqdo-blog
一个用 Marqdo 的 `ext/web` 网络扩展库搭建的博客系统示例:美观大气的现代化主题、
SQLite 驱动的文章/标签、动态路由、WebSocket 实时终端、以及受会话门禁保护的后台 CRUD。
## 运行
```bash
cargo build -p marqdo_plugin_web
cargo run -- examples/marqdo-blog/index.mq.md
```
打开 http://127.0.0.1:18085/:
- `/` — 首页:文章卡片网格 + 实时 WebSocket 终端
- `/post/{slug}` — 动态路由渲染单篇文章(标题/日期/标签/正文)
- `/tags` — 标签归档;`/tag/{slug}` 查看某标签下的文章
- `/about` — 关于页
- `/admin` — 会话门禁后台,登录 `admin` / `marqdo`,可增删改文章与标签
- `/live` — WebSocket 回显端点
- `/static/*` — 静态资源(`public/` 下的 `live.js`)
## 设计亮点(文档即代码)
- **样式即数据表格,装配即函数**(`styles/theme.mq.md`):
主题不再是一大段手写 CSS 字符串,而是由一张张 GFM 样式表组成 ——
`|选择器|属性|值|` 规则行(同一选择器多行自动合并成一条规则),
响应式用 `|媒体|选择器|属性|值|` 分组进 `@media` 块。
每个 `## 段`(基础/顶栏/侧栏/主体/卡片/页脚/表单/响应式)导出一张样式表,
`## 全局` 用 `网页.样式装配` 函数把每张表装配成 CSS 文本,再 `text.str_join` 拼成完整样式表,
最后经 `页面.样式` 注入页面。样式保持可读的数据表格,不写胶水代码。
- **页面 = 组件装配 + 主体绑定**(`index.mq.md`):
导航/侧栏/页脚用 `|组件|样式|` 表装配,文章列表用 `|属性|值|` 绑定 SQLite 字段。
- **动态路由**:`/post/{slug}` 的 `slug` 注入查询条件,`页面.详情` 把首行渲染成文章。
- **数据模型**(`db/`):`schema.mq.md` 定义 `posts`/`tags`/`post_tags` 三张表,
`seed.mq.md` 提供种子数据,`index.mq.md` 幂等建表 + 灌数据。
## 冒烟测试
服务器启动后(端口 18085),运行:
```bash
bash examples/marqdo-blog/smoke.sh
```
覆盖:首页/卡片/主题 CSS/媒体查询、静态资源、动态路由详情、标签归档、鉴权门禁、
登录会话、后台表单、WebSocket 回显。全部通过时输出 `通过 N / N`。
可从仓库根目录或本目录运行:相对 `static_dir`(`public`)与相对数据库路径
(`data/marqdo-blog.db`)都按**入口脚本所在目录**解析,不依赖终端工作目录。
@@ -0,0 +1,13 @@
## 页脚
站点页脚。放版权与概览链接。
`页脚` =
| 属性 | 值 | 样式 |
|------|-----|------|
| © 2026 Marqdo 博客 | / | |
| 关于 | /about | |
| 后台 | /admin | |
**`页脚`**
+15
View File
@@ -0,0 +1,15 @@
## 导航
站点顶部导航。首项是站点名(渐变 Logo 由主题 CSS 处理),`后台` 指向需要登录的 `/admin`。
`导航` =
| 属性 | 值 | 样式 |
|------|-----|------|
| Marqdo 博客 | / | |
| 首页 | / | |
| 标签 | /tags | |
| 关于 | /about | |
| 后台 | /admin | |
**`导航`**
@@ -0,0 +1,15 @@
## 侧栏
右侧归档面板:文章入口、标签、实时小部件。
`侧栏` =
| 属性 | 值 | 样式 |
|------|-----|------|
| 全部文章 | / | |
| 标签归档 | /tags | |
| 关于本站 | /about | |
| 发布文章 | /admin/new | |
| 实时终端 | /#live | |
**`侧栏`**
+28
View File
@@ -0,0 +1,28 @@
---
title: db/index
description: 打开 sqlite、建三张表、幂等种子。
导入 网页:ext/web/网页.mq.md
import schema:schema.mq.md
import seed:seed.mq.md
---
## 打开
*store = > 网页.数据库 地址="sqlite:data/marqdo-blog.db"*
*字段 = > schema.posts*
*标签字段 = > schema.tags*
*关联字段 = > schema.post_tags*
> `store`.初始化 名=posts 字段=`字段`
> `store`.初始化 名=tags 字段=`标签字段`
> `store`.初始化 名=post_tags 字段=`关联字段`
*行 = > store.查询 表="posts" 上限=1*
1. `行`
**store**
2. *
*文章 = > seed.posts*
*标签 = > seed.tags*
*关联 = > seed.post_tags*
> `store`.插入 表=posts 行=`文章`
> `store`.插入 表=tags 行=`标签`
> `store`.插入 表=post_tags 行=`关联`
**store**
+46
View File
@@ -0,0 +1,46 @@
## posts
文章主表结构。`slug` 用于详情页 `/post/{slug}` 的动态路由;`content` 存 Markdown 正文;`tag` 是主标签(tags 表 slug)。
`schema` =
| 字段 | 类型 | 可空 |
|------|------|------|
| id | integer | false |
| title | text | false |
| slug | text | false |
| summary | text | true |
| content | text | true |
| tag | text | true |
| created_at | text | true |
| updated_at | text | true |
**`schema`**
## tags
标签表结构。
`tags` =
| 字段 | 类型 | 可空 |
|------|------|------|
| id | integer | false |
| name | text | false |
| slug | text | false |
**`tags`**
## post_tags
文章-标签关联表结构。
`post_tags` =
| 字段 | 类型 | 可空 |
|------|------|------|
| id | integer | false |
| post_id | integer | false |
| tag_id | integer | false |
**`post_tags`**
+53
View File
@@ -0,0 +1,53 @@
## posts
种子文章。首页与详情页的初始数据。created_at 用于按时间倒序展示;tag 是主标签 slug。
`posts` =
| 行 | title | slug | summary | content | tag | created_at | updated_at |
|----|-------|------|---------|---------|-----|------------|------------|
| 1 | 你好,Marqdo 博客 | hello-marqdo | 用 Marqdo 的 web 扩展库搭建的第一个博客。表格即组件、文档即代码。 | 这是一篇介绍博客系统的文章。它由 Marqdo 脚本在启动时写入 SQLite,通过 ext/web 的组件装配渲染成页面。 | marqdo | 2026-08-01 | 2026-08-02 |
| 2 | 动态路由与文章详情 | dynamic-routing | 如何用 /post/{slug} 动态路由渲染单篇文章。 | 本文说明动态路由机制:作者面注册带 {slug} 占位符的路由,请求时把路径参数注入页面查询条件。 | web | 2026-08-05 | 2026-08-05 |
| 3 | 用 GFM 表格表达数据 | gfm-tables | Marqdo 的字典操作不依赖 json 库,GFM 表格即可完成。 | 表格即数据、表格即组件。这篇文章展示如何在 .mq.md 里用横向表写种子数据,用脚注索引读取字段。 | tutorial | 2026-08-10 | 2026-08-11 |
| 4 | WebSocket 实时小部件 | websocket-live | 给博客加一个实时回显的 WebSocket 端点。 | 通过 app.路由实时 注册 /live 端点,配合 public/live.js 在首页显示实时连接状态。 | realtime | 2026-08-15 | 2026-08-15 |
| 5 | 会话与登录鉴权 | session-auth | 后台用 session 门禁保护,只有登录用户能发布文章。 | 用 app.鉴权 配置管理员用户表,/admin 下的 CRUD 页面都需要有效会话。 | web | 2026-08-18 | 2026-08-20 |
| 6 | 数据库与 CRUD | database-crud | 博客的文章、标签、关联全部由 SQLite 支撑。 | db.初始化 建表、db.插入 写种子、后台表单增删改。文章与标签通过 post_tags 关联。 | database | 2026-08-20 | 2026-08-21 |
**`posts`**
## tags
种子标签。
`tags` =
| 行 | name | slug |
|----|------|------|
| 1 | Marqdo | marqdo |
| 2 | Web | web |
| 3 | 教程 | tutorial |
| 4 | 数据库 | database |
| 5 | 实时 | realtime |
**`tags`**
## post_tags
种子文章-标签关联。
`post_tags` =
| 行 | post_id | tag_id |
|----|---------|--------|
| 1 | 1 | 1 |
| 2 | 1 | 2 |
| 3 | 2 | 2 |
| 4 | 3 | 1 |
| 5 | 3 | 3 |
| 6 | 4 | 5 |
| 7 | 4 | 2 |
| 8 | 5 | 2 |
| 9 | 6 | 4 |
| 10 | 6 | 1 |
**`post_tags`**
+109
View File
@@ -0,0 +1,109 @@
---
title: Marqdo 博客
description: 用 web 扩展库搭建的博客系统示例:首页列表、动态文章详情、标签归档、登录门禁后台。
导入 网页: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
`首页` =
| 组件 | 样式 |
|------|------|
| nav.`导航` | |
| side.`侧栏` | |
| foot.`页脚` | |
`列表` =
| 属性 | 值 | 样式 |
|------|-----|------|
| 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 |
*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`*
*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.路由实时 路径="/live" 回显=True*
*app = > app.鉴权 用户表=`管理员` 会话时长=3600*
> `app`.监听
+40
View File
@@ -0,0 +1,40 @@
// 实时 WebSocket 小部件(连接 /live 端点)。
// 连接 ws://host/live,发送输入,展示服务器回显。
(function () {
var out = document.getElementById("live-out");
var input = document.getElementById("live-msg");
var btn = document.getElementById("live-send");
var status = document.getElementById("live-status");
if (!out || !input || !btn || !status) return;
var proto = location.protocol === "https:" ? "wss" : "ws";
var ws = new WebSocket(proto + "://" + location.host + "/live");
status.textContent = "connecting…";
ws.onopen = function () {
status.textContent = "connected";
btn.disabled = false;
};
ws.onmessage = function (ev) {
var p = document.createElement("p");
p.textContent = "echo: " + ev.data;
out.appendChild(p);
out.scrollTop = out.scrollHeight;
};
ws.onclose = function () {
status.textContent = "closed";
btn.disabled = true;
};
ws.onerror = function () {
status.textContent = "error";
btn.disabled = true;
};
btn.onclick = function () {
var m = input.value.trim();
if (m) ws.send(m);
};
input.addEventListener("keydown", function (e) {
if (e.key === "Enter") btn.onclick();
});
})();
+68
View File
@@ -0,0 +1,68 @@
#!/usr/bin/env bash
# 冒烟测试:marqdo-blog 全功能验证。
# 用法:bash examples/marqdo-blog/smoke.sh
set -uo pipefail
BASE="http://127.0.0.1:18085"
PASS=0; FAIL=0
ok() { echo " ok: $1"; PASS=$((PASS+1)); }
bad() { echo " FAIL: $1"; FAIL=$((FAIL+1)); }
echo "== 首页 =="
code=$(curl -s -o /dev/null -w "%{http_code}" "$BASE/")
[ "$code" = "200" ] && ok "GET / -> $code" || bad "GET / -> $code"
curl -s "$BASE/" | grep -q '<title>Marqdo 博客</title>' && ok "title" || bad "title"
curl -s "$BASE/" | grep -q 'class="card"' && ok "卡片渲染" || bad "卡片缺失"
curl -s "$BASE/" | grep -q 'aside.side' && ok "主题 CSS 注入" || bad "主题 CSS 缺失"
curl -s "$BASE/" | grep -q '@media (max-width: 860px)' && ok "响应式媒体查询" || bad "媒体查询缺失"
echo "== 静态 =="
code=$(curl -s -o /dev/null -w "%{http_code}" "$BASE/static/live.js")
[ "$code" = "200" ] && ok "GET /static/live.js -> $code" || bad "static -> $code"
echo "== 动态路由 =="
code=$(curl -s -o /dev/null -w "%{http_code}" "$BASE/post/hello-marqdo")
[ "$code" = "200" ] && ok "GET /post/hello-marqdo -> $code" || bad "post detail -> $code"
curl -s "$BASE/post/hello-marqdo" | grep -q 'article-title' && ok "文章详情渲染" || bad "文章详情缺失"
echo "== 标签 =="
curl -s "$BASE/tags" | grep -q 'href="/tag/marqdo"' && ok "标签归档链接" || bad "标签链接缺失"
code=$(curl -s -o /dev/null -w "%{http_code}" "$BASE/tag/web")
[ "$code" = "200" ] && ok "GET /tag/web -> $code" || bad "tag page -> $code"
echo "== 鉴权门禁 =="
code=$(curl -s -o /dev/null -w "%{http_code}" "$BASE/admin")
[ "$code" = "303" ] && ok "未登录 /admin -> $code (重定向登录)" || bad "未登录 /admin -> $code"
echo "== 登录 =="
rm -f /tmp/mq_smoke_cookies.txt /tmp/mq_smoke_headers.txt
curl -s -D /tmp/mq_smoke_headers.txt -o /dev/null -d "username=admin&password=marqdo" "$BASE/admin/login"
sid=$(grep -i "set-cookie" /tmp/mq_smoke_headers.txt | sed 's/.*marqdo_sid=\([^;]*\).*/\1/')
[ -n "$sid" ] && ok "登录获取会话 cookie" || bad "登录未返回 cookie"
code=$(curl -s -b "marqdo_sid=$sid" -o /dev/null -w "%{http_code}" "$BASE/admin")
[ "$code" = "200" ] && ok "带会话访问 /admin -> $code" || bad "带会话 /admin -> $code"
echo "== 发布文章 (CRUD) =="
code=$(curl -s -b "marqdo_sid=$sid" -o /dev/null -w "%{http_code}" "$BASE/admin/posts/new")
[ "$code" = "200" ] && ok "GET /admin/posts/new -> $code" || bad "new form -> $code"
echo "== WebSocket =="
wsok=$(python3 -c "
import socket, base64, os
s = socket.create_connection(('127.0.0.1', 18085), timeout=3)
key = base64.b64encode(os.urandom(16)).decode()
s.sendall((f'GET /live HTTP/1.1\r\nHost: x\r\nUpgrade: websocket\r\nConnection: Upgrade\r\nSec-WebSocket-Key: {key}\r\nSec-WebSocket-Version: 13\r\n\r\n').encode())
r = s.recv(1024).decode(errors='replace')
if '101' not in r.split('\r\n')[0]:
print('NO'); s.close(); raise SystemExit
mask = os.urandom(4); payload = b'ping'
m = bytes(b ^ mask[i%4] for i, b in enumerate(payload))
s.sendall(bytes([0x81, 0x80|len(payload)]) + mask + m)
d = s.recv(1024)
print('OK' if b'ping' in d else 'NO')
s.close()
" 2>/dev/null)
[ "$wsok" = "OK" ] && ok "WebSocket /live 回显" || bad "WebSocket 回显 $wsok"
echo
echo "通过 $PASS / $((PASS+FAIL))"
[ "$FAIL" = "0" ] || exit 1
+405
View File
@@ -0,0 +1,405 @@
---
title: styles/theme
description: 博客主题:样式即数据表格,装配即函数。
import 网页:ext/web/网页.mq.md
import text:lib/text.mq.md
---
博客主题的样式即数据表格:每个 `## 段` 导出一张 GFM 样式表(`|选择器|属性|值|`,
或用 `|媒体|选择器|属性|值|` 表达响应式),`## 全局` 用 `样式装配` 函数把它们
装配成一份完整 CSS。这符合 文档即代码 —— 样式是可读的表格,装配是显式调用。
## 基础
配色与字体变量、页面骨架。衬线标题 + 无衬线正文,暖白纸感背景。
`基础` =
| 选择器 | 属性 | 值 |
|--------|------|-----|
| :root | --ink | #1c1917 |
| :root | --ink-soft | #44403c |
| :root | --muted | #78716c |
| :root | --faint | #a8a29e |
| :root | --paper | #f7f5f2 |
| :root | --card | #ffffff |
| :root | --line | #e7e5e4 |
| :root | --accent | #4f46e5 |
| :root | --accent-2 | #7c3aed |
| :root | --accent-ink | #ffffff |
| :root | --radius | 16px |
| :root | --shadow | 0 1px 2px rgba(28,25,23,.05), 0 8px 24px rgba(28,25,23,.06) |
| :root | --shadow-lg | 0 4px 12px rgba(28,25,23,.08), 0 20px 48px rgba(28,25,23,.12) |
| :root | --serif | "Noto Serif SC", Georgia, "Songti SC", serif |
| :root | --sans | "Noto Sans SC", "IBM Plex Sans", system-ui, -apple-system, sans-serif |
| html | scroll-behavior | smooth |
| * | box-sizing | border-box |
| ::selection | background | rgba(79,70,229,.18) |
| body | margin | 0 |
| body | font-family | var(--sans) |
| body | background | var(--paper) |
| body | color | var(--ink) |
| body | display | grid |
| body | min-height | 100vh |
| body | line-height | 1.7 |
| body | grid-template-rows | auto 1fr auto |
| body.has-sidebar | grid-template-columns | 15rem 1fr |
| body.has-sidebar | grid-template-areas | "top top" "side main" "foot foot" |
| body.no-sidebar | grid-template-areas | "top" "main" "foot" |
**`基础`**
## 顶栏
吸顶导航:磨砂玻璃 + 细分隔线,Logo 处用渐变强调。
`顶栏` =
| 选择器 | 属性 | 值 |
|--------|------|-----|
| header.topnav | grid-area | top |
| header.topnav | position | sticky |
| header.topnav | top | 0 |
| header.topnav | z-index | 20 |
| header.topnav | background | rgba(255,255,255,.82) |
| header.topnav | backdrop-filter | blur(10px) |
| header.topnav | -webkit-backdrop-filter | blur(10px) |
| header.topnav | border-bottom | 1px solid var(--line) |
| header.topnav | padding | .9rem 2rem |
| header.topnav | display | flex |
| header.topnav | align-items | center |
| header.topnav | justify-content | space-between |
| ul.nav | list-style | none |
| ul.nav | margin | 0 |
| ul.nav | padding | 0 |
| ul.nav | display | flex |
| ul.nav | align-items | center |
| ul.nav | gap | .35rem |
| ul.nav li | margin | 0 |
| ul.nav a | display | inline-block |
| ul.nav a | padding | .45rem .9rem |
| ul.nav a | border-radius | 999px |
| ul.nav a | color | var(--ink-soft) |
| ul.nav a | font-weight | 500 |
| ul.nav a | text-decoration | none |
| ul.nav a | transition | background .18s ease, color .18s ease |
| ul.nav a:hover | background | rgba(79,70,229,.1) |
| ul.nav a:hover | color | var(--accent) |
| ul.nav li:first-child a | font-family | var(--serif) |
| ul.nav li:first-child a | font-size | 1.25rem |
| ul.nav li:first-child a | font-weight | 700 |
| ul.nav li:first-child a | background | linear-gradient(120deg, var(--accent), var(--accent-2)) |
| ul.nav li:first-child a | -webkit-background-clip | text |
| ul.nav li:first-child a | background-clip | text |
| ul.nav li:first-child a | -webkit-text-fill-color | transparent |
| ul.nav li:first-child a | color | transparent |
| ul.nav li:first-child a | padding-left | .2rem |
| ul.nav li:first-child a | padding-right | .2rem |
**`顶栏`**
## 侧栏
归档面板:浅底圆角卡片,链接胶囊化。
`侧栏` =
| 选择器 | 属性 | 值 |
|--------|------|-----|
| aside.side | grid-area | side |
| aside.side | padding | 2rem 1.25rem |
| aside.side | border-right | 1px solid var(--line) |
| aside.side | background | linear-gradient(180deg, #fbfaf8, #f3f1ec) |
| ul.side-nav | list-style | none |
| ul.side-nav | margin | 0 |
| ul.side-nav | padding | 0 |
| ul.side-nav | display | flex |
| ul.side-nav | flex-direction | column |
| ul.side-nav | gap | .25rem |
| ul.side-nav li | margin | 0 |
| ul.side-nav a | display | block |
| ul.side-nav a | padding | .55rem .85rem |
| ul.side-nav a | border-radius | 10px |
| ul.side-nav a | color | var(--ink-soft) |
| ul.side-nav a | text-decoration | none |
| ul.side-nav a | font-weight | 500 |
| ul.side-nav a | transition | background .15s ease, transform .15s ease, color .15s ease |
| ul.side-nav a:hover | background | #fff |
| ul.side-nav a:hover | color | var(--accent) |
| ul.side-nav a:hover | transform | translateX(4px) |
| ul.side-nav a:hover | box-shadow | 0 1px 3px rgba(28,25,23,.08) |
**`侧栏`**
## 主体
内容区留白与节奏。
`主体` =
| 选择器 | 属性 | 值 |
|--------|------|-----|
| main.main | grid-area | main |
| main.main | padding | 2.5rem 2.5rem 3.5rem |
| main.main | max-width | 76rem |
| main.main | width | 100% |
| .main-intro | margin-bottom | .5rem |
| .main-intro h1 | font-family | var(--serif) |
| .main-intro h1 | margin | 0 0 .5rem |
| .main-intro h1 | font-size | clamp(2rem, 5vw, 2.9rem) |
| .main-intro h1 | line-height | 1.2 |
| .main-intro h1 | font-weight | 700 |
| .main-intro h1 | letter-spacing | -.01em |
| .main-intro p | color | var(--muted) |
| .main-intro p | margin | 0 |
| .main-intro p | font-size | 1.05rem |
**`主体`**
## 卡片
文章卡片:白底大圆角、柔和阴影、hover 抬升,整卡可点。
`卡片` =
| 选择器 | 属性 | 值 |
|--------|------|-----|
| .content.cards | display | grid |
| .content.cards | gap | 1.5rem |
| .content.cards | margin-top | 2rem |
| .content.cards | grid-template-columns | repeat(auto-fill, minmax(17rem, 1fr)) |
| .content.cards article.card | background | var(--card) |
| .content.cards article.card | border | 1px solid var(--line) |
| .content.cards article.card | border-radius | var(--radius) |
| .content.cards article.card | padding | 1.6rem 1.7rem |
| .content.cards article.card | box-shadow | var(--shadow) |
| .content.cards article.card | transition | transform .22s ease, box-shadow .22s ease, border-color .22s ease |
| .content.cards article.card | display | flex |
| .content.cards article.card | flex-direction | column |
| .content.cards article.card | gap | .55rem |
| .content.cards article.card:hover | transform | translateY(-6px) |
| .content.cards article.card:hover | box-shadow | var(--shadow-lg) |
| .content.cards article.card:hover | border-color | rgba(79,70,229,.35) |
| .content.cards a.card-link | text-decoration | none |
| .content.cards a.card-link | color | inherit |
| .content.cards a.card-link | display | flex |
| .content.cards a.card-link | flex-direction | column |
| .content.cards a.card-link | gap | .55rem |
| .content.cards a.card-link | height | 100% |
| .content.cards a.card-link:hover | color | inherit |
| .content.cards h2 | font-family | var(--serif) |
| .content.cards h2 | margin | 0 |
| .content.cards h2 | font-size | 1.35rem |
| .content.cards h2 | line-height | 1.35 |
| .content.cards h2 | font-weight | 700 |
| .content.cards h2 | transition | color .18s ease |
| .content.cards a.card-link:hover h2 | color | var(--accent) |
| .card-meta | font-size | .82rem |
| .card-meta | color | var(--faint) |
| .card-meta | letter-spacing | .04em |
| .card-meta | text-transform | uppercase |
| .card-tag | align-self | flex-start |
| .card-tag | font-size | .78rem |
| .card-tag | color | var(--accent) |
| .card-tag | background | rgba(79,70,229,.08) |
| .card-tag | padding | .15rem .65rem |
| .card-tag | border-radius | 999px |
| .card-tag | font-weight | 600 |
| .content.cards p | color | var(--muted) |
| .content.cards p | margin | 0 |
| .content.cards p | font-size | .95rem |
| .content.cards p | flex | 1 |
**`卡片`**
## 页脚
`页脚` =
| 选择器 | 属性 | 值 |
|--------|------|-----|
| footer.foot | grid-area | foot |
| footer.foot | padding | 1.4rem 2rem |
| footer.foot | border-top | 1px solid var(--line) |
| footer.foot | color | var(--muted) |
| footer.foot | background | #fff |
| footer.foot | font-size | .9rem |
| footer.foot | display | flex |
| footer.foot | justify-content | space-between |
| footer.foot | align-items | center |
| footer.foot | flex-wrap | wrap |
| footer.foot | gap | .5rem |
| ul.foot-nav | list-style | none |
| ul.foot-nav | margin | 0 |
| ul.foot-nav | padding | 0 |
| ul.foot-nav | display | flex |
| ul.foot-nav | gap | 1rem |
| ul.foot-nav | flex-wrap | wrap |
| ul.foot-nav li | margin | 0 |
| ul.foot-nav a | color | var(--muted) |
| ul.foot-nav a | text-decoration | none |
| ul.foot-nav a:hover | color | var(--accent) |
**`页脚`**
## 表单
后台表单统一风格。
`表单` =
| 选择器 | 属性 | 值 |
|--------|------|-----|
| .site-form | margin-top | 1.75rem |
| .site-form | max-width | 34rem |
| .site-form | background | var(--card) |
| .site-form | border | 1px solid var(--line) |
| .site-form | border-radius | var(--radius) |
| .site-form | padding | 1.8rem |
| .site-form | box-shadow | var(--shadow) |
| .site-form form | display | grid |
| .site-form form | gap | 1rem |
| .site-form label | display | grid |
| .site-form label | gap | .35rem |
| .site-form label | font-size | .92rem |
| .site-form label | font-weight | 600 |
| .site-form label | color | var(--ink-soft) |
| .site-form input | padding | .65rem .8rem |
| .site-form input | border | 1px solid var(--line) |
| .site-form input | border-radius | 10px |
| .site-form input | font | inherit |
| .site-form input | background | #fdfcfb |
| .site-form input | transition | border-color .15s ease, box-shadow .15s ease |
| .site-form textarea | padding | .65rem .8rem |
| .site-form textarea | border | 1px solid var(--line) |
| .site-form textarea | border-radius | 10px |
| .site-form textarea | font | inherit |
| .site-form textarea | background | #fdfcfb |
| .site-form textarea | transition | border-color .15s ease, box-shadow .15s ease |
| .site-form select | padding | .65rem .8rem |
| .site-form select | border | 1px solid var(--line) |
| .site-form select | border-radius | 10px |
| .site-form select | font | inherit |
| .site-form select | background | #fdfcfb |
| .site-form select | transition | border-color .15s ease, box-shadow .15s ease |
| .site-form input:focus | outline | none |
| .site-form input:focus | border-color | var(--accent) |
| .site-form input:focus | box-shadow | 0 0 0 3px rgba(79,70,229,.12) |
| .site-form textarea:focus | outline | none |
| .site-form textarea:focus | border-color | var(--accent) |
| .site-form textarea:focus | box-shadow | 0 0 0 3px rgba(79,70,229,.12) |
| .site-form select:focus | outline | none |
| .site-form select:focus | border-color | var(--accent) |
| .site-form select:focus | box-shadow | 0 0 0 3px rgba(79,70,229,.12) |
| .site-form input[readonly] | background | #f5f5f4 |
| .site-form input[readonly] | color | var(--muted) |
| .site-form textarea | min-height | 10rem |
| .site-form textarea | resize | vertical |
| .site-form .err | color | #b91c1c |
| .site-form .err | font-size | .85rem |
| .site-form .actions | display | flex |
| .site-form .actions | gap | .75rem |
| .site-form .actions | align-items | center |
| .site-form .actions | flex-wrap | wrap |
| .site-form .actions | padding-top | .25rem |
| .site-form button | background | linear-gradient(120deg, var(--accent), var(--accent-2)) |
| .site-form button | color | var(--accent-ink) |
| .site-form button | border | 0 |
| .site-form button | padding | .6rem 1.3rem |
| .site-form button | border-radius | 999px |
| .site-form button | cursor | pointer |
| .site-form button | font-weight | 600 |
| .site-form button | font-size | .95rem |
| .site-form button | transition | opacity .15s ease, transform .15s ease, box-shadow .15s ease |
| .site-form button:hover | opacity | .92 |
| .site-form button:hover | transform | translateY(-1px) |
| .site-form button:hover | box-shadow | 0 6px 18px rgba(79,70,229,.3) |
| .site-form a.btn | display | inline-block |
| .site-form a.btn | padding | .6rem 1.3rem |
| .site-form a.btn | border-radius | 999px |
| .site-form a.btn | border | 1px solid var(--line) |
| .site-form a.btn | color | var(--ink-soft) |
| .site-form a.btn | text-decoration | none |
| .site-form a.btn | font-weight | 500 |
| .site-form a.btn | font-size | .95rem |
| .site-form .meta | color | var(--muted) |
| .site-form .meta | font-size | .9rem |
| .site-form .admin-list | margin | 0 |
| .site-form .admin-list | padding | 0 |
| .site-form .admin-list | list-style | none |
| .site-form .admin-list | display | grid |
| .site-form .admin-list | gap | .5rem |
| .site-form .admin-list li | background | #fdfcfb |
| .site-form .admin-list li | border | 1px solid var(--line) |
| .site-form .admin-list li | border-radius | 10px |
| .site-form .admin-list li | padding | .6rem .9rem |
| .site-form .admin-list li | display | flex |
| .site-form .admin-list li | justify-content | space-between |
| .site-form .admin-list li | align-items | center |
| .site-form .admin-list li | gap | 1rem |
| .site-form .admin-list a | color | var(--accent) |
| .site-form .admin-list a | text-decoration | none |
| .site-form .admin-list a | font-size | .9rem |
**`表单`**
## 响应式
窄屏收为单栏,导航换行。
`响应式` =
| 媒体 | 选择器 | 属性 | 值 |
|------|--------|------|-----|
| (max-width: 860px) | body.has-sidebar | grid-template-columns | 1fr |
| (max-width: 860px) | body.has-sidebar | grid-template-areas | "top" "main" "side" "foot" |
| (max-width: 860px) | aside.side | border-right | 0 |
| (max-width: 860px) | aside.side | border-bottom | 1px solid var(--line) |
| (max-width: 860px) | aside.side | padding | 1rem 2rem |
| (max-width: 860px) | ul.side-nav | flex-direction | row |
| (max-width: 860px) | ul.side-nav | flex-wrap | wrap |
| (max-width: 860px) | main.main | padding | 1.75rem 1.25rem 2.5rem |
| (max-width: 860px) | header.topnav | padding | .75rem 1.25rem |
| (max-width: 860px) | footer.foot | padding | 1.2rem 1.25rem |
| (max-width: 860px) | .content.cards | grid-template-columns | 1fr |
| (max-width: 520px) | ul.nav | flex-wrap | wrap |
**`响应式`**
## 全局
用 样式装配 函数逐个把段落表装配成 CSS,再拼接成完整样式表。
*基础表 = > 基础*
*顶栏表 = > 顶栏*
*侧栏表 = > 侧栏*
*主体表 = > 主体*
*卡片表 = > 卡片*
*页脚表 = > 页脚*
*表单表 = > 表单*
*响应式表 = > 响应式*
*css基础 = > 网页.样式装配 名="基础" 表=`基础表`*
*css顶栏 = > 网页.样式装配 名="顶栏" 表=`顶栏表`*
*css侧栏 = > 网页.样式装配 名="侧栏" 表=`侧栏表`*
*css主体 = > 网页.样式装配 名="主体" 表=`主体表`*
*css卡片 = > 网页.样式装配 名="卡片" 表=`卡片表`*
*css页脚 = > 网页.样式装配 名="页脚" 表=`页脚表`*
*css表单 = > 网页.样式装配 名="表单" 表=`表单表`*
*css响应式 = > 网页.样式装配 名="响应式" 表=`响应式表`*
`css段` =
| css |
|-----|
| `css基础` |
| `css顶栏` |
| `css侧栏` |
| `css主体` |
| `css卡片` |
| `css页脚` |
| `css表单` |
| `css响应式` |
*css = > text.str_join xs=`css段` sep=""*
**css**