From 645444fcb82a6c70cd877657f5400662d7949831 Mon Sep 17 00:00:00 2001 From: Zhang Jinnan Date: Fri, 27 Nov 2026 12:09:09 +0800 Subject: [PATCH] feat: add five zero-dependency starter projects for first contributions --- README.md | 14 + tasks/starters/README.md | 79 ++++++ tasks/starters/commit-heatmap/README.md | 79 ++++++ tasks/starters/commit-heatmap/app.js | 276 +++++++++++++++++++ tasks/starters/commit-heatmap/data.js | 60 +++++ tasks/starters/commit-heatmap/index.html | 59 +++++ tasks/starters/commit-heatmap/styles.css | 121 +++++++++ tasks/starters/contributor-wall/README.md | 78 ++++++ tasks/starters/contributor-wall/app.js | 295 +++++++++++++++++++++ tasks/starters/contributor-wall/data.js | 80 ++++++ tasks/starters/contributor-wall/index.html | 60 +++++ tasks/starters/contributor-wall/styles.css | 170 ++++++++++++ tasks/starters/glossary-cards/README.md | 77 ++++++ tasks/starters/glossary-cards/app.js | 243 +++++++++++++++++ tasks/starters/glossary-cards/data.js | 88 ++++++ tasks/starters/glossary-cards/index.html | 57 ++++ tasks/starters/glossary-cards/styles.css | 164 ++++++++++++ tasks/starters/index.html | 163 ++++++++++++ tasks/starters/issue-builder/README.md | 77 ++++++ tasks/starters/issue-builder/app.js | 193 ++++++++++++++ tasks/starters/issue-builder/index.html | 106 ++++++++ tasks/starters/issue-builder/styles.css | 120 +++++++++ tasks/starters/license-picker/README.md | 78 ++++++ tasks/starters/license-picker/app.js | 198 ++++++++++++++ tasks/starters/license-picker/data.js | 85 ++++++ tasks/starters/license-picker/index.html | 70 +++++ tasks/starters/license-picker/styles.css | 110 ++++++++ 27 files changed, 3200 insertions(+) create mode 100644 tasks/starters/README.md create mode 100644 tasks/starters/commit-heatmap/README.md create mode 100644 tasks/starters/commit-heatmap/app.js create mode 100644 tasks/starters/commit-heatmap/data.js create mode 100644 tasks/starters/commit-heatmap/index.html create mode 100644 tasks/starters/commit-heatmap/styles.css create mode 100644 tasks/starters/contributor-wall/README.md create mode 100644 tasks/starters/contributor-wall/app.js create mode 100644 tasks/starters/contributor-wall/data.js create mode 100644 tasks/starters/contributor-wall/index.html create mode 100644 tasks/starters/contributor-wall/styles.css create mode 100644 tasks/starters/glossary-cards/README.md create mode 100644 tasks/starters/glossary-cards/app.js create mode 100644 tasks/starters/glossary-cards/data.js create mode 100644 tasks/starters/glossary-cards/index.html create mode 100644 tasks/starters/glossary-cards/styles.css create mode 100644 tasks/starters/index.html create mode 100644 tasks/starters/issue-builder/README.md create mode 100644 tasks/starters/issue-builder/app.js create mode 100644 tasks/starters/issue-builder/index.html create mode 100644 tasks/starters/issue-builder/styles.css create mode 100644 tasks/starters/license-picker/README.md create mode 100644 tasks/starters/license-picker/app.js create mode 100644 tasks/starters/license-picker/data.js create mode 100644 tasks/starters/license-picker/index.html create mode 100644 tasks/starters/license-picker/styles.css diff --git a/README.md b/README.md index 478f41e..af286bd 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,20 @@ 初次参与不必从复杂任务开始。修正文档、补充复现步骤、整理社区资料、改进一段英文表达,都是有价值的起点。 +## 基础任务:五个可以直接打开的小项目 + +[`tasks/starters/`](tasks/starters/) 下有五个纯 HTML + CSS + JavaScript 的小项目,零依赖、无需构建、离线可运行。每个项目都是一个完整的小作品,也是一个可以认领和改进的任务: + +| 项目 | 解决的问题 | 主要练习 | +| --- | --- | --- | +| [许可证选择器](tasks/starters/license-picker/) | 不知道该选哪个许可证 | 合规判断、决策逻辑 | +| [贡献者名片墙](tasks/starters/contributor-wall/) | 贡献难以被看见 | 数据筛选、Canvas 导出 | +| [术语双语卡](tasks/starters/glossary-cards/) | 中英术语不一致 | 国际化表达、状态管理 | +| [Issue 模板生成器](tasks/starters/issue-builder/) | Issue 缺信息、难复现 | 协作规范、表单校验 | +| [提交活跃热力图](tasks/starters/commit-heatmap/) | 活跃度看不清 | SVG 绘制、可访问性 | + +打开 [`tasks/starters/index.html`](tasks/starters/index.html) 可以看到入口页。每个项目的 `README.md` 都写明了验收标准与可认领的改进方向,适合作为第一次 PR 的对象。 + ## 两条相互促进的实践路径 ### 路径一:完成开源项目实践 diff --git a/tasks/starters/README.md b/tasks/starters/README.md new file mode 100644 index 0000000..635a359 --- /dev/null +++ b/tasks/starters/README.md @@ -0,0 +1,79 @@ +# 入门项目:五个可以直接打开的小作品 + +这里是课程的**基础任务区**。每个项目都是一个完整、可运行的小作品,也是一个可以认领的开源协作任务。 + +设计原则只有三条: + +1. **零依赖**:纯 HTML + CSS + JavaScript,不用框架、不用构建、不联网。双击 `index.html` 就能跑。 +2. **小而完整**:一个项目在一到两次课内可以读懂、改对、交出去。 +3. **可被分享**:作品本身就能作为“创意社区”式的公开产出,而不只是练习。 + +## 五个项目 + +| 项目 | 解决的问题 | 主要练到的能力 | 难度 | 建议投入 | +| --- | --- | --- | --- | --- | +| [license-picker](./license-picker/) 许可证选择器 | 不知道该给项目选哪个许可证 | 许可证与合规、决策逻辑 | 入门 | 2—3 小时 | +| [contributor-wall](./contributor-wall/) 贡献者名片墙 | 如何让贡献被看见、被认可 | 数据结构、筛选排序、Canvas 导出 | 入门 | 3—4 小时 | +| [glossary-cards](./glossary-cards/) 术语双语卡 | 中英术语不一致导致沟通成本 | 国际化表达、状态管理、键盘操作 | 入门 | 3—4 小时 | +| [issue-builder](./issue-builder/) Issue 模板生成器 | 新手提的 Issue 缺信息、难复现 | 协作规范、表单校验、剪贴板 | 入门 | 2—3 小时 | +| [commit-heatmap](./commit-heatmap/) 提交活跃热力图 | 社区活跃度说不清、看不清 | 数据可视化、SVG、可访问性 | 入门+ | 4—5 小时 | + +打开 [`index.html`](./index.html) 可以看到这五个项目的入口页。 + +## 怎么跑起来 + +不需要安装任何东西: + +- 直接双击某个项目的 `index.html`; +- 或在仓库根目录执行 `python3 -m http.server 8000`,再访问 `http://localhost:8000/tasks/starters/`。 + +两种方式都支持。代码里刻意没有使用 `fetch()` 读取本地 JSON,就是为了让 `file://` 下也能正常工作——数据统一放在 `data.js` 里,通过 ` + + + diff --git a/tasks/starters/commit-heatmap/styles.css b/tasks/starters/commit-heatmap/styles.css new file mode 100644 index 0000000..d956c4d --- /dev/null +++ b/tasks/starters/commit-heatmap/styles.css @@ -0,0 +1,121 @@ +:root { + --bg: #f7f7f5; + --surface: #ffffff; + --text: #1c1c1a; + --muted: #6b6b66; + --line: #e3e3de; + --accent: #2f6f4f; + --accent-soft: #e8f1eb; + --shadow: 0 1px 2px rgba(28, 28, 26, .05), 0 10px 30px rgba(28, 28, 26, .05); + --l0: #ebedea; + --l1: #c6ddcd; + --l2: #8dbfa0; + --l3: #4f9a72; + --l4: #2f6f4f; +} +@media (prefers-color-scheme: dark) { + :root { + --bg: #16181a; + --surface: #1e2124; + --text: #e9e9e4; + --muted: #9a9a94; + --line: #2f3336; + --accent: #7fbd9a; + --accent-soft: #23302a; + --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 10px 30px rgba(0, 0, 0, .25); + --l0: #24282b; + --l1: #2c4a39; + --l2: #3f7154; + --l3: #5b9a76; + --l4: #8ec4a4; + } +} +* { box-sizing: border-box; } +body { + margin: 0; + padding: 40px 20px 64px; + background: var(--bg); + color: var(--text); + font: 16px/1.65 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif; + -webkit-font-smoothing: antialiased; +} +code { font-size: 12px; } +.page-head, main, .page-foot { max-width: 1000px; margin: 0 auto; } +.crumb { margin: 0 0 14px; font-size: 13px; color: var(--muted); } +.crumb a { color: var(--accent); text-decoration: none; } +.crumb a:hover { text-decoration: underline; } +h1 { margin: 0 0 8px; font-size: clamp(26px, 3.6vw, 34px); letter-spacing: -.01em; } +.lede { margin: 0 0 28px; max-width: 58ch; color: var(--muted); } + +.panel { + padding: 22px; + background: var(--surface); + border: 1px solid var(--line); + border-radius: 12px; + box-shadow: var(--shadow); +} +.panel-head { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-start; justify-content: space-between; margin-bottom: 18px; } +.panel-head h2 { margin: 0; font-size: 17px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; } +.sub { margin: 3px 0 0; font-size: 12.5px; color: var(--muted); } +.years { display: inline-flex; gap: 2px; padding: 3px; border: 1px solid var(--line); border-radius: 999px; } +.years button { + font: inherit; + font-size: 13px; + padding: 5px 14px; + border: 0; + border-radius: 999px; + background: transparent; + color: var(--muted); + cursor: pointer; + font-variant-numeric: tabular-nums; +} +.years button[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); } +.years button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; } + +.chart-wrap { position: relative; overflow-x: auto; padding-bottom: 4px; } +#chart { display: block; min-width: 640px; } +#chart:focus-visible { outline: 2px solid var(--accent); outline-offset: 6px; border-radius: 8px; } +#chart text { fill: var(--muted); font-size: 10px; } +#chart rect.cell { stroke: none; } +#chart rect.cursor { stroke: var(--text); stroke-width: 2; } +.lvl-0 { fill: var(--l0); background: var(--l0); } +.lvl-1 { fill: var(--l1); background: var(--l1); } +.lvl-2 { fill: var(--l2); background: var(--l2); } +.lvl-3 { fill: var(--l3); background: var(--l3); } +.lvl-4 { fill: var(--l4); background: var(--l4); } + +.tip { + position: absolute; + z-index: 2; + padding: 6px 9px; + border-radius: 6px; + background: var(--text); + color: var(--bg); + font-size: 12px; + white-space: nowrap; + pointer-events: none; + transform: translate(-50%, -130%); +} +.live { margin: 10px 0 0; font-size: 12.5px; color: var(--muted); } +.legend { display: flex; align-items: center; gap: 5px; margin-top: 12px; font-size: 12px; color: var(--muted); } +.swatch { width: 13px; height: 13px; border-radius: 3px; display: inline-block; } + +.stats { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); margin-top: 16px; } +.stat { margin: 0; padding: 14px 16px; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; } +.stat dt { margin: 0 0 4px; font-size: 12px; color: var(--muted); } +.stat dd { margin: 0; font-size: 22px; font-weight: 600; font-variant-numeric: tabular-nums; } +.stat dd small { font-size: 12px; font-weight: 400; color: var(--muted); margin-left: 3px; } + +.insight { margin: 18px 0 0; padding: 14px 16px; border-left: 3px solid var(--accent); background: var(--accent-soft); border-radius: 0 8px 8px 0; font-size: 14px; } +.tip-text { margin: 14px 0 0; font-size: 12.5px; color: var(--muted); } +.sr-only { + position: absolute; + width: 1px; height: 1px; + padding: 0; margin: -1px; + overflow: hidden; + clip: rect(0 0 0 0); + white-space: nowrap; + border: 0; +} +.page-foot { margin-top: 30px; font-size: 12.5px; color: var(--muted); } +@media (prefers-reduced-motion: reduce) { * { transition: none !important; } } diff --git a/tasks/starters/contributor-wall/README.md b/tasks/starters/contributor-wall/README.md new file mode 100644 index 0000000..2c739a4 --- /dev/null +++ b/tasks/starters/contributor-wall/README.md @@ -0,0 +1,78 @@ +# 贡献者名片墙 + +> 把贡献者、角色与语言整理成可筛选的卡片,并能导出自己的贡献卡。 + +## 为什么做这个 + +开源项目的贡献很容易被压缩成一个数字:合并了几个 PR、提交了多少行。但真正让新人有归属感的,往往是另一种信息——谁在做什么、谁会说哪种语言、遇到问题可以找谁。 + +这个页面把“贡献者名单”从一张表格变成可以被浏览、筛选和分享的东西,也让“认可”这件事有了具体的载体。 + +## 学习目标 + +- 用数组和对象描述一组人,理解数据与视图分离; +- 练习筛选、搜索、排序的组合逻辑,注意三者同时生效时的行为; +- 用 Canvas 在浏览器里生成一张图片并下载,理解绘制顺序与坐标; +- 处理空状态、无匹配结果、API 不可用等边界情况; +- 认识一个原则:公开他人信息前必须取得同意。 + +## 现在能做什么 + +- 九位示例贡献者,含姓名、账号、角色、语言、加入时间与一句说明; +- 关键词搜索(姓名、账号、角色、语言、说明都参与匹配); +- 角色筛选(胶囊按钮,带 `aria-pressed` 状态); +- 三种排序:默认、按姓名、按加入时间; +- 结果计数与空状态提示; +- 点击“生成贡献卡”在 `` 中预览 1080×1350 图片,可下载 PNG。 + +## 运行 + +双击 `index.html`。数据在 `data.js` 中,修改后刷新即可看到变化。 + +```bash +python3 -m http.server 8000 +# 打开 http://localhost:8000/contributor-wall/ +``` + +## 验收标准 + +- [ ] 搜索、筛选、排序可以同时生效,结果计数正确; +- [ ] 无匹配结果时显示空状态,不残留上一轮卡片; +- [ ] 贡献卡预览与所选人物一致,中文不出现乱码或截断; +- [ ] 窄屏(375px)下卡片单列排列,弹窗不溢出屏幕; +- [ ] 弹窗可用 Esc 关闭,关闭按钮有可读的名称; +- [ ] 筛选按钮可用键盘操作,状态变化可被读屏感知; +- [ ] 页面注明“示例数据”与“公开前需取得同意”。 + +## 可以认领的改进 + +1. **补字段**:增加“首次贡献类型”“导师”或“时区”,并让搜索覆盖新字段。 +2. **改卡面**:给贡献卡加二维码(用纯 JS 生成会很难,可以先放占位并说明取舍)。 +3. **多语言**:界面支持中英切换,注意 `lang` 属性与日期格式。 +4. **空状态优化**:提供“清除筛选”按钮,而不是让用户自己找原因。 +5. **性能**:贡献者增至几百人时改用分页或虚拟列表,并记录改动前后的渲染耗时。 +6. **数据校验**:加载时检查必填字段,缺失时在页面上明确提示哪一条数据有问题。 +7. **导出全部**:把当前筛选结果导出为 CSV,注意中文 Excel 的 BOM 问题。 + +不建议做的事:把贡献者按“贡献大小”排序并显示排名。这个页面的目的是让人被看见,不是给人排队。 + +## 已知局限 + +- 示例数据为虚构,不代表任何真实个人; +- 未做头像上传,避免处理图片与隐私问题; +- Canvas 导出的字体依赖系统,不同机器上字重可能略有差异; +- 不支持深色卡面切换。 + +## 文件说明 + +| 文件 | 作用 | +| --- | --- | +| `index.html` | 页面结构:工具栏、筛选区、卡片网格、弹窗 | +| `styles.css` | 布局与配色,跟随系统深浅色 | +| `data.js` | 贡献者示例数据 | +| `app.js` | 筛选、排序、渲染、Canvas 绘制与下载 | +| `README.md` | 本文件 | + +## 变更记录 + +- 初版:搜索、角色筛选、三种排序、贡献卡导出。 diff --git a/tasks/starters/contributor-wall/app.js b/tasks/starters/contributor-wall/app.js new file mode 100644 index 0000000..1e6dff5 --- /dev/null +++ b/tasks/starters/contributor-wall/app.js @@ -0,0 +1,295 @@ +(function () { + "use strict"; + + var DATA = window.WALL_DATA; + var people = DATA.contributors.slice(); + + var grid = document.getElementById("grid"); + var empty = document.getElementById("empty"); + var countEl = document.getElementById("count"); + var searchEl = document.getElementById("search"); + var sortEl = document.getElementById("sort"); + var roleWrap = document.getElementById("roleFilters"); + + var dialog = document.getElementById("cardDialog"); + var canvas = document.getElementById("cardCanvas"); + var downloadLink = document.getElementById("downloadCard"); + + var state = { query: "", role: "all", sort: "default" }; + var lastCardHref = ""; + + var PALETTE = ["#34557a", "#2f6f4f", "#7a4a34", "#5a4a7a", "#2f6a6a", "#7a3f52", "#4a5a2f", "#3f4a5a"]; + + function colorFor(name) { + var sum = 0; + for (var i = 0; i < name.length; i += 1) { + sum += name.charCodeAt(i); + } + return PALETTE[sum % PALETTE.length]; + } + + function el(tag, className, text) { + var node = document.createElement(tag); + if (className) node.className = className; + if (text != null) node.textContent = text; + return node; + } + + function roles() { + var seen = {}; + var list = []; + people.forEach(function (p) { + if (!seen[p.role]) { + seen[p.role] = true; + list.push(p.role); + } + }); + return list; + } + + function buildRoleChips() { + var options = [{ value: "all", label: "全部" }].concat( + roles().map(function (r) { + return { value: r, label: r }; + }) + ); + roleWrap.textContent = ""; + options.forEach(function (opt) { + var btn = el("button", "chip", opt.label); + btn.type = "button"; + btn.setAttribute("aria-pressed", String(state.role === opt.value)); + btn.addEventListener("click", function () { + state.role = opt.value; + Array.prototype.forEach.call(roleWrap.children, function (child) { + child.setAttribute("aria-pressed", String(child === btn)); + }); + render(); + }); + roleWrap.appendChild(btn); + }); + } + + function matches(person) { + if (state.role !== "all" && person.role !== state.role) return false; + var q = state.query.trim().toLowerCase(); + if (!q) return true; + var haystack = [person.name, person.handle, person.role, person.note] + .concat(person.langs) + .join(" ") + .toLowerCase(); + return haystack.indexOf(q) !== -1; + } + + function sortList(list) { + var copy = list.slice(); + if (state.sort === "name") { + copy.sort(function (a, b) { + return a.name.localeCompare(b.name, "zh-Hans-CN"); + }); + } else if (state.sort === "since") { + copy.sort(function (a, b) { + return a.since < b.since ? 1 : a.since > b.since ? -1 : 0; + }); + } + return copy; + } + + function render() { + var list = sortList(people.filter(matches)); + grid.textContent = ""; + + list.forEach(function (person) { + var li = el("li", "person"); + + var top = el("div", "person-top"); + var avatar = el("span", "avatar", person.name.slice(0, 1)); + avatar.style.background = colorFor(person.name); + avatar.setAttribute("aria-hidden", "true"); + var idBox = el("div"); + idBox.appendChild(el("h2", null, person.name)); + idBox.appendChild(el("p", "handle", person.handle)); + top.appendChild(avatar); + top.appendChild(idBox); + li.appendChild(top); + + li.appendChild(el("p", "note", person.note)); + + var meta = el("div", "person-meta"); + meta.appendChild(el("span", "tag", person.role)); + person.langs.forEach(function (lang) { + meta.appendChild(el("span", "tag lang", lang)); + }); + li.appendChild(meta); + + var foot = el("div", "person-foot"); + foot.appendChild(el("span", "since", "加入于 " + person.since)); + var btn = el("button", "card-btn", "生成贡献卡"); + btn.type = "button"; + btn.addEventListener("click", function () { + openCard(person); + }); + foot.appendChild(btn); + li.appendChild(foot); + + grid.appendChild(li); + }); + + empty.hidden = list.length > 0; + countEl.textContent = + "显示 " + list.length + " / " + people.length + " 位贡献者" + + (state.role === "all" ? "" : ",角色:" + state.role); + } + + function roundRect(ctx, x, y, w, h, r) { + ctx.beginPath(); + ctx.moveTo(x + r, y); + ctx.arcTo(x + w, y, x + w, y + h, r); + ctx.arcTo(x + w, y + h, x, y + h, r); + ctx.arcTo(x, y + h, x, y, r); + ctx.arcTo(x, y, x + w, y, r); + ctx.closePath(); + } + + function wrapText(ctx, text, x, y, maxWidth, lineHeight, maxLines) { + var chars = String(text).split(""); + var line = ""; + var lines = []; + for (var i = 0; i < chars.length; i += 1) { + var test = line + chars[i]; + if (ctx.measureText(test).width > maxWidth && line) { + lines.push(line); + line = chars[i]; + if (maxLines && lines.length === maxLines - 1) break; + } else { + line = test; + } + } + if (line) lines.push(line); + lines.slice(0, maxLines || lines.length).forEach(function (item, index) { + ctx.fillText(item, x, y + index * lineHeight); + }); + } + + function drawCard(person) { + var ctx = canvas.getContext("2d"); + var W = canvas.width; + var H = canvas.height; + + var bg = ctx.createLinearGradient(0, 0, W, H); + bg.addColorStop(0, "#1d2b38"); + bg.addColorStop(0.55, "#24384a"); + bg.addColorStop(1, "#31536b"); + ctx.fillStyle = bg; + ctx.fillRect(0, 0, W, H); + + ctx.strokeStyle = "rgba(255,255,255,.14)"; + ctx.lineWidth = 2; + roundRect(ctx, 56, 56, W - 112, H - 112, 28); + ctx.stroke(); + + ctx.fillStyle = "rgba(255,255,255,.62)"; + ctx.font = "500 24px -apple-system, 'PingFang SC', 'Microsoft YaHei', sans-serif"; + ctx.fillText("CONTRIBUTOR CARD", 104, 148); + + ctx.fillStyle = colorFor(person.name); + ctx.beginPath(); + ctx.arc(164, 300, 60, 0, Math.PI * 2); + ctx.fill(); + ctx.fillStyle = "#ffffff"; + ctx.font = "600 46px -apple-system, 'PingFang SC', 'Microsoft YaHei', sans-serif"; + ctx.textAlign = "center"; + ctx.fillText(person.name.slice(0, 1), 164, 316); + ctx.textAlign = "left"; + + ctx.fillStyle = "#ffffff"; + ctx.font = "600 62px -apple-system, 'PingFang SC', 'Microsoft YaHei', sans-serif"; + ctx.fillText(person.name, 252, 292); + + ctx.fillStyle = "rgba(255,255,255,.7)"; + ctx.font = "400 28px ui-monospace, Menlo, monospace"; + ctx.fillText(person.handle, 254, 336); + + ctx.fillStyle = "rgba(255,255,255,.16)"; + roundRect(ctx, 104, 410, 190, 54, 27); + ctx.fill(); + ctx.fillStyle = "#eaf1f7"; + ctx.font = "500 26px -apple-system, 'PingFang SC', 'Microsoft YaHei', sans-serif"; + ctx.fillText(person.role, 138, 445); + + ctx.fillStyle = "#ffffff"; + ctx.font = "400 36px -apple-system, 'PingFang SC', 'Microsoft YaHei', sans-serif"; + wrapText(ctx, person.note, 104, 560, W - 208, 56, 4); + + ctx.fillStyle = "rgba(255,255,255,.7)"; + ctx.font = "400 26px -apple-system, 'PingFang SC', 'Microsoft YaHei', sans-serif"; + ctx.fillText("语言 · " + person.langs.join(" / "), 104, 830); + + ctx.strokeStyle = "rgba(255,255,255,.18)"; + ctx.beginPath(); + ctx.moveTo(104, 900); + ctx.lineTo(W - 104, 900); + ctx.stroke(); + + ctx.fillStyle = "rgba(255,255,255,.86)"; + ctx.font = "500 30px -apple-system, 'PingFang SC', 'Microsoft YaHei', sans-serif"; + ctx.fillText(DATA.repo, 104, 972); + + ctx.fillStyle = "rgba(255,255,255,.58)"; + ctx.font = "400 24px -apple-system, 'PingFang SC', 'Microsoft YaHei', sans-serif"; + ctx.fillText("加入于 " + person.since, 104, 1016); + + ctx.fillStyle = "rgba(255,255,255,.86)"; + ctx.font = "400 26px -apple-system, 'PingFang SC', 'Microsoft YaHei', sans-serif"; + ctx.fillText("开源项目国际化运营 · 课程实践", 104, H - 130); + + ctx.fillStyle = "rgba(255,255,255,.5)"; + ctx.font = "400 22px -apple-system, 'PingFang SC', 'Microsoft YaHei', sans-serif"; + ctx.fillText("本卡片由本地生成,未上传任何数据", 104, H - 92); + + canvas.setAttribute("aria-label", person.name + " 的贡献卡预览图"); + try { + lastCardHref = canvas.toDataURL("image/png"); + downloadLink.href = lastCardHref; + downloadLink.download = "contributor-" + person.handle.replace(/[^a-z0-9-]/gi, "") + ".png"; + downloadLink.hidden = false; + } catch (error) { + downloadLink.hidden = true; + } + } + + function openCard(person) { + drawCard(person); + document.getElementById("dialogTitle").textContent = person.name + " 的贡献卡"; + if (typeof dialog.showModal === "function") { + dialog.showModal(); + } else { + dialog.setAttribute("open", ""); + } + } + + function closeCard() { + if (typeof dialog.close === "function") { + dialog.close(); + } else { + dialog.removeAttribute("open"); + } + } + + searchEl.addEventListener("input", function () { + state.query = searchEl.value; + render(); + }); + sortEl.addEventListener("change", function () { + state.sort = sortEl.value; + render(); + }); + + document.getElementById("closeDialog").addEventListener("click", closeCard); + document.getElementById("closeDialog2").addEventListener("click", closeCard); + dialog.addEventListener("click", function (event) { + if (event.target === dialog) closeCard(); + }); + + buildRoleChips(); + render(); +})(); diff --git a/tasks/starters/contributor-wall/data.js b/tasks/starters/contributor-wall/data.js new file mode 100644 index 0000000..f8b49f2 --- /dev/null +++ b/tasks/starters/contributor-wall/data.js @@ -0,0 +1,80 @@ +/* 示例数据:姓名与账号均为虚构,仅用于演示结构。 + 替换为真实名单前,请先取得本人同意,并说明公开范围。 */ +window.WALL_DATA = { + repo: "open-origin", + updated: "2026-11", + contributors: [ + { + name: "林小满", + handle: "@lin-xm", + role: "文档", + langs: ["zh", "en"], + since: "2026-09", + note: "把 README 从说明书改成了能照着做的入门路径。", + }, + { + name: "周叙", + handle: "@zhouxu", + role: "本地化", + langs: ["zh", "en", "ja"], + since: "2026-09", + note: "维护术语表,专门处理那些直译过来就不通的词。", + }, + { + name: "陈砚", + handle: "@chenyan", + role: "开发", + langs: ["zh", "en"], + since: "2026-10", + note: "给课程仓库补了一套离线可用的示例项目。", + }, + { + name: "Ravi K.", + handle: "@ravi-k", + role: "评审", + langs: ["en", "hi"], + since: "2026-10", + note: "习惯先问“这个改动解决了谁的问题”,再谈实现。", + }, + { + name: "苏禾", + handle: "@suhe", + role: "设计", + langs: ["zh"], + since: "2026-10", + note: "负责活动海报与课件排版,坚持正文先能读,再谈好看。", + }, + { + name: "郑一舟", + handle: "@yizhou", + role: "运营", + langs: ["zh", "en"], + since: "2026-10", + note: "组织过两次线上共学,把录屏和笔记都留在了仓库里。", + }, + { + name: "Marta L.", + handle: "@marta-l", + role: "社区支持", + langs: ["en", "es"], + since: "2026-11", + note: "在 Issue 区做首次响应,帮新人把问题描述完整。", + }, + { + name: "何晴", + handle: "@heqing", + role: "活动", + langs: ["zh", "en"], + since: "2026-11", + note: "策划了 COSCON 参会分享,让见闻变成可复用的内容。", + }, + { + name: "王砚秋", + handle: "@wangyq", + role: "文档", + langs: ["zh", "de"], + since: "2026-11", + note: "把散落在聊天记录里的约定,整理成了公开的协作规范。", + }, + ], +}; diff --git a/tasks/starters/contributor-wall/index.html b/tasks/starters/contributor-wall/index.html new file mode 100644 index 0000000..ad92d82 --- /dev/null +++ b/tasks/starters/contributor-wall/index.html @@ -0,0 +1,60 @@ + + + + + +贡献者名片墙 · 入门项目 + + + +
+

入门项目 / 02

+

贡献者名片墙

+

把贡献者、角色和语言整理成可筛选的卡片。认可不该只发生在合并 PR 的那一刻。

+
+ +
+
+
+ + +
+
+ + +
+
+ +
+ +

+ +
    + +
    + + +
    +

    贡献卡预览

    + +
    + +
    + 下载图片 + +
    +

    图片只在本机生成,不会上传到任何地方。

    +
    + +
    +

    页面中的贡献者是示例数据,替换为真实名单前请先取得本人同意。

    +
    + + + + + diff --git a/tasks/starters/contributor-wall/styles.css b/tasks/starters/contributor-wall/styles.css new file mode 100644 index 0000000..a82f6b4 --- /dev/null +++ b/tasks/starters/contributor-wall/styles.css @@ -0,0 +1,170 @@ +:root { + --bg: #f7f7f5; + --surface: #ffffff; + --text: #1c1c1a; + --muted: #6b6b66; + --line: #e3e3de; + --accent: #34557a; + --accent-soft: #e7edf4; + --shadow: 0 1px 2px rgba(28, 28, 26, .05), 0 10px 30px rgba(28, 28, 26, .05); +} +@media (prefers-color-scheme: dark) { + :root { + --bg: #16181a; + --surface: #1e2124; + --text: #e9e9e4; + --muted: #9a9a94; + --line: #2f3336; + --accent: #8fb0d4; + --accent-soft: #212c38; + --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 10px 30px rgba(0, 0, 0, .25); + } +} +* { box-sizing: border-box; } +body { + margin: 0; + padding: 40px 20px 64px; + background: var(--bg); + color: var(--text); + font: 16px/1.65 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif; + -webkit-font-smoothing: antialiased; +} +a { color: var(--accent); } +.page-head, main, .page-foot { max-width: 1060px; margin: 0 auto; } +.crumb { margin: 0 0 14px; font-size: 13px; color: var(--muted); } +.crumb a { text-decoration: none; } +.crumb a:hover { text-decoration: underline; } +h1 { margin: 0 0 8px; font-size: clamp(26px, 3.6vw, 34px); letter-spacing: -.01em; } +.lede { margin: 0 0 28px; max-width: 56ch; color: var(--muted); } + +.toolbar { display: flex; flex-wrap: wrap; gap: 12px; margin-bottom: 14px; } +.field { display: flex; flex-direction: column; gap: 4px; min-width: 160px; } +.field.grow { flex: 1 1 260px; } +.field label { font-size: 12px; color: var(--muted); letter-spacing: .04em; } +input, select { + font: inherit; + font-size: 14px; + padding: 9px 11px; + color: var(--text); + background: var(--surface); + border: 1px solid var(--line); + border-radius: 8px; +} +input:focus-visible, select:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; } + +.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; } +.chip { + font: inherit; + font-size: 13px; + padding: 5px 12px; + border-radius: 999px; + border: 1px solid var(--line); + background: var(--surface); + color: var(--muted); + cursor: pointer; +} +.chip[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); } +.chip:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; } +.count { margin: 0 0 16px; font-size: 13px; color: var(--muted); } + +.grid { + list-style: none; + margin: 0; + padding: 0; + display: grid; + gap: 14px; + grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); +} +.person { + height: 100%; + display: flex; + flex-direction: column; + padding: 18px; + background: var(--surface); + border: 1px solid var(--line); + border-radius: 12px; + box-shadow: var(--shadow); +} +.person-top { display: flex; gap: 12px; align-items: center; margin-bottom: 12px; } +.avatar { + flex: none; + width: 44px; + height: 44px; + border-radius: 50%; + display: grid; + place-items: center; + font-size: 17px; + font-weight: 600; + color: #fff; + letter-spacing: .02em; +} +.person h2 { margin: 0; font-size: 16px; line-height: 1.3; } +.handle { margin: 2px 0 0; font-size: 12px; color: var(--muted); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; } +.note { margin: 0 0 14px; font-size: 13.5px; color: var(--muted); } +.person-meta { margin-top: auto; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; } +.tag { font-size: 11px; padding: 2px 8px; border-radius: 4px; background: var(--accent-soft); color: var(--accent); } +.tag.lang { background: transparent; border: 1px solid var(--line); color: var(--muted); } +.person-foot { + margin-top: 12px; + padding-top: 10px; + border-top: 1px solid var(--line); + display: flex; + align-items: center; + justify-content: space-between; + gap: 8px; +} +.since { font-size: 11.5px; color: var(--muted); } +.card-btn { + font: inherit; + font-size: 12.5px; + padding: 5px 10px; + border-radius: 6px; + border: 1px solid var(--accent); + background: transparent; + color: var(--accent); + cursor: pointer; +} +.card-btn:hover { background: var(--accent-soft); } +.empty { padding: 40px 0; text-align: center; color: var(--muted); font-size: 14px; } + +dialog { + width: min(420px, calc(100vw - 32px)); + padding: 18px; + border: 1px solid var(--line); + border-radius: 14px; + background: var(--surface); + color: var(--text); + box-shadow: 0 24px 60px rgba(0, 0, 0, .28); +} +dialog::backdrop { background: rgba(12, 14, 16, .55); } +.dialog-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; } +.dialog-head h2 { margin: 0; font-size: 16px; } +.icon-btn { + width: 30px; + height: 30px; + border-radius: 50%; + border: 1px solid var(--line); + background: transparent; + color: var(--muted); + font-size: 18px; + line-height: 1; + cursor: pointer; +} +canvas { width: 100%; height: auto; display: block; border-radius: 10px; border: 1px solid var(--line); } +.dialog-actions { display: flex; gap: 8px; margin-top: 14px; } +.btn { + font: inherit; + font-size: 13.5px; + padding: 8px 14px; + border-radius: 8px; + border: 1px solid var(--accent); + background: var(--accent); + color: var(--surface); + text-decoration: none; + text-align: center; +} +.btn.ghost { background: transparent; color: var(--accent); } +.btn:focus-visible, .icon-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; } +.hint { margin: 10px 0 0; font-size: 12px; color: var(--muted); } +.page-foot { margin-top: 32px; font-size: 12.5px; color: var(--muted); } +@media (prefers-reduced-motion: reduce) { * { transition: none !important; } } diff --git a/tasks/starters/glossary-cards/README.md b/tasks/starters/glossary-cards/README.md new file mode 100644 index 0000000..e896d32 --- /dev/null +++ b/tasks/starters/glossary-cards/README.md @@ -0,0 +1,77 @@ +# 术语双语卡 + +> 十二个高频术语,翻卡学习,切到自测模式查漏。 + +## 为什么做这个 + +跨语言协作里最贵的成本往往不是语法,而是同一个词被理解成两件事。比如把 issue 译成“问题”,功能建议就会看起来像故障报告;把 localization 和 internationalization 混用,讨论本地化方案时会各说各话。 + +这个项目把术语做成可翻阅的卡片,并且每条都附上“常见误区”——那通常才是分歧的真正来源。 + +## 学习目标 + +- 理解国际化(i18n)与本地化(l10n)的分工,而不是当成同义词; +- 认识协作流程中的基本概念:上游、下游、Issue、PR、fork、回归; +- 练习状态管理:卡片索引、翻转状态、模式切换; +- 练习键盘操作与读屏友好的动态内容更新; +- 练习用数据驱动界面:加一条数据,学习与自测同时生效。 + +## 现在能做什么 + +- 学习模式:正面中文术语与分类,背面英文、释义与常见误区; +- 点击卡片或按空格翻转,← → 切换上一张/下一张; +- 进度显示,首尾自动禁用对应按钮; +- 自测模式:随机抽 8 题,四选一,答后立即显示正确答案与释义; +- 结果页给出得分与错题清单,可重测或回到学习模式。 + +## 运行 + +双击 `index.html`。术语在 `data.js` 中,按现有字段追加即可。 + +```bash +python3 -m http.server 8000 +# 打开 http://localhost:8000/glossary-cards/ +``` + +## 验收标准 + +- [ ] 十二张卡片均可翻转,翻回正面时内容不残留上一张的文本; +- [ ] ← → 在首尾不会越界,按钮禁用状态与索引一致; +- [ ] 自测四选一不会出现重复选项,正确答案必在选项中; +- [ ] 答错后能同时看到正确答案与释义,而不是只说“错了”; +- [ ] 模式切换后焦点不丢失,读屏能感知面板变化; +- [ ] 关闭动画偏好(`prefers-reduced-motion`)时卡片不旋转但仍可切换内容; +- [ ] 375px 宽度下卡片文字不溢出。 + +## 可以认领的改进 + +1. **加术语**:补充“技术债”“复现步骤”“静默失败”等词,注意释义要能区分近义词。 +2. **反向自测**:给出英文,选中文;两种方向混出,检验是否真的理解。 +3. **错题重练**:只重做上次答错的题,而不是重新随机。 +4. **学习进度记忆**:用 `localStorage` 记住看到第几张,刷新后恢复。 +5. **术语表导出**:把当前数据导出为 Markdown 表格,方便贴进项目文档。 +6. **多语言界面**:界面文案支持中英切换,术语本身保持双语。 +7. **来源标注**:给每条术语补一个出处链接(如某项目的术语表),并注明访问日期。 + +不建议做的事:给术语加“重要程度”星级。重要性取决于读者场景,标星会误导。 + +## 已知局限 + +- 释义为课程整理,不是任何项目的官方定义; +- 只有中英一对,未覆盖其他语言; +- 自测固定 8 题,题库小于 8 条时会重复; +- 未做拼写或输入型题目。 + +## 文件说明 + +| 文件 | 作用 | +| --- | --- | +| `index.html` | 学习面板与自测面板的结构 | +| `styles.css` | 卡片翻转、配色与响应式 | +| `data.js` | 术语数据:中文、英文、分类、释义、误区 | +| `app.js` | 翻卡、键盘、出题、判分与结果 | +| `README.md` | 本文件 | + +## 变更记录 + +- 初版:12 条术语、翻卡学习、8 题自测与错题清单。 diff --git a/tasks/starters/glossary-cards/app.js b/tasks/starters/glossary-cards/app.js new file mode 100644 index 0000000..d901aa0 --- /dev/null +++ b/tasks/starters/glossary-cards/app.js @@ -0,0 +1,243 @@ +(function () { + "use strict"; + + var TERMS = window.GLOSSARY; + var study = { index: 0, flipped: false }; + var quiz = null; + + var card = document.getElementById("flashcard"); + var tagEl = document.getElementById("cardTag"); + var zhEl = document.getElementById("cardZh"); + var enEl = document.getElementById("cardEn"); + var defEl = document.getElementById("cardDef"); + var pitfallEl = document.getElementById("cardPitfall"); + var progressEl = document.getElementById("studyProgress"); + var prevBtn = document.getElementById("prev"); + var nextBtn = document.getElementById("next"); + + var tabStudy = document.getElementById("tabStudy"); + var tabQuiz = document.getElementById("tabQuiz"); + var studyPanel = document.getElementById("studyPanel"); + var quizPanel = document.getElementById("quizPanel"); + var quizBody = document.getElementById("quizBody"); + + function el(tag, className, text) { + var node = document.createElement(tag); + if (className) node.className = className; + if (text != null) node.textContent = text; + return node; + } + + function shuffle(list) { + var copy = list.slice(); + for (var i = copy.length - 1; i > 0; i -= 1) { + var j = Math.floor(Math.random() * (i + 1)); + var tmp = copy[i]; + copy[i] = copy[j]; + copy[j] = tmp; + } + return copy; + } + + function renderStudy() { + var term = TERMS[study.index]; + tagEl.textContent = term.tag + " · " + (study.index + 1); + zhEl.textContent = term.zh; + enEl.textContent = term.en; + defEl.textContent = term.def; + pitfallEl.textContent = "常见误区:" + term.pitfall; + progressEl.textContent = study.index + 1 + " / " + TERMS.length; + prevBtn.disabled = study.index === 0; + nextBtn.disabled = study.index === TERMS.length - 1; + card.classList.toggle("flipped", study.flipped); + card.setAttribute( + "aria-label", + study.flipped ? "背面:" + term.en + ",点击翻回中文" : "正面:" + term.zh + ",点击查看英文与释义" + ); + } + + function go(step) { + var next = study.index + step; + if (next < 0 || next >= TERMS.length) return; + study.index = next; + study.flipped = false; + renderStudy(); + } + + card.addEventListener("click", function () { + study.flipped = !study.flipped; + renderStudy(); + }); + + prevBtn.addEventListener("click", function () { + go(-1); + }); + nextBtn.addEventListener("click", function () { + go(1); + }); + + document.addEventListener("keydown", function (event) { + if (studyPanel.hidden) return; + var tag = (event.target.tagName || "").toLowerCase(); + if (tag === "input" || tag === "select" || tag === "textarea") return; + if (event.key === "ArrowLeft") { + go(-1); + } else if (event.key === "ArrowRight") { + go(1); + } else if (event.key === " " && event.target !== card) { + event.preventDefault(); + study.flipped = !study.flipped; + renderStudy(); + } + }); + + function buildQuiz() { + var pool = shuffle(TERMS).slice(0, 8); + var items = pool.map(function (term) { + var distractors = shuffle( + TERMS.filter(function (t) { + return t.en !== term.en; + }) + ).slice(0, 3); + var options = shuffle([term].concat(distractors)).map(function (t) { + return t.en; + }); + return { term: term, options: options, picked: null }; + }); + quiz = { items: items, index: 0, right: 0, wrong: [] }; + } + + function renderQuiz() { + quizBody.textContent = ""; + var item = quiz.items[quiz.index]; + var box = el("div", "quiz-card"); + + var meta = el("div", "quiz-meta"); + meta.appendChild(el("span", null, "第 " + (quiz.index + 1) + " / " + quiz.items.length + " 题")); + meta.appendChild(el("span", null, "答对 " + quiz.right)); + box.appendChild(meta); + + var q = el("p", "quiz-q"); + q.appendChild(document.createTextNode("「")); + q.appendChild(el("em", null, item.term.zh)); + q.appendChild(document.createTextNode("」对应的英文术语是?")); + box.appendChild(q); + + var opts = el("div", "quiz-opts"); + var letters = ["A", "B", "C", "D"]; + item.options.forEach(function (option, i) { + var btn = el("button", "opt"); + btn.type = "button"; + btn.appendChild(el("span", "key", letters[i])); + btn.appendChild(el("span", null, option)); + btn.disabled = item.picked !== null; + if (item.picked !== null) { + if (option === item.term.en) btn.classList.add("correct"); + if (option === item.picked && option !== item.term.en) btn.classList.add("wrong"); + } + btn.addEventListener("click", function () { + answer(item, option); + }); + opts.appendChild(btn); + }); + box.appendChild(opts); + + if (item.picked !== null) { + var ok = item.picked === item.term.en; + var fb = el("p", "feedback " + (ok ? "ok" : "bad")); + fb.textContent = ok + ? "答对了。" + item.term.def + : "正确答案是 " + item.term.en + "。" + item.term.def; + box.appendChild(fb); + + var nextBtn2 = el("button", "btn", quiz.index === quiz.items.length - 1 ? "查看结果" : "下一题"); + nextBtn2.type = "button"; + nextBtn2.addEventListener("click", function () { + if (quiz.index === quiz.items.length - 1) { + renderSummary(); + } else { + quiz.index += 1; + renderQuiz(); + } + }); + box.appendChild(nextBtn2); + } + + quizBody.appendChild(box); + } + + function answer(item, option) { + if (item.picked !== null) return; + item.picked = option; + if (option === item.term.en) { + quiz.right += 1; + } else { + quiz.wrong.push(item.term); + } + renderQuiz(); + } + + function renderSummary() { + quizBody.textContent = ""; + quiz.index = quiz.items.length; + var box = el("div", "quiz-card"); + + var score = el("p", "score"); + score.appendChild(document.createTextNode("答对 ")); + score.appendChild(el("strong", null, String(quiz.right))); + score.appendChild(document.createTextNode(" / " + quiz.items.length)); + box.appendChild(score); + + if (quiz.wrong.length === 0) { + box.appendChild(el("p", null, "全部答对。可以切回学习模式,再看看那些常见误区。")); + } else { + box.appendChild(el("p", null, "需要再看一遍的术语:")); + var ul = el("ul", "wrong-list"); + quiz.wrong.forEach(function (term) { + ul.appendChild(el("li", null, term.zh + " — " + term.en)); + }); + box.appendChild(ul); + } + + var again = el("button", "btn", "重新测一次"); + again.type = "button"; + again.addEventListener("click", function () { + buildQuiz(); + renderQuiz(); + }); + box.appendChild(again); + + var back = el("button", "btn ghost", "回到学习模式"); + back.type = "button"; + back.style.marginLeft = "8px"; + back.addEventListener("click", function () { + selectMode("study"); + }); + box.appendChild(back); + + quizBody.appendChild(box); + } + + function selectMode(mode) { + var isStudy = mode === "study"; + tabStudy.setAttribute("aria-selected", String(isStudy)); + tabQuiz.setAttribute("aria-selected", String(!isStudy)); + studyPanel.hidden = !isStudy; + quizPanel.hidden = isStudy; + if (!isStudy) { + if (!quiz || quiz.index >= quiz.items.length) { + buildQuiz(); + } + renderQuiz(); + } + } + + tabStudy.addEventListener("click", function () { + selectMode("study"); + }); + tabQuiz.addEventListener("click", function () { + selectMode("quiz"); + }); + + renderStudy(); +})(); diff --git a/tasks/starters/glossary-cards/data.js b/tasks/starters/glossary-cards/data.js new file mode 100644 index 0000000..2048493 --- /dev/null +++ b/tasks/starters/glossary-cards/data.js @@ -0,0 +1,88 @@ +/* 术语表:解释为课程整理,正式文档以项目原文为准。 + 新增术语时请保持字段完整,自测模式会自动纳入。 */ +window.GLOSSARY = [ + { + zh: "上游", + en: "upstream", + tag: "协作方向", + def: "你所依赖的项目或代码来源那一侧。修复通常要先向上游提交,而不是只改自己的副本。", + pitfall: "不是“上级”。上游指依赖来源,反方向才是下游。", + }, + { + zh: "下游", + en: "downstream", + tag: "协作方向", + def: "使用你的项目、或在你之后继续构建的一方。破坏性改动会直接影响他们。", + pitfall: "常被误写成“下级用户”。下游是依赖关系,不是等级关系。", + }, + { + zh: "贡献者", + en: "contributor", + tag: "角色", + def: "以任何形式为项目做出贡献的人:代码、文档、翻译、设计、评审、答疑、组织活动都算。", + pitfall: "只把提交代码的人算作贡献者,是最常见的窄化。", + }, + { + zh: "维护者", + en: "maintainer", + tag: "角色", + def: "对项目方向、合并决定和版本发布负责的人,通常拥有仓库写权限。", + pitfall: "不要和维护者等同于“全职”或“创始人”。很多维护者是业余时间在做。", + }, + { + zh: "议题", + en: "issue", + tag: "协作流程", + def: "记录缺陷、需求或讨论的公开条目,是异步协作的基本单位。", + pitfall: "译成“问题”会让功能建议看起来像故障,讨论时容易误解语气。", + }, + { + zh: "合并请求", + en: "pull request", + tag: "协作流程", + def: "请求把某个分支的改动合入目标分支,并在此过程中接受评审。", + pitfall: "直译成“拉请求”几乎无法理解;不同平台也叫 merge request。", + }, + { + zh: "派生", + en: "fork", + tag: "协作流程", + def: "把仓库复制到自己的命名空间,可以独立修改,再向上游发起合并请求。", + pitfall: "和 clone 不是一回事:fork 发生在平台上,clone 发生在本地。", + }, + { + zh: "回归", + en: "regression", + tag: "质量", + def: "原本正常的功能在新版本中失效,通常由不相关的改动引入。", + pitfall: "不是“回退”。回退是 revert,回归是功能退化。", + }, + { + zh: "行为准则", + en: "code of conduct", + tag: "社区", + def: "社区对参与行为的共同约定,包含不可接受行为与处理渠道。", + pitfall: "译成“行为代码”会让人以为是程序代码,实际是社区规则。", + }, + { + zh: "本地化", + en: "localization", + tag: "国际化", + def: "针对具体语言和地区做适配:翻译、日期与数字格式、示例、文化语境。", + pitfall: "和国际化不是同义词。国际化是让产品能被适配,本地化是具体适配某种语言。", + }, + { + zh: "路线图", + en: "roadmap", + tag: "治理", + def: "公开的阶段性方向说明,帮助使用者判断是否要跟进。", + pitfall: "不是交付承诺。把路线图当合同,会让维护者不敢公开计划。", + }, + { + zh: "治理", + en: "governance", + tag: "治理", + def: "决策如何产生、角色与权限如何分配、分歧如何解决的一整套安排。", + pitfall: "不等于“管理”。小项目也有治理,只是可能没写下来。", + }, +]; diff --git a/tasks/starters/glossary-cards/index.html b/tasks/starters/glossary-cards/index.html new file mode 100644 index 0000000..7fb6134 --- /dev/null +++ b/tasks/starters/glossary-cards/index.html @@ -0,0 +1,57 @@ + + + + + +术语双语卡 · 入门项目 + + + +
    +

    入门项目 / 03

    +

    术语双语卡

    +

    十二个高频术语,正面看中文,翻过来看英文、释义和常见误译。

    +
    + +
    +
    + + +
    + +
    +
    + +
    +
    + + + +
    +

    键盘:← → 切换,空格翻转。术语解释为课程整理,正式文档以项目原文为准。

    +
    + + +
    + +
    +

    术语表用于统一表达,不替代项目自己的术语约定。发现译法不一致,欢迎提 PR 讨论。

    +
    + + + + + diff --git a/tasks/starters/glossary-cards/styles.css b/tasks/starters/glossary-cards/styles.css new file mode 100644 index 0000000..86af6f5 --- /dev/null +++ b/tasks/starters/glossary-cards/styles.css @@ -0,0 +1,164 @@ +:root { + --bg: #f7f7f5; + --surface: #ffffff; + --text: #1c1c1a; + --muted: #6b6b66; + --line: #e3e3de; + --accent: #6b4a7a; + --accent-soft: #f0eaf3; + --ok: #2f6f4f; + --ok-soft: #e8f1eb; + --bad: #8a3f3f; + --bad-soft: #f6e9e9; + --shadow: 0 1px 2px rgba(28, 28, 26, .05), 0 12px 32px rgba(28, 28, 26, .06); +} +@media (prefers-color-scheme: dark) { + :root { + --bg: #16181a; + --surface: #1e2124; + --text: #e9e9e4; + --muted: #9a9a94; + --line: #2f3336; + --accent: #b79cc6; + --accent-soft: #2a2230; + --ok: #7fbd9a; + --ok-soft: #22302a; + --bad: #d99a9a; + --bad-soft: #322323; + --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 12px 32px rgba(0, 0, 0, .25); + } +} +* { box-sizing: border-box; } +body { + margin: 0; + padding: 40px 20px 64px; + background: var(--bg); + color: var(--text); + font: 16px/1.65 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif; + -webkit-font-smoothing: antialiased; +} +a { color: var(--accent); } +.page-head, main, .page-foot { max-width: 760px; margin: 0 auto; } +.crumb { margin: 0 0 14px; font-size: 13px; color: var(--muted); } +.crumb a { text-decoration: none; } +.crumb a:hover { text-decoration: underline; } +h1 { margin: 0 0 8px; font-size: clamp(26px, 3.6vw, 34px); letter-spacing: -.01em; } +.lede { margin: 0 0 26px; color: var(--muted); } + +.mode { display: inline-flex; padding: 3px; gap: 3px; margin-bottom: 22px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); } +.mode button { + font: inherit; + font-size: 14px; + padding: 6px 18px; + border: 0; + border-radius: 999px; + background: transparent; + color: var(--muted); + cursor: pointer; +} +.mode button[aria-selected="true"] { background: var(--accent-soft); color: var(--accent); } +.mode button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; } + +.stage { perspective: 1400px; margin-bottom: 18px; } +.flashcard { + position: relative; + display: block; + width: 100%; + min-height: 300px; + padding: 0; + border: 0; + background: transparent; + cursor: pointer; + transform-style: preserve-3d; + transition: transform .5s cubic-bezier(.2, .7, .3, 1); +} +.flashcard.flipped { transform: rotateY(180deg); } +.flashcard:focus-visible { outline: 2px solid var(--accent); outline-offset: 6px; border-radius: 14px; } +.face { + position: absolute; + inset: 0; + display: flex; + flex-direction: column; + align-items: center; + justify-content: center; + gap: 12px; + padding: 32px 28px; + border: 1px solid var(--line); + border-radius: 14px; + background: var(--surface); + box-shadow: var(--shadow); + backface-visibility: hidden; + text-align: center; +} +.face.back { + transform: rotateY(180deg); + align-items: flex-start; + text-align: left; + justify-content: center; + gap: 10px; +} +.tag { font-size: 11px; padding: 2px 9px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); } +.term-zh { font-size: clamp(30px, 6vw, 44px); font-weight: 600; letter-spacing: .02em; } +.term-en { font-size: clamp(22px, 4vw, 28px); font-weight: 600; letter-spacing: .01em; } +.hint-line { font-size: 12.5px; color: var(--muted); } +.def { font-size: 15px; } +.pitfall { font-size: 13.5px; color: var(--muted); padding-top: 8px; border-top: 1px dashed var(--line); width: 100%; } + +.controls { display: flex; align-items: center; justify-content: space-between; gap: 10px; } +.btn { + font: inherit; + font-size: 13.5px; + padding: 8px 14px; + border-radius: 8px; + border: 1px solid var(--accent); + background: var(--accent); + color: var(--surface); + cursor: pointer; +} +.btn.ghost { background: transparent; color: var(--accent); } +.btn:disabled { opacity: .4; cursor: default; } +.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; } +.progress { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; } +.tip { margin: 18px 0 0; font-size: 12.5px; color: var(--muted); } + +.quiz-card { padding: 24px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); } +.quiz-meta { display: flex; justify-content: space-between; font-size: 12.5px; color: var(--muted); margin-bottom: 14px; } +.quiz-q { margin: 0 0 18px; font-size: 19px; line-height: 1.5; } +.quiz-q em { font-style: normal; color: var(--accent); font-weight: 600; } +.quiz-opts { display: grid; gap: 8px; margin-bottom: 16px; } +.opt { + display: flex; + align-items: center; + gap: 10px; + width: 100%; + padding: 11px 14px; + font: inherit; + font-size: 14px; + text-align: left; + color: var(--text); + background: transparent; + border: 1px solid var(--line); + border-radius: 9px; + cursor: pointer; +} +.opt:hover:not(:disabled) { border-color: var(--accent); } +.opt:disabled { cursor: default; } +.opt.correct { border-color: var(--ok); background: var(--ok-soft); } +.opt.wrong { border-color: var(--bad); background: var(--bad-soft); } +.opt .key { font-size: 11px; color: var(--muted); font-family: ui-monospace, Menlo, monospace; } +.opt:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; } +.feedback { margin: 0 0 14px; padding: 11px 13px; border-radius: 9px; font-size: 13.5px; background: var(--accent-soft); } +.feedback.ok { background: var(--ok-soft); color: var(--ok); } +.feedback.bad { background: var(--bad-soft); color: var(--bad); } +.score { font-size: 15px; margin: 0 0 6px; } +.score strong { font-size: 26px; color: var(--accent); } +.wrong-list { margin: 0 0 16px; padding-left: 18px; font-size: 13.5px; color: var(--muted); } +.wrong-list li { margin-bottom: 4px; } +.page-foot { margin-top: 32px; font-size: 12.5px; color: var(--muted); } +@media (prefers-reduced-motion: reduce) { + .flashcard { transition: none; } +} +@media (max-width: 480px) { + .flashcard { min-height: 320px; } + .face { padding: 24px 20px; } +} diff --git a/tasks/starters/index.html b/tasks/starters/index.html new file mode 100644 index 0000000..8714108 --- /dev/null +++ b/tasks/starters/index.html @@ -0,0 +1,163 @@ + + + + + +入门项目 · 开源项目国际化运营 + + + + + + diff --git a/tasks/starters/issue-builder/README.md b/tasks/starters/issue-builder/README.md new file mode 100644 index 0000000..3f55f93 --- /dev/null +++ b/tasks/starters/issue-builder/README.md @@ -0,0 +1,77 @@ +# Issue 模板生成器 + +> 把零散描述整理成结构清晰、可复现的 Issue,边填边看 Markdown 预览。 + +## 为什么做这个 + +“有个地方报错了,麻烦看一下”这样的 Issue,维护者需要来回问三四轮才能开始处理。而一个写清背景、步骤、期望与实际的 Issue,往往第一次就能被复现。 + +这个工具不替人思考,只是把结构固定下来,并在提交前提醒几个最容易漏掉的自检项。 + +## 学习目标 + +- 理解一个可复现的 Issue 需要哪些信息,以及每项信息解决谁的什么问题; +- 练习表单校验:必填、长度、条件必填(只有 Bug 才要求复现步骤); +- 练习实时生成文本并与表单双向对应; +- 理解 `navigator.clipboard` 在 `file://` 下会失败,需要降级方案; +- 认识项目模板的差异:同一个仓库和通用模板结构并不相同。 + +## 现在能做什么 + +- 三种类型:Bug 报告、功能建议、文档改进;切换时自动显示/隐藏复现相关字段; +- 两套模板:本仓库简版(起因/重现步骤/报错信息)与通用完整模板; +- 实时预览 Markdown,标题单独预览; +- 提交前自检:是否搜索过重复、是否移除个人信息; +- 校验未通过时禁用复制与下载,并说明还缺什么; +- 复制标题、复制正文、下载 `.md` 三个出口。 + +## 运行 + +双击 `index.html`。不需要安装依赖。 + +```bash +python3 -m http.server 8000 +# 打开 http://localhost:8000/issue-builder/ +``` + +## 验收标准 + +- [ ] 三种类型切换时,复现步骤、期望/实际、运行环境、自检区的显示状态正确; +- [ ] 两套模板生成的 Markdown 结构不同,且都能被平台正常渲染; +- [ ] 标题为空或过短时,复制与下载被禁用,并给出具体原因; +- [ ] 功能建议与文档改进类型不要求复现步骤; +- [ ] 复制在 `file://` 与 `http://` 两种打开方式下都可用; +- [ ] 下载的 `.md` 文件名不为空、不含路径分隔符; +- [ ] 375px 宽度下预览区可滚动,不撑破布局。 + +## 可以认领的改进 + +1. **自定义模板**:允许粘贴一段项目自己的 `ISSUE_TEMPLATE.md`,按其中的 `###` 标题生成对应输入框。 +2. **必填标记联动**:让 `required`、`aria-required` 与视觉标记保持一致,而不是只靠 CSS。 +3. **字数提示**:标题接近上限时提示,而不是到 90 字才截断。 +4. **草稿保存**:用 `localStorage` 保存未提交内容,刷新不丢;同时提供清除按钮。 +5. **多语言**:界面与生成的模板支持中英切换,注意标题长度建议要按语言调整。 +6. **粘贴导入**:把一段随手写的描述粘贴进来,按空行粗分为背景与步骤,再由用户确认。 +7. **校验说明**:每个错误提示直接标在对应字段下方,而不是只在底部汇总。 + +不建议做的事:自动判断“这是不是重复 Issue”。判断重复需要理解语义与上下文,工具给不出可靠结论。 + +## 已知局限 + +- 只覆盖三种常见类型,安全漏洞、性能问题等场景未单独建模; +- 不校验 Markdown 语法,也不检查图片链接是否有效; +- 自检项只是提醒,无法验证用户是否真的搜索过; +- 模板结构写死在 `app.js` 中,改模板需要改代码。 + +## 文件说明 + +| 文件 | 作用 | +| --- | --- | +| `index.html` | 表单字段与预览区结构 | +| `styles.css` | 双栏布局、表单与预览样式 | +| `app.js` | 取值、校验、生成 Markdown、复制与下载 | +| `README.md` | 本文件 | + +## 变更记录 + +- 初版:三种类型、两套模板、实时预览、复制与下载。 diff --git a/tasks/starters/issue-builder/app.js b/tasks/starters/issue-builder/app.js new file mode 100644 index 0000000..6093ad7 --- /dev/null +++ b/tasks/starters/issue-builder/app.js @@ -0,0 +1,193 @@ +(function () { + "use strict"; + + var form = document.getElementById("form"); + var previewEl = document.getElementById("preview"); + var titlePreviewEl = document.getElementById("titlePreview"); + var statusEl = document.getElementById("status"); + var copyTitleBtn = document.getElementById("copyTitle"); + var copyBodyBtn = document.getElementById("copyBody"); + var downloadBtn = document.getElementById("download"); + var bugFields = Array.prototype.slice.call(form.querySelectorAll('[data-for="bug"]')); + + function value(id) { + var el = document.getElementById(id); + return el ? el.value.trim() : ""; + } + + function checked(id) { + var el = document.getElementById(id); + return !!(el && el.checked); + } + + function collect() { + return { + type: value("type") || "bug", + template: value("template") || "course", + title: value("title"), + background: value("background"), + steps: value("steps"), + expected: value("expected"), + actual: value("actual"), + env: value("env"), + extra: value("extra"), + dup: checked("checkDup"), + privacy: checked("checkPrivacy"), + }; + } + + var TYPE_LABEL = { bug: "Bug 报告", feature: "功能建议", docs: "文档改进" }; + + function validate(d) { + var errors = []; + if (d.title.length < 6) errors.push("标题太短,建议写清位置和现象"); + if (d.title.length > 60) errors.push("标题偏长,可以只保留最关键的信息"); + if (d.background.length < 10) errors.push("背景至少写一句:你在做什么、卡在哪"); + if (d.type === "bug" && d.steps.length < 5) errors.push("Bug 需要可复现的步骤"); + if (d.type === "bug" && !d.dup) errors.push("请先搜索是否已有相同 Issue"); + if (d.type === "bug" && !d.privacy) errors.push("请确认已移除个人信息与密钥"); + return errors; + } + + function block(title, content, fallback) { + return "### " + title + "\n\n" + (content || fallback || "(未填写)") + "\n"; + } + + function buildCourse(d) { + var parts = []; + parts.push(block("该问题是怎么引起的?", d.background)); + parts.push(block("重现步骤", d.type === "bug" ? d.steps : "(不适用)")); + var report = d.actual; + if (d.env) report += (report ? "\n\n" : "") + "运行环境:" + d.env; + parts.push(block("报错信息", report, d.type === "bug" ? "(未填写)" : "(不适用)")); + if (d.extra) parts.push(block("补充信息", d.extra)); + return parts.join("\n"); + } + + function buildFull(d) { + var parts = []; + parts.push("## 问题类型\n\n" + TYPE_LABEL[d.type] + "\n"); + parts.push("## 背景\n\n" + (d.background || "(未填写)") + "\n"); + if (d.type === "bug") { + parts.push("## 复现步骤\n\n" + (d.steps || "(未填写)") + "\n"); + parts.push("## 期望结果\n\n" + (d.expected || "(未填写)") + "\n"); + parts.push("## 实际结果\n\n" + (d.actual || "(未填写)") + "\n"); + if (d.env) parts.push("## 运行环境\n\n" + d.env + "\n"); + } else { + parts.push("## 建议做法\n\n" + (d.expected || "(未填写)") + "\n"); + parts.push("## 参考\n\n" + (d.actual || "(未填写)") + "\n"); + } + if (d.extra) parts.push("## 附加信息\n\n" + d.extra + "\n"); + parts.push( + "## 提交前自检\n\n- [" + (d.dup ? "x" : " ") + "] 我搜索过已有 Issue,没有重复\n- [" + + (d.privacy ? "x" : " ") + "] 我移除了账号、密钥和个人信息\n" + ); + return parts.join("\n"); + } + + function body(d) { + return d.template === "course" ? buildCourse(d) : buildFull(d); + } + + function syncBugFields(d) { + bugFields.forEach(function (field) { + field.hidden = d.type !== "bug"; + }); + } + + function update() { + var d = collect(); + syncBugFields(d); + + var errors = validate(d); + var text = body(d); + + previewEl.textContent = text; + titlePreviewEl.textContent = d.title || "(尚未填写)"; + + var blocked = errors.length > 0 || !d.title; + copyTitleBtn.disabled = !d.title; + copyBodyBtn.disabled = blocked; + downloadBtn.disabled = blocked; + + if (errors.length) { + statusEl.className = "status error"; + statusEl.textContent = "还需要补充:" + errors.join(";") + "。"; + } else { + statusEl.className = "status"; + statusEl.textContent = "结构已完整。粘贴前再读一遍,确认没有夸大和无关内容。"; + } + } + + function copy(text, btn, doneText) { + var original = btn.textContent; + function done() { + btn.textContent = doneText || "已复制"; + window.setTimeout(function () { + btn.textContent = original; + }, 1500); + } + function fallback() { + var box = document.createElement("textarea"); + box.value = text; + box.setAttribute("readonly", ""); + box.style.position = "fixed"; + box.style.opacity = "0"; + document.body.appendChild(box); + box.select(); + try { + document.execCommand("copy"); + done(); + } catch (error) { + window.prompt("请手动复制:", text); + } + document.body.removeChild(box); + } + if (navigator.clipboard && navigator.clipboard.writeText) { + navigator.clipboard.writeText(text).then(done, fallback); + } else { + fallback(); + } + } + + function slug(text) { + return ( + text + .toLowerCase() + .replace(/[^\w\u4e00-\u9fa5]+/g, "-") + .replace(/^-+|-+$/g, "") + .slice(0, 40) || "issue" + ); + } + + form.addEventListener("input", update); + form.addEventListener("change", update); + form.addEventListener("submit", function (event) { + event.preventDefault(); + }); + + copyTitleBtn.addEventListener("click", function () { + copy(collect().title, copyTitleBtn, "标题已复制"); + }); + copyBodyBtn.addEventListener("click", function () { + copy(body(collect()), copyBodyBtn, "正文已复制"); + }); + + downloadBtn.addEventListener("click", function () { + var d = collect(); + var content = "# " + d.title + "\n\n" + body(d) + "\n"; + var blob = new Blob([content], { type: "text/markdown;charset=utf-8" }); + var url = URL.createObjectURL(blob); + var a = document.createElement("a"); + a.href = url; + a.download = "issue-" + slug(d.title) + ".md"; + document.body.appendChild(a); + a.click(); + document.body.removeChild(a); + window.setTimeout(function () { + URL.revokeObjectURL(url); + }, 1000); + }); + + update(); +})(); diff --git a/tasks/starters/issue-builder/index.html b/tasks/starters/issue-builder/index.html new file mode 100644 index 0000000..81b79af --- /dev/null +++ b/tasks/starters/issue-builder/index.html @@ -0,0 +1,106 @@ + + + + + +Issue 模板生成器 · 入门项目 + + + +
    +

    入门项目 / 04

    +

    Issue 模板生成器

    +

    把零散描述整理成结构清晰、可复现的 Issue,边填边看 Markdown 预览。

    +
    + +
    +
    +
    +
    + + +
    +
    + + +
    +
    + +
    + + +

    建议 8—60 字,包含位置和现象,不要只写“有个问题”。

    +
    + +
    + + +
    + +
    + + +
    + +
    +
    + + +
    +
    + + +
    +
    + +
    + + +
    + +
    + + +
    + +
    + 提交前自检 + + +
    + +

    +
    + +
    +
    +

    预览

    +
    + + + +
    +
    +
    
    +    
    + 标题 + (尚未填写) +
    +

    提交到平台时,标题填进标题框,正文粘贴到描述框。不要把自己的私聊记录或密钥贴进来。

    +
    +
    + +
    +

    模板参考仓库中的 .gitee/ISSUE_TEMPLATE.zh-CN.md。不同项目有自己的模板,提交前请先看对方的贡献指南。

    +
    + + + + diff --git a/tasks/starters/issue-builder/styles.css b/tasks/starters/issue-builder/styles.css new file mode 100644 index 0000000..6ba6d0a --- /dev/null +++ b/tasks/starters/issue-builder/styles.css @@ -0,0 +1,120 @@ +:root { + --bg: #f7f7f5; + --surface: #ffffff; + --text: #1c1c1a; + --muted: #6b6b66; + --line: #e3e3de; + --accent: #8a5a1f; + --accent-soft: #f6efe3; + --bad: #8a3f3f; + --shadow: 0 1px 2px rgba(28, 28, 26, .05), 0 10px 30px rgba(28, 28, 26, .05); +} +@media (prefers-color-scheme: dark) { + :root { + --bg: #16181a; + --surface: #1e2124; + --text: #e9e9e4; + --muted: #9a9a94; + --line: #2f3336; + --accent: #d9b27c; + --accent-soft: #322a1f; + --bad: #d99a9a; + --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 10px 30px rgba(0, 0, 0, .25); + } +} +* { box-sizing: border-box; } +body { + margin: 0; + padding: 40px 20px 64px; + background: var(--bg); + color: var(--text); + font: 16px/1.65 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif; + -webkit-font-smoothing: antialiased; +} +a { color: var(--accent); } +.page-head, .layout, .page-foot { max-width: 1120px; margin: 0 auto; } +.crumb { margin: 0 0 14px; font-size: 13px; color: var(--muted); } +.crumb a { text-decoration: none; } +.crumb a:hover { text-decoration: underline; } +h1 { margin: 0 0 8px; font-size: clamp(26px, 3.6vw, 34px); letter-spacing: -.01em; } +.lede { margin: 0 0 28px; max-width: 58ch; color: var(--muted); } + +.layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.05fr); gap: 20px; align-items: start; } +@media (max-width: 900px) { .layout { grid-template-columns: 1fr; } } + +.panel { + background: var(--surface); + border: 1px solid var(--line); + border-radius: 12px; + padding: 22px; + box-shadow: var(--shadow); +} +.row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; } +.row[hidden] { display: none; } +@media (max-width: 560px) { .row { grid-template-columns: 1fr; } } +.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 16px; } +.field[hidden], fieldset[hidden] { display: none; } +.field label { font-size: 13px; font-weight: 600; } +.req { font-weight: 400; font-size: 11px; color: var(--accent); background: var(--accent-soft); padding: 1px 6px; border-radius: 4px; margin-left: 4px; } +input, select, textarea { + font: inherit; + font-size: 14px; + padding: 9px 11px; + color: var(--text); + background: var(--surface); + border: 1px solid var(--line); + border-radius: 8px; + width: 100%; +} +textarea { resize: vertical; line-height: 1.6; } +input:focus-visible, select:focus-visible, textarea:focus-visible, pre:focus-visible { + outline: 2px solid var(--accent); + outline-offset: 1px; +} +.help { margin: 0; font-size: 12px; color: var(--muted); } +.checks { border: 1px solid var(--line); border-radius: 9px; padding: 12px 14px; margin: 0 0 16px; } +.checks legend { padding: 0 4px; font-size: 12.5px; color: var(--muted); } +.check { display: flex; gap: 8px; align-items: flex-start; font-size: 13px; margin-bottom: 6px; cursor: pointer; } +.check:last-child { margin-bottom: 0; } +.check input { width: auto; margin-top: 4px; accent-color: var(--accent); flex: none; } +.status { margin: 0; font-size: 13px; color: var(--muted); } +.status.error { color: var(--bad); } + +.preview-wrap { position: sticky; top: 24px; } +@media (max-width: 900px) { .preview-wrap { position: static; } } +.preview-head { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between; margin-bottom: 12px; } +.preview-head h2 { margin: 0; font-size: 15px; } +.preview-actions { display: flex; flex-wrap: wrap; gap: 6px; } +.btn { + font: inherit; + font-size: 13px; + padding: 7px 12px; + border-radius: 7px; + border: 1px solid var(--accent); + background: var(--accent); + color: var(--surface); + cursor: pointer; +} +.btn.ghost { background: transparent; color: var(--accent); } +.btn:disabled { opacity: .45; cursor: default; } +.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; } +.preview { + margin: 0 0 14px; + padding: 16px; + min-height: 280px; + max-height: 440px; + overflow: auto; + font: 12.5px/1.75 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; + white-space: pre-wrap; + word-break: break-word; + background: var(--bg); + border: 1px solid var(--line); + border-radius: 9px; + color: var(--text); +} +.preview-title { display: flex; gap: 10px; align-items: baseline; padding: 10px 0 0; border-top: 1px solid var(--line); margin-bottom: 10px; font-size: 13px; } +.preview-title-label { flex: none; font-size: 11px; color: var(--accent); background: var(--accent-soft); padding: 2px 8px; border-radius: 4px; } +.preview-title-text { color: var(--muted); word-break: break-word; } +.page-foot { margin-top: 30px; font-size: 12.5px; color: var(--muted); } +.page-foot code { font-size: 11.5px; background: var(--accent-soft); color: var(--accent); padding: 1px 5px; border-radius: 4px; } +@media (prefers-reduced-motion: reduce) { * { transition: none !important; } } diff --git a/tasks/starters/license-picker/README.md b/tasks/starters/license-picker/README.md new file mode 100644 index 0000000..064fbd0 --- /dev/null +++ b/tasks/starters/license-picker/README.md @@ -0,0 +1,78 @@ +# 许可证选择器 + +> 一个不联网的小工具:回答六个问题,给出一个有理由的许可证建议。 + +## 为什么做这个 + +新手最常见的两个做法是:随手复制一个 MIT,或者直接不写许可证。前者可能和项目目标冲突(比如希望衍生作品也开源),后者会让别人不敢用。 + +这个工具把“选许可证”拆成几个能回答的问题,并把结论拆成**允许、要求、限制**三栏,让选择过程可以被讨论、被质疑。 + +## 学习目标 + +- 理解宽松许可证与互惠(copyleft)许可证的差别; +- 知道专利条款、网络服务、库链接分别会改变什么; +- 练习把一段判断逻辑写成可读的 JavaScript; +- 练习表单的可访问性:`fieldset`、`legend`、键盘操作、焦点可见。 + +## 现在能做什么 + +- 六道单选题,覆盖对象类型、闭源衍生、网络服务、专利、库引用、中文文本; +- 选择“文档/内容”或“硬件”时,只保留相关的问题,其余自动隐藏; +- 结果区实时更新,给出许可证名称、SPDX 标识、推荐理由、允许/要求/限制三栏和备选方案; +- 可一键复制 SPDX 标识,不支持剪贴板 API 时自动降级。 + +## 运行 + +双击 `index.html` 即可,不需要服务器。也可以从上级目录启动本地服务: + +```bash +python3 -m http.server 8000 +# 打开 http://localhost:8000/license-picker/ +``` + +## 验收标准 + +- [ ] 六道题的任意组合都能得到结果,且不会出现空白面板; +- [ ] 内容、硬件两类选择下,隐藏的问题不会影响结果; +- [ ] 结果区的三栏信息与实际许可证一致,没有编造条款; +- [ ] 全程可用键盘完成,焦点位置清晰可见; +- [ ] 375px 宽度下无横向滚动,结果区不遮挡内容; +- [ ] 复制按钮在 `file://` 下也能工作; +- [ ] 页面上保留了“不构成法律意见”的提示。 + +## 可以认领的改进 + +按难度从低到高: + +1. **补许可证**:加入 MPL-2.0、BSL-1.0 或某种你熟悉的许可证,同时补上它和现有选项的差异说明。 +2. **补问题**:例如“是否要求衍生作品使用不同名称”,用于区分商标条款;注意不要让问题数量失控。 +3. **加对比模式**:勾选两到三个许可证,并排显示三栏差异。 +4. **加链接**:每个许可证给出官方原文链接,并在新标签页打开(记得加 `rel="noopener"`)。 +5. **加重置**:一键回到初始状态,便于课堂上多人轮流试用。 +6. **加导出**:把当前结论导出为一段 Markdown,方便直接贴进项目 README。 + +不建议做的事:把结论写成“最佳许可证”,或者用打分的方式暗示某个许可证更高级。许可证只有适配与否。 + +## 已知局限 + +- 只覆盖常见许可证,GPL-2.0、EPL、Unlicense 等尚未纳入; +- 不能判断许可证之间的兼容性,例如把 Apache-2.0 代码并入 GPL-2.0 项目的问题; +- 不处理双许可证、商业许可并存的场景; +- 结论基于常识性归纳,不是法律意见。 + +## 文件说明 + +| 文件 | 作用 | +| --- | --- | +| `index.html` | 页面结构:六道问题 + 结果区 | +| `styles.css` | 配色与布局,跟随系统深浅色 | +| `data.js` | 许可证资料,改这里就能增加选项 | +| `app.js` | 读取答案、决策、渲染结果 | +| `README.md` | 本文件 | + +`data.js` 里的资料是人工整理的结构化数据,字段含义:`permissions` 允许做的事、`conditions` 必须履行的义务、`limitations` 明确排除的事项、`alternatives` 备选许可证 id。 + +## 变更记录 + +- 初版:六问决策、三类对象、三栏结果、SPDX 复制。 diff --git a/tasks/starters/license-picker/app.js b/tasks/starters/license-picker/app.js new file mode 100644 index 0000000..4479a62 --- /dev/null +++ b/tasks/starters/license-picker/app.js @@ -0,0 +1,198 @@ +(function () { + "use strict"; + + var form = document.getElementById("quiz"); + var resultEl = document.getElementById("result"); + var progressEl = document.getElementById("progress"); + var softwareFields = Array.prototype.slice.call( + form.querySelectorAll('[data-only="software"]') + ); + + function readAnswers() { + var data = new FormData(form); + return { + target: data.get("target") || "software", + closed: data.get("closed") || "yes", + network: data.get("network") || "no", + patent: data.get("patent") || "no", + library: data.get("library") || "no", + china: data.get("china") || "no", + }; + } + + /* 决策顺序:先看对象类型,再看是否允许闭源衍生, + 然后用网络服务、库、专利、中文文本四个条件细分。 */ + function decide(a) { + if (a.target === "content") return { id: "ccby4", why: ["内容类成果更适合内容许可证,软件许可证不覆盖改编与署名规则。"] }; + if (a.target === "hardware") { + return { + id: "cernohls", + why: ["硬件设计需要覆盖制造与分发的许可证,软件许可证无法约束实体复制。"], + }; + } + + if (a.closed === "yes") { + if (a.patent === "yes") { + return { + id: "apache2", + why: ["允许闭源衍生,所以选择宽松许可证。", "需要明确专利授权,Apache-2.0 有专门条款。"], + }; + } + if (a.china === "yes") { + return { + id: "mulanpsl2", + why: ["允许闭源衍生,宽松许可证即可。", "希望使用中文正式文本,木兰宽松许可证第 2 版是常见选择。"], + }; + } + return { + id: "mit", + why: ["允许闭源衍生,宽松许可证即可。", "没有专利或中文文本的特殊要求,MIT 最短、最易被理解。"], + }; + } + + if (a.network === "yes") { + return { + id: "agpl3", + why: ["要求衍生作品必须开源。", "以网络服务形式提供,GPL 无法覆盖这一场景,需要 AGPL。"], + }; + } + if (a.library === "yes") { + return { + id: "lgpl3", + why: ["要求衍生作品开源。", "希望被闭源程序链接使用,LGPL 只要求库本身的修改开源。"], + }; + } + return { + id: "gpl3", + why: ["要求衍生作品必须开源。", "不涉及网络服务与库的特殊场景,GPL-3.0 覆盖最直接。"], + }; + } + + function el(tag, className, text) { + var node = document.createElement(tag); + if (className) node.className = className; + if (text != null) node.textContent = text; + return node; + } + + function listBlock(title, items) { + var wrap = el("div", "col"); + wrap.appendChild(el("h3", null, title)); + var ul = el("ul"); + items.forEach(function (item) { + ul.appendChild(el("li", null, item)); + }); + wrap.appendChild(ul); + return wrap; + } + + function render(a) { + var picked = decide(a); + var lic = window.LICENSES[picked.id]; + resultEl.textContent = ""; + + resultEl.appendChild(el("h2", "res-name", lic.name)); + resultEl.appendChild(el("p", "res-spdx", lic.spdx)); + resultEl.appendChild(el("p", "res-summary", lic.summary)); + + var why = el("ul", "why"); + picked.why.forEach(function (reason) { + why.appendChild(el("li", null, reason)); + }); + resultEl.appendChild(why); + + var cols = el("div", "cols"); + cols.appendChild(listBlock("允许", lic.permissions)); + cols.appendChild(listBlock("要求", lic.conditions)); + cols.appendChild(listBlock("限制", lic.limitations)); + resultEl.appendChild(cols); + + var row = el("div", "copy-row"); + var copyBtn = el("button", null, "复制 SPDX 标识"); + copyBtn.type = "button"; + copyBtn.addEventListener("click", function () { + copyText(lic.spdx, copyBtn); + }); + row.appendChild(copyBtn); + resultEl.appendChild(row); + + if (lic.alternatives && lic.alternatives.length) { + var alt = el("div", "alt"); + alt.appendChild(el("strong", null, "也可以考虑:")); + var names = lic.alternatives + .map(function (id) { + return window.LICENSES[id] ? window.LICENSES[id].name : id; + }) + .join("、"); + alt.appendChild(document.createTextNode(names + "。差别主要在专利条款、文本语言和兼容性上。")); + resultEl.appendChild(alt); + } + + resultEl.appendChild( + el( + "p", + "note", + "这不是法律意见。若项目涉及专利、商业授权或多方合并,请让法务或社区维护者复核后再定。" + ) + ); + } + + function copyText(text, btn) { + function done() { + var original = btn.textContent; + btn.textContent = "已复制"; + window.setTimeout(function () { + btn.textContent = original; + }, 1500); + } + if (navigator.clipboard && navigator.clipboard.writeText) { + navigator.clipboard.writeText(text).then(done, fallback); + } else { + fallback(); + } + function fallback() { + var box = document.createElement("textarea"); + box.value = text; + box.setAttribute("readonly", ""); + box.style.position = "fixed"; + box.style.opacity = "0"; + document.body.appendChild(box); + box.select(); + try { + document.execCommand("copy"); + done(); + } catch (error) { + window.prompt("请手动复制:", text); + } + document.body.removeChild(box); + } + } + + function syncVisibility(a) { + var isSoftware = a.target === "software"; + softwareFields.forEach(function (field) { + field.hidden = !isSoftware; + }); + } + + function update() { + var answers = readAnswers(); + syncVisibility(answers); + + var total = answers.target === "software" ? 6 : 1; + progressEl.textContent = + answers.target === "software" + ? "已根据当前选择生成建议,修改任一选项会立即更新。" + : "内容与硬件只需要回答第一题,其余问题已隐藏。"; + + render(answers); + progressEl.setAttribute("data-total", String(total)); + } + + form.addEventListener("change", update); + form.addEventListener("submit", function (event) { + event.preventDefault(); + }); + + update(); +})(); diff --git a/tasks/starters/license-picker/data.js b/tasks/starters/license-picker/data.js new file mode 100644 index 0000000..787d0d9 --- /dev/null +++ b/tasks/starters/license-picker/data.js @@ -0,0 +1,85 @@ +/* 许可证资料:字段含义见 README。 + 文字为通俗归纳,正式采用前请阅读许可证原文。 */ +window.LICENSES = { + mit: { + name: "MIT 许可证", + spdx: "MIT", + summary: "最短、最常见的宽松许可证。任何人都可以用、改、卖,只要保留版权声明。", + permissions: ["商业使用", "修改", "分发", "私人使用"], + conditions: ["保留版权与许可声明"], + limitations: ["不提供担保", "作者不承担赔偿责任", "不得用作者名义背书"], + alternatives: ["apache2", "mulanpsl2"], + }, + apache2: { + name: "Apache 许可证 2.0", + spdx: "Apache-2.0", + summary: "宽松许可证,额外写明专利授权与商标边界,适合有企业参与的项目。", + permissions: ["商业使用", "修改", "分发", "专利使用"], + conditions: ["保留版权与许可声明", "标注修改过的文件", "保留 NOTICE 文件", "附许可证副本"], + limitations: ["不授予商标权", "不提供担保", "作者不承担赔偿责任"], + alternatives: ["mit", "mulanpsl2"], + }, + mulanpsl2: { + name: "木兰宽松许可证 第 2 版", + spdx: "MulanPSL-2.0", + summary: "中文正式文本的宽松许可证,含专利许可条款,国内项目采用时沟通成本较低。", + permissions: ["商业使用", "修改", "分发", "专利使用"], + conditions: ["保留版权与许可声明", "标注修改内容", "附许可证文本"], + limitations: ["不提供担保", "作者不承担赔偿责任", "不得暗示背书"], + alternatives: ["apache2", "mit"], + }, + gpl3: { + name: "GNU 通用公共许可证 第 3 版", + spdx: "GPL-3.0-only", + summary: "强互惠许可证。衍生作品分发时必须同样开源,适合希望成果持续回流的项目。", + permissions: ["商业使用", "修改", "分发", "专利使用"], + conditions: ["衍生作品采用同一许可证", "提供完整对应源码", "保留声明与许可文本", "不得追加额外限制"], + limitations: ["不提供担保", "不得附加限制条款", "与部分许可证不兼容"], + alternatives: ["agpl3", "lgpl3"], + }, + lgpl3: { + name: "GNU 宽通用公共许可证 第 3 版", + spdx: "LGPL-3.0-only", + summary: "面向库的弱互惠许可证。修改库本身要开源,但链接它的程序可以闭源。", + permissions: ["商业使用", "修改", "分发", "闭源程序链接使用"], + conditions: ["修改库本身须以 LGPL 开源", "提供对应源码", "保留重新链接的能力"], + limitations: ["不提供担保", "不得限制接收者行使权利"], + alternatives: ["gpl3", "apache2"], + }, + agpl3: { + name: "GNU Affero 通用公共许可证 第 3 版", + spdx: "AGPL-3.0-only", + summary: "在 GPL 基础上补上网络服务场景:用户通过网络使用,也应能拿到源码。", + permissions: ["商业使用", "修改", "分发", "专利使用"], + conditions: ["衍生作品采用同一许可证", "网络服务须提供源码", "保留声明与许可文本"], + limitations: ["不提供担保", "商业采用门槛较高", "与部分许可证不兼容"], + alternatives: ["gpl3"], + }, + ccby4: { + name: "知识共享 署名 4.0", + spdx: "CC-BY-4.0", + summary: "面向文档、教材、图片和数据的内容许可证。允许商用与改编,但必须署名。", + permissions: ["复制", "改编", "商业使用", "再分发"], + conditions: ["署名原作者", "注明是否修改", "保留许可证链接"], + limitations: ["不授予专利与商标许可", "不得追加法律或技术限制", "不提供担保"], + alternatives: [], + }, + cernohls: { + name: "CERN 开放硬件许可证 强互惠版", + spdx: "CERN-OHL-S-2.0", + summary: "面向硬件设计的互惠许可证。分发修改后的设计,须以同一许可证开放。", + permissions: ["制造", "修改", "分发", "商业使用"], + conditions: ["衍生设计采用同一许可证", "提供设计文档与来源", "保留声明"], + limitations: ["不提供担保", "不授予商标权"], + alternatives: ["cernohlw"], + }, + cernohlw: { + name: "CERN 开放硬件许可证 弱互惠版", + spdx: "CERN-OHL-W-2.0", + summary: "硬件弱互惠许可证,允许把开放设计与自有设计组合,改动部分仍需开放。", + permissions: ["制造", "修改", "分发", "商业使用"], + conditions: ["修改部分须开放", "保留声明与来源"], + limitations: ["不提供担保", "不授予商标权"], + alternatives: ["cernohls"], + }, +}; diff --git a/tasks/starters/license-picker/index.html b/tasks/starters/license-picker/index.html new file mode 100644 index 0000000..cfe43f0 --- /dev/null +++ b/tasks/starters/license-picker/index.html @@ -0,0 +1,70 @@ + + + + + +许可证选择器 · 入门项目 + + + +
    +

    入门项目 / 01

    +

    许可证选择器

    +

    回答六个问题,得到一个能说清理由的许可证建议。结果只是起点,正式采用前请阅读许可证原文。

    +
    + +
    +
    +
    + 01你要开放的是什么? + + + +
    + +
    + 02允许别人修改后闭源分发吗? + + +
    + +
    + 03会以网络服务的形式提供给用户吗? + + +
    + +
    + 04是否包含专利,需要明确的专利授权? + + +
    + +
    + 05是否希望被闭源项目当作库引用? + + +
    + +
    + 06是否希望使用中文正式文本、面向国内社区发布? + + +
    + +

    +
    + +
    +

    选择左侧选项后,这里会给出建议。

    +
    +
    + +
    +

    本工具只做常识性梳理,不构成法律意见。许可证条款以官方英文或中文原文为准。

    +
    + + + + + diff --git a/tasks/starters/license-picker/styles.css b/tasks/starters/license-picker/styles.css new file mode 100644 index 0000000..517fd1f --- /dev/null +++ b/tasks/starters/license-picker/styles.css @@ -0,0 +1,110 @@ +:root { + --bg: #f7f7f5; + --surface: #ffffff; + --text: #1c1c1a; + --muted: #6b6b66; + --line: #e3e3de; + --accent: #2f6f4f; + --accent-soft: #e8f1eb; + --warn: #8a5a1f; + --warn-soft: #f6efe3; + --shadow: 0 1px 2px rgba(28, 28, 26, .05), 0 10px 30px rgba(28, 28, 26, .05); +} +@media (prefers-color-scheme: dark) { + :root { + --bg: #16181a; + --surface: #1e2124; + --text: #e9e9e4; + --muted: #9a9a94; + --line: #2f3336; + --accent: #7fbd9a; + --accent-soft: #23302a; + --warn: #d9b27c; + --warn-soft: #322a1f; + --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 10px 30px rgba(0, 0, 0, .25); + } +} +* { box-sizing: border-box; } +body { + margin: 0; + padding: 40px 20px 64px; + background: var(--bg); + color: var(--text); + font: 16px/1.65 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif; + -webkit-font-smoothing: antialiased; +} +a { color: var(--accent); } +.page-head, .layout, .page-foot { max-width: 1040px; margin: 0 auto; } +.crumb { margin: 0 0 14px; font-size: 13px; color: var(--muted); } +.crumb a { text-decoration: none; } +.crumb a:hover { text-decoration: underline; } +h1 { margin: 0 0 8px; font-size: clamp(26px, 3.6vw, 34px); letter-spacing: -.01em; } +.lede { margin: 0 0 32px; max-width: 58ch; color: var(--muted); } + +.layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 20px; align-items: start; } +@media (max-width: 860px) { .layout { grid-template-columns: 1fr; } } + +.panel { + background: var(--surface); + border: 1px solid var(--line); + border-radius: 12px; + padding: 22px; + box-shadow: var(--shadow); +} +.q { border: 0; margin: 0 0 20px; padding: 0; } +.q:last-of-type { margin-bottom: 8px; } +.q legend { padding: 0; margin-bottom: 10px; font-weight: 600; font-size: 15px; } +.q-no { color: var(--accent); font-size: 12px; letter-spacing: .1em; margin-right: 8px; font-weight: 500; } +.opt { + display: flex; + gap: 10px; + align-items: flex-start; + padding: 10px 12px; + margin-bottom: 8px; + border: 1px solid var(--line); + border-radius: 8px; + cursor: pointer; + font-size: 14px; + color: var(--muted); + transition: border-color .15s ease, background .15s ease; +} +.opt:hover { border-color: var(--accent); } +.opt input { margin: 3px 0 0; accent-color: var(--accent); flex: none; } +.opt:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); color: var(--text); } +.opt:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; } +.q[hidden] { display: none; } +.progress { margin: 4px 0 0; font-size: 13px; color: var(--muted); } + +.result { position: sticky; top: 24px; } +@media (max-width: 860px) { .result { position: static; } } +.placeholder { margin: 0; color: var(--muted); font-size: 14px; } +.res-name { margin: 0 0 2px; font-size: 24px; letter-spacing: -.01em; } +.res-spdx { margin: 0 0 14px; font-size: 13px; color: var(--muted); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; } +.res-summary { margin: 0 0 18px; font-size: 14px; } +.why { margin: 0 0 20px; padding: 0 0 0 3px; list-style: none; } +.why li { position: relative; padding-left: 16px; margin-bottom: 6px; font-size: 13px; color: var(--muted); } +.why li::before { content: ""; position: absolute; left: 0; top: .62em; width: 5px; height: 5px; border-radius: 50%; background: var(--accent); } +.cols { display: grid; gap: 10px; grid-template-columns: repeat(3, minmax(0, 1fr)); margin-bottom: 18px; } +@media (max-width: 520px) { .cols { grid-template-columns: 1fr; } } +.col { padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; } +.col h3 { margin: 0 0 6px; font-size: 12px; letter-spacing: .06em; color: var(--muted); font-weight: 600; } +.col ul { margin: 0; padding-left: 16px; font-size: 13px; } +.col li { margin-bottom: 3px; } +.copy-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; } +button { + font: inherit; + font-size: 14px; + padding: 8px 14px; + border-radius: 8px; + border: 1px solid var(--accent); + background: var(--accent); + color: var(--surface); + cursor: pointer; +} +button.ghost { background: transparent; color: var(--accent); } +button:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; } +.note { margin: 16px 0 0; padding: 10px 12px; border-radius: 8px; background: var(--warn-soft); color: var(--warn); font-size: 12.5px; } +.alt { margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--line); font-size: 13px; color: var(--muted); } +.alt strong { color: var(--text); font-weight: 600; } +.page-foot { margin-top: 32px; font-size: 12.5px; color: var(--muted); } +@media (prefers-reduced-motion: reduce) { * { transition: none !important; } } -- Gitee