diff --git a/.github/ISSUE_TEMPLATE/artwork.yml b/.github/ISSUE_TEMPLATE/artwork.yml new file mode 100644 index 0000000..8958328 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/artwork.yml @@ -0,0 +1,50 @@ +name: "上传绘画作品" +description: "手机选择照片,填写作品信息。仅 hulingjun 提交的作品会发布到画展。" +title: "[画作] " +body: + - type: markdown + attributes: + value: | + ## 留下这一幅画 + 一幅作品新建一条记录。提交后通常几分钟内自动发布到 https://hulingjun.github.io/art/ 。 + + **图片一上传到 GitHub 就可能被公开访问,包括原始照片。** 请先裁掉姓名、学校、住址等信息,并在手机分享照片时移除位置。画展中的处理版会去掉照片元数据,但不会删除 GitHub 的原始附件。 + - type: input + id: artwork-title + attributes: + label: 作品名称 + placeholder: 例如:彩色的夏天 + validations: + required: true + - type: input + id: artwork-date + attributes: + label: 创作日期 + description: "格式 YYYY-MM-DD。不记得具体日期可以留空,不会以上传日期代替。" + placeholder: "2026-09-05" + - type: textarea + id: artwork-photo + attributes: + label: 作品图片 + description: "点输入框下方的附件按钮,选择手机相册中的一张照片。支持 JPG、PNG、WebP、GIF,最大 10 MB。HEIC 请先转成 JPG;GIF 只展示首帧。不要删除上传后自动出现的图片链接。" + placeholder: 在这里添加一张画作照片 + validations: + required: true + - type: textarea + id: artwork-story + attributes: + label: 作品故事 + description: 可选,记录她画这幅画时说的话,最多 1200 字。请勿填写私人信息。 + placeholder: 她说…… + - type: checkboxes + id: public-consent + attributes: + label: 公开确认 + options: + - label: 我确认只上传可公开展示的画作,不含孩子的姓名、学校、住址等隐私。 + required: true + - type: markdown + attributes: + value: | + 提交后请保持记录为 Open(打开)。编辑上面的信息会更新画展;Close issue(关闭记录)会下架,Reopen(重新打开)会恢复。 + 下架不会自动删除 GitHub 的原始附件。发布结果见本记录下的自动回复。 diff --git a/.github/ISSUE_TEMPLATE/growth.yml b/.github/ISSUE_TEMPLATE/growth.yml new file mode 100644 index 0000000..faaaa95 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/growth.yml @@ -0,0 +1,47 @@ +name: "写一条成长记录" +description: "记录自己的思考,或女儿的一次新发现。" +title: "[成长] " +body: + - type: dropdown + id: scope + attributes: + label: 记录归属 + options: + - 我的成长 + - 女儿的成长 + validations: + required: true + - type: input + id: heading + attributes: + label: 记录标题 + placeholder: 今天,理解了一件小事 + validations: + required: true + - type: input + id: date + attributes: + label: 记录日期 + placeholder: "2026-09-05" + description: "填写 YYYY-MM-DD,例如 2026-09-05。" + validations: + required: true + - type: textarea + id: content + attributes: + label: 记录正文 + description: 写下这次经历、发现或思考。支持换行,以纯文字展示,最多 10000 字。 + validations: + required: true + - type: checkboxes + id: consent + attributes: + label: 公开确认 + options: + - label: 我确认这份记录可以在公开网站和 GitHub 仓库中展示。 + required: true + - type: markdown + attributes: + value: | + 仅 hulingjun 的记录会进入网站。不要填写孩子的姓名、学校、位置或其他隐私。 + 编辑本记录会更新网站,关闭记录会从网站下架。GitHub 历史仍保留。 diff --git a/.github/ISSUE_TEMPLATE/knowledge.yml b/.github/ISSUE_TEMPLATE/knowledge.yml new file mode 100644 index 0000000..44f45ab --- /dev/null +++ b/.github/ISSUE_TEMPLATE/knowledge.yml @@ -0,0 +1,25 @@ +name: "保存知识空间" +description: "把编辑器复制的知识数据保存到 GitHub,自动进入成长档案。" +title: "[知识] " +body: + - type: markdown + attributes: + value: | + 请使用 hulingjun 登录。从知识空间点击“保存到 GitHub”,复制完整数据后粘贴到下方。 + 同一个空间的新提交会成为最新版本;旧版本留在 GitHub 历史中。只提交准备公开的内容。 + 如需私密知识存储,不要在这里提交:当前仓库与网站均为公开。 + - type: textarea + id: knowledge-data + attributes: + label: 知识数据 + description: 粘贴从编辑器复制的完整 JSON。请勿修改 spaceId。 + render: json + validations: + required: true + - type: checkboxes + id: consent + attributes: + label: 公开确认 + options: + - label: 我确认这份记录可以在公开网站和 GitHub 仓库中展示。 + required: true diff --git a/.github/workflows/archive-check.yml b/.github/workflows/archive-check.yml new file mode 100644 index 0000000..a276e8a --- /dev/null +++ b/.github/workflows/archive-check.yml @@ -0,0 +1,42 @@ +name: Validate growth archive +on: + pull_request: + branches: [main] + push: + branches: [agent/github-art-gallery] +permissions: + contents: read +jobs: + validate: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + persist-credentials: false + - uses: actions/setup-node@v4 + with: + node-version: 22 + - run: npm install + - name: Install isolated image processing tools + run: npm install --prefix "$RUNNER_TEMP/gallery-tools" --no-package-lock --no-save sharp@0.35.4 + - name: Validate records, permissions and image processing + run: node --test scripts/archive.test.mjs + env: + GALLERY_TOOLS_DIR: ${{ runner.temp }}/gallery-tools + - name: Build empty archive fixture + run: | + node scripts/build-gallery.mjs + node scripts/sync-records.mjs + npm run build + env: + GALLERY_TOOLS_DIR: ${{ runner.temp }}/gallery-tools + GALLERY_FIXTURE: scripts/fixtures/empty.json + - name: Check published routes and public data + run: | + test -s github-dist/index.html + test -s github-dist/art/index.html + test -s github-dist/learning/index.html + test -s github-dist/knowledge/index.html + test -s github-dist/3d-alpha/index.html + test -s github-dist/art-data/manifest.json + test -s github-dist/records/index.json diff --git a/.github/workflows/pages.yml b/.github/workflows/pages.yml index dd5632d..afeb58b 100644 --- a/.github/workflows/pages.yml +++ b/.github/workflows/pages.yml @@ -3,28 +3,68 @@ on: push: branches: [main] workflow_dispatch: + issues: + types: [opened, edited, closed, reopened, deleted] permissions: contents: read - pages: write - id-token: write concurrency: group: pages - cancel-in-progress: true + cancel-in-progress: false jobs: build-and-deploy: + if: >- + github.event_name != 'issues' || + (github.event.sender.login == github.repository_owner && + github.event.issue.user.login == github.repository_owner && + (startsWith(github.event.issue.title, '[画作]') || + startsWith(github.event.issue.title, '[知识]') || + startsWith(github.event.issue.title, '[成长]') || + startsWith(github.event.changes.title.from, '[画作]') || + startsWith(github.event.changes.title.from, '[知识]') || + startsWith(github.event.changes.title.from, '[成长]'))) + permissions: + contents: write + issues: write + pages: write + id-token: write environment: name: github-pages url: ${{ steps.deployment.outputs.page_url }} runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 + with: + ref: main + fetch-depth: 1 - uses: actions/setup-node@v4 with: node-version: 22 - name: Install dependencies run: npm install - - name: Build static 2D and 3D site + - name: Install isolated image processing tools + run: npm install --prefix "$RUNNER_TEMP/gallery-tools" --no-package-lock --no-save sharp@0.35.4 + - name: Validate archive security and image processing + run: node --test scripts/archive.test.mjs + env: + GALLERY_TOOLS_DIR: ${{ runner.temp }}/gallery-tools + - name: Prepare owner artwork and growth records + run: | + node scripts/build-gallery.mjs + node scripts/sync-records.mjs + env: + GITHUB_TOKEN: ${{ github.token }} + GALLERY_TOOLS_DIR: ${{ runner.temp }}/gallery-tools + - name: Build website run: npm run build + - name: Save knowledge and journal files in GitHub + run: | + git add -- content + if ! git diff --cached --quiet; then + git config user.name "github-actions[bot]" + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" + git commit -m "Archive owner growth records" + git push origin HEAD:main + fi - uses: actions/configure-pages@v5 - uses: actions/upload-pages-artifact@v3 with: @@ -32,3 +72,24 @@ jobs: - name: Deploy to GitHub Pages id: deployment uses: actions/deploy-pages@v4 + - name: Report publication result on the submitted record + if: always() && github.event_name == 'issues' && github.event.action != 'deleted' + uses: actions/github-script@v7 + env: + DEPLOY_OUTCOME: ${{ steps.deployment.outcome }} + with: + script: | + const fs = require('node:fs'); + const number = context.issue.number; + let body; + if (process.env.DEPLOY_OUTCOME !== 'success') { + body = '这次发布未完成,线上保留上次成功版本。请查看本次运行并重试:https://github.com/' + context.repo.owner + '/' + context.repo.repo + '/actions/runs/' + context.runId; + } else { + const reports = ['gallery-report.json', 'records-report.json'].filter(p => fs.existsSync(p)).map(p => JSON.parse(fs.readFileSync(p, 'utf8'))); + const error = reports.flatMap(r => r.errors || []).find(e => e.id === number); + const published = reports.some(r => (r.publishedIds || []).includes(number)); + body = error ? '本记录尚未发布:' + error.message + '。请编辑原记录修正后,系统会自动重试。' + : published ? '已保存并发布到成长档案:https://hulingjun.github.io/ 。知识数据已写入仓库 content/knowledge;画作见 /art/。' + : '本记录当前未在网站展示(已关闭、改名或已被同一空间的新版本取代)。GitHub 记录及历史仍保留。'; + } + await github.rest.issues.createComment({...context.repo, issue_number: number, body}); diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..78fccbb --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +node_modules/ +github-dist/ +gallery-report.json +records-report.json +github-pages/public/art-data/images/ +github-pages/public/records/knowledge/ diff --git a/README.md b/README.md index c6371b3..8418694 100644 --- a/README.md +++ b/README.md @@ -1 +1,35 @@ -# hulingjun.github.io \ No newline at end of file +# HJ · 个人成长记录 + +https://hulingjun.github.io/ + +- 首页:自己的知识、成长随记,以及女儿的成长足迹。 +- /art/:原比例绘画作品,手机可跳转 GitHub 上传。 +- /knowledge/:保留现有节点编辑器,可提交 / 打开 GitHub 知识空间。 +- /learning/:保留原《关键对话》学习实验;/3d-alpha/ 不变。 + +## 保存方式 + +当前是公开 GitHub Pages 网站,无需 Google Cloud、OAuth 密钥或额外后端。 +登录 GitHub **hulingjun** 账号,使用仓库的“上传绘画作品”“保存知识空间”“写一条成长记录”模板。 + +知识编辑器的“保存到 GitHub”捕获当前空间快照,复制 JSON 后跳转提交。自动流程校验作者身份和数据,将知识保存到 content/knowledge/*.json,随记保存到 content/journal/*.json,再发布网站。只有自动回复确认成功才代表保存完成;本地缓存仅是恢复草稿,不是云端同步。 + +同一空间用稳定 spaceId 识别,最新提交编号为生效版本。旧记录和 Git 历史保留。打开 GitHub 空间会创建草稿副本,不覆盖原草稿。旧浏览器中的每个本地空间需要分别提交一次。单次网页提交限制 55000 字符,更大空间请先 JSON 备份并拆分。 + +编辑记录会更新,关闭会从网站下架,重开会恢复。关闭最新知识快照会回退到尚未关闭的较旧快照;全部关闭才会下架空间。已提交的知识文件和 Git 历史不自动删除。 + +## 画作与隐私 + +一条作品记录一张图片:JPG/PNG/WebP/GIF(首帧),最大 10 MB。HEIC 需先转 JPG。构建阶段校验 GitHub 附件域名、每次重定向、大小、MIME 与真实图片格式,自动校正方向,生成不裁切的 WebP 展示图与缩略图,移除元数据。 + +**GitHub 原始附件在上传后可能立即公开,网站去除元数据不等于清理原始附件。** 上传前移除位置、裁掉姓名、学校、地址。关闭记录不删除原始附件。不要提交密钥或私人信息。 + +不纳入贝贝、王洁、营养师、瑜伽、普拉提相关记录;相应文字校验只是防误收录,不是完整内容审查。 + +## 云端构建 + +GitHub Actions 在 main 更新、手动触发、作者本人更改成长记录时同步和部署。外部用户的 Issue 不会触发发布,构建读取记录时另以固定 GitHub 用户 ID 校验身份。Issue 文本只作为 JSON / 文字处理,不进入 shell,不执行代码。 + +archive-check 校验权限、解析、URL 安全、图片尺寸和去元数据、知识文件写入与正式构建。图片工具 sharp 0.35.4 在 Actions 临时目录独立安装,不改变现有应用依赖与锁文件。 + +部署失败保留线上上一次成功版本。下架仍需成功部署,错误详情在 Actions 以及提交记录的自动回复中。 diff --git a/app/art/page.tsx b/app/art/page.tsx new file mode 100644 index 0000000..5241f38 --- /dev/null +++ b/app/art/page.tsx @@ -0,0 +1,34 @@ +import {useEffect,useRef,useState} from "react"; +import {Artwork,getJson,UPLOAD_ART} from "../shared/archive"; +import ArchiveNav from "../shared/ArchiveNav"; +import "../shared/archive.css"; + +function ArtImage({art}:{art:Artwork}) { + const [error,setError]=useState(false); + return error?图片暂时无法显示,请刷新重试:{art.title}setError(true)}/>; +} +export default function ArtGallery() { + const [artworks,setArtworks]=useState([]); + const [status,setStatus]=useState("loading"); + const [year,setYear]=useState("all"); + const [selected,setSelected]=useState(null); + const dialog=useRef(null); + const [retry,setRetry]=useState(0); + useEffect(()=>{ + const controller=new AbortController();setStatus("loading"); + getJson<{artworks:Artwork[]}>("/art-data/manifest.json",controller.signal).then(data=>{setArtworks(data.artworks);setStatus("ready");}).catch(e=>{if(e.name!=="AbortError")setStatus("error")}); + return ()=>controller.abort(); + },[retry]); + useEffect(()=>{if(selected)dialog.current?.showModal();else dialog.current?.close()},[selected]); + const years=[...new Set(artworks.map(a=>a.date?.slice(0,4)).filter(Boolean))].sort().reverse(); + const visible=artworks.filter(a=>year==="all"||a.date?.startsWith(year)); + return
+

HER GROWTH / ARTWORKS

她眼中的世界。

把每一次落笔,留在成长的时间里。

+ 上传作品
+
怎样上传、修改和下架作品?
  1. 先用手机拍下画作,再点击“上传作品”,在 GitHub 登录 hulingjun 账号。
  2. 填写标题、日期,在“作品图片”中选择相册照片,勾选公开确认后提交。一次提交一幅画。
  3. 通常几分钟后会自动发布。记录下方的回复会告诉你发布结果。
  4. 编辑原记录可修改作品,关闭原记录可下架,重新打开可恢复。

支持 JPG、PNG、WebP、GIF(首帧),最大 10 MB;HEIC 请先转为 JPG。作品保持原比例,不裁切。

GitHub 原始附件是公开的,请先裁掉姓名、学校、住址,并移除照片位置。网站处理版会清除元数据;下架不等于删除原始附件。

管理我的作品 ↗
+

绘画作品 {artworks.length ? String(artworks.length).padStart(2,"0") : ""}

{years.map(y=>)}
+ {status==="loading"?

正在打开画展……

:status==="error"?

画展暂时无法载入,作品不会因此丢失。

:visible.length?
{visible.map(art=>

{art.title}

{art.story&&

{art.story}

}
)}
:

{artworks.length?"这一年还没有作品":"第一幅画,从这里留下。"}

不需要画得完美,每一幅都值得留存。

上传第一幅作品 ↗
} + setSelected(null)} onClick={e=>{if(e.target===e.currentTarget)setSelected(null)}} aria-labelledby="art-title"> + {selected&&<>

{selected.title}

{selected.title}{selected.story&&

{selected.story}

}查看 / 管理作品记录 ↗} +
+
HJ / 她的成长档案返回成长记录 ↗
; +} diff --git a/app/knowledge/GitHubArchive.tsx b/app/knowledge/GitHubArchive.tsx new file mode 100644 index 0000000..e5b24bc --- /dev/null +++ b/app/knowledge/GitHubArchive.tsx @@ -0,0 +1,62 @@ +import {useEffect,useRef,useState} from "react"; +import type {KnowledgeGraph} from "./model"; +import {isKnowledgeGraph} from "./model"; +import {Archive,getJson,NEW_KNOWLEDGE,KnowledgeRecord} from "../shared/archive"; +import "./github-archive.css"; +export default function GitHubArchive({graph,spaceId,onLoad}:{graph:KnowledgeGraph;spaceId:string;onLoad:(id:string,graph:KnowledgeGraph)=>void}){ + const dialog=useRef(null); + const textarea=useRef(null); + const [mode,setMode]=useState<"save"|"load">("save"); + const [items,setItems]=useState([]); + const [message,setMessage]=useState(""); + const [busy,setBusy]=useState(false); + const [payload,setPayload]=useState(""); + const autoOpened=useRef(false); + async function loadRecord(item:KnowledgeRecord){ + setBusy(true);setMessage("正在读取 GitHub 版本……"); + try{ + const data=await getJson<{spaceId:string;graph:KnowledgeGraph}>(item.path); + if(!isKnowledgeGraph(data.graph)||data.spaceId!==item.id)throw new Error("知识数据格式不正确"); + onLoad(data.spaceId,data.graph);dialog.current?.close();setMessage(""); + }catch(e){setMessage(e instanceof Error?e.message:"读取失败,请重试");} + finally{setBusy(false)} + } + async function refresh(){ + setBusy(true);setMessage("正在读取已发布空间……"); + try{const data=await getJson("/records/index.json");setItems(data.knowledge);setMessage(data.knowledge.length?"":"还没有 GitHub 版本。请先保存一个空间。");return data.knowledge;} + catch{setMessage("读取失败,请检查网络后重试。");return []} + finally{setBusy(false)} + } + useEffect(()=>{ + if(autoOpened.current||!spaceId)return; + autoOpened.current=true; + const id=new URLSearchParams(window.location.search).get("cloud"); + if(id){setMode("load");dialog.current?.showModal();refresh().then(list=>{const item=list.find(k=>k.id===id);if(item)loadRecord(item);else setMessage("此空间暂未发布,或已从网站下架。")})} + },[spaceId]); + const beginSave=()=>{ + // Capture a stable snapshot; later canvas edits are not silently included. + setMode("save");setPayload(JSON.stringify({version:1,spaceId,graph},null,2));setMessage("");dialog.current?.showModal(); + }; + const tooLarge=payload.length>55000; + return <> + + + +

{mode==="save"?"保存这次思考":"我的 GitHub 空间"}

+ {mode==="save"?<> +

知识会提交到公开的 GitHub 仓库,发布成功后出现在成长记录中。只有 hulingjun 提交的记录会被收录。

+
  1. 复制下方完整数据。
  2. 打开 GitHub,粘贴到“知识数据”,勾选公开确认并提交。
  3. 等待自动回复确认保存成功。仅复制或打开 GitHub 不代表已保存。
+