Skip to content

Refactor docs structure: fix title/sidebar mismatches, complete English translation#56

Merged
CodFrm merged 10 commits into
scriptscat:mainfrom
cyfung1031:refactor-001
Jul 8, 2026
Merged

Refactor docs structure: fix title/sidebar mismatches, complete English translation#56
CodFrm merged 10 commits into
scriptscat:mainfrom
cyfung1031:refactor-001

Conversation

@cyfung1031

@cyfung1031 cyfung1031 commented Jul 6, 2026

Copy link
Copy Markdown
Collaborator

Summary

Implements the plan in REFACTOR_PROPOSAL.md, addressing two problems raised about this repo:

  1. The docs//i18n/ folder structure was messy (numbered-prefix filenames, README.md-as-index files needing id: frontmatter overrides, three different URL-derivation mechanisms).
  2. Sidebar labels could silently mismatch the page they linked to (e.g. sidebar showed "VSCode 扩展开发脚本" while the page's actual heading was "使用 VSCode 开发脚本").

No published URL changes except one intentional addition (/docs/use/ now redirects to the existing /docs/use/use/, fixing a pre-existing dead link in the footer and in-page content). This is enforced by a committed URL inventory (scripts/url-inventory.txt) diffed in CI on every build.

  • Phase 0 — added pnpm run check (URL inventory / i18n parity / frontmatter lint scripts) and a Gitea Actions CI workflow that runs it on every PR.
  • Phase 1 — fixed 2 broken links, 7 broken anchors, and a deprecated Docusaurus config option that a permissive onBrokenLinks: "warn" had let ship; flipped to "throw".
  • Phase 2 — renamed every doc so its file path matches its doc ID/URL exactly, deleted the id:/sidebar_position: frontmatter overrides that existed only to work around mismatched filenames, and made all three sidebars (use/dev/change) fully explicit in sidebars.js.
  • Phase 3 — normalized every image folder to a <doc-name>.assets/ sibling directory (matching the convention already used by dev/background.assets/ etc.), splitting/merging folders that had been shared across multiple docs.
  • Phase 4 — moved every doc's H1 into frontmatter title (the only title source now; sidebar/browser-title/H1 mismatches are impossible by construction) and fixed the specific mismatches, including the VSCode one reported.
  • Phase 5 — translated the 25 zh-Hans docs that had no English mirror (all of dev/ including the whole Agent section, plus about/ and 5 changelog entries), so the English site no longer silently falls back to Chinese content.

Also added CONTRIBUTING.md documenting these conventions for future contributors/agents.

Test plan

  • pnpm run build — clean build, zero broken links/anchors/images, both locales (onBrokenLinks/onBrokenAnchors: throw)
  • pnpm run check — URL inventory (94/94 routes match baseline), i18n parity (41/41 docs translated), frontmatter lint — all pass in strict mode
  • Verified in a local preview: the VSCode page's sidebar label, browser title, and H1 all now read "使用 VSCode 开发脚本"; the English Agent section renders correctly with translated content and a translated "Agent" category label in the sidebar/breadcrumb
  • Confirmed via git mv + rebuild that renames introduced zero URL drift, including one non-obvious case (use/use.md's slug auto-collapsing when the filename matches its parent directory name — pinned with an explicit slug: override)

🤖 Generated with Claude Code

cyfung1031 added 10 commits July 7, 2026 02:12
Captures the current-state audit (URL contract, title/H1 mismatches,
translation gaps, broken links/anchors) and the phased plan to fix
folder structure, sidebar/title consistency, and English translation
without changing any published URL.
Adds three checks wired into `pnpm run check`:
- check-url-inventory.mjs: diffs the built site's routes against a
  committed baseline (scripts/url-inventory.txt), generated from the
  current build. This is the mechanical guarantee that later refactor
  phases don't change any published URL.
- check-i18n-parity.mjs: reports zh-Hans docs missing an English
  mirror and vice versa (warn-only via scripts/check-config.json until
  the translation backlog in Phase 5 is cleared).
- check-frontmatter.mjs: reports missing titles, leftover id:/
  sidebar_position: overrides, number-prefixed filenames, and stray
  body H1s (warn-only until Phase 4 normalizes titles).

Also adds a Gitea Actions CI workflow that runs build + check on PRs,
and inserts `pnpm run check` into the deploy workflow so a bad merge
can't ship. .DS_Store was already gitignored and untracked, so no
cleanup was needed there.
… (Phase 1)

- Migrate onBrokenMarkdownLinks to markdown.hooks.onBrokenMarkdownLinks
  (deprecated top-level option, removed in Docusaurus v4) and flip
  onBrokenLinks/onBrokenAnchors to "throw" now that the build is clean.
- Fix the 2 broken links and 7 broken anchors the previous "warn"
  setting let ship:
  - dev/agent/skill-install.md linked to non-existent ./agent-skill
    and ./agent-skill-dev paths instead of the actual sibling
    filenames ./skill.md and ./skill-dev.md.
  - use/6.vscode.md (zh + en) and the footer "使用指南" link pointed at
    /docs/use/, which has never resolved (the quick-start doc lives at
    /docs/use/use/) — pointed them at the real path.
  - change/README.md's historical changelog entry linked to a
    non-existent dev/meta.md#console anchor; retargeted to
    dev/background.md#日志, the section it was actually describing.
  - dev/README.md, dev/api.md, dev/meta.md referenced heading anchors
    using the raw Chinese heading text, which doesn't match
    Docusaurus's generated slugs once backticks/parens/emoji are
    stripped (e.g. #定时脚本 -> #定时脚本crontab, #storagename-🧪 ->
    #storagename-, #gm_cookie -> #gm_cookie-).
- Add @docusaurus/plugin-client-redirects with a single redirect,
  /docs/use/ -> /docs/use/use/, as a safety net for old bookmarks/search
  engines (the broken-link checker doesn't recognize plugin-generated
  redirect targets, so in-content links were fixed directly instead).
- editUrl now sets editLocalizedFiles: true so "Edit this page" on
  /en/ docs opens the English source instead of the zh one.
- Add blog: false to the classic preset: bumping @docusaurus/core to
  the already-pinned ^3.10.1 (previously resolved to a stale 3.9.2 in
  the lockfile) caused the default-enabled, content-less blog plugin
  to start emitting empty /blog/ and /en/blog/ routes that never
  existed on the site; disabling it restores the original route set.
- Ran update-browserslist-db (caniuse-lite was 13-15 months stale).

scripts/url-inventory.txt gains exactly 2 routes (/docs/use/index.html,
/en/docs/use/index.html) for the new redirect; no existing route
changed, verified by `pnpm run check`.
Renames every doc so its file path matches its doc id/URL verbatim,
then deletes the id:/sidebar_position: frontmatter overrides that
existed only to paper over the mismatch:

- docs/use/N.foo.md -> docs/use/foo.md (numbered-prefix files); the
  numeric prefix was already being stripped from the id/URL by
  Docusaurus, so this is a pure rename with no id override needed.
- docs/use/4.from-other/ -> docs/use/from-other/,
  docs/use/99.policy/ -> docs/use/policy/ (same reasoning for dirs).
- docs/dev/agent/{conversation,dom,skill,skill-dev,skill-install,
  task,model,opfs,mcp,builtin-tools}.md -> agent-*.md, matching the
  id: overrides they previously needed (dev/agent/agent-conversation
  etc.) so the override can be deleted instead of the filename staying
  arbitrary.
- docs/dev/README.md -> docs/dev/index.md, docs/change/README.md ->
  docs/change/index.md, docs/about/README.md -> docs/about/index.md:
  README-as-index needed an explicit id: override before; index.md is
  Docusaurus's native landing-page convention, no override needed.
- docs/change/beta.md -> docs/change/beta-changelog.md to match its
  id: beta-changelog override (now deleted).
- docs/use/1.README.md -> docs/use/use.md keeps a `slug: /use/use`
  frontmatter override — Docusaurus auto-collapses a doc whose
  filename matches its enclosing folder name (here "use/use.md") to
  the parent path, which would have silently changed the published
  URL from /docs/use/use/ to /docs/use/; the explicit slug pins it.
- Deleted the two _category_.json files; their labels move into
  sidebars.js as explicit category items.
- sidebars.js is now fully explicit for all three sidebars (use, dev,
  change), replacing autogeneration (which had a real ordering
  collision between the two files both prefixed "2.") and the
  descending sidebar_position: 9995..10000 changelog-ordering hack.
- Updated the two internal cross-references that pointed at renamed
  files by relative path (change/index.md <-> beta-changelog.md,
  dev/agent/agent-skill-install.md -> agent-skill.md/agent-skill-dev.md),
  and updated the two navbar docId references (dev/dev -> dev/index,
  change/change -> change/index) to match.

Every file was moved in both docs/ and its i18n/en mirror (where a
mirror exists) so ids stay aligned across locales.

Verified via `pnpm run check`: the URL inventory is still exactly the
94 routes from Phase 1 (zero drift from ~35 file renames), and the
build has zero broken links/anchors under the "throw" settings from
Phase 1.
Migrates every img/*.assets/ nested folder to a plain sibling
<doc-name>.assets/ directory next to its .md file, matching the
convention already used by dev/background.assets, dev/cloudcat.assets,
dev/config.assets, and change/v1.3.assets:

- docs/use/img/README.assets/ split by actual consumer: the 5 images
  used by use/use.md moved to use/use.assets/, the 4 images used by
  use/open-dev.md merged into use/open-dev.assets/ alongside the 6
  images that were already in use/img/5.open-dev.assets/.
- docs/use/from-other/img/{migrate-from-tampermonkey,
  migrate-from-violentmonkey}/ -> sibling
  migrate-from-tampermonkey.assets/ and migrate-from-violentmonkey.assets/.
  Two screenshots of the ScriptCat import step are genuinely shared
  between both migration guides; they stay in
  migrate-from-tampermonkey.assets/ and migrate-from-violentmonkey.md
  references them cross-folder rather than duplicating the files.
- docs/change/img/{README,v0.16}.assets/ (3 + 1 images, both only ever
  referenced from v0.16.md) merged into docs/change/v0.16.assets/;
  img/v0.17.assets/ and img/v1.2.assets/ promoted to plain siblings.
- Same treatment for the i18n/en mirror tree (README.assets/ ->
  use.assets/, 5.open-dev.assets/ -> open-dev.assets/, etc.); the en
  from-other assets were already correctly split per-doc, just needed
  the folder rename.
- All docs/**/img/ directories are now gone; every remaining image
  reference is a relative path to a same-directory *.assets/ folder.

Verified via `pnpm run check`: URL inventory still exactly the 94
routes from Phase 1/2, and a clean rebuild confirms every image
(including the two shared migration-guide screenshots) still resolves
in both locales.
Moves every doc's body H1 into frontmatter `title` and removes the H1
line, so Docusaurus renders the page heading from `title` alone —
making a sidebar/title/H1 mismatch impossible by construction instead
of by convention:

- 42 docs (zh + en) had no frontmatter title at all; a mechanical pass
  lifted their existing H1 text into `title` and deleted the H1 line.
- 6 docs had a title that didn't match their H1 (the actual bugs this
  refactor targets, including the reported "VSCode 扩展开发脚本" vs
  "使用 VSCode 开发脚本" mismatch):
  - use/vscode.md (zh + en): title replaced with the H1 text so the
    sidebar now shows what the page actually says.
  - use/policy/{disclaimer,privacy,privacy_website}.md (zh) and
    policy/disclaimer.md (en): title replaced with the fuller H1 text,
    with the previous short title preserved as `sidebar_label` so the
    sidebar entry stays uncluttered while the page title is accurate.
  - use/policy/privacy.md and privacy_website.md (en) already had no
    body H1, so were left untouched.
- use/install_comple.md keeps its `hide_title: true` exemption (its
  decorative "🎉 欢迎使用脚本猫" H1 is intentional).

Fixed a false positive in check-frontmatter.mjs: it was flagging
example "# Heading" lines inside fenced ```markdown code samples
(dev/agent/agent-skill-dev.md's SKILL.cat.md examples) as real H1s.
The check now strips fenced code blocks before scanning.

With zero real violations left, scripts/check-config.json flips
frontmatterStrict to true, so this class of mismatch fails CI instead
of just warning.

Verified via `pnpm run check`: URL inventory still the same 94 routes,
build is clean, and the frontmatter check now passes in strict mode.
…(Phase 5)

Translates the 25 zh-Hans docs that had no English mirror:

- about/index.md
- change/{v0.16,v0.17,v1.1,v1.2,v1.4}.md
- dev/{index,api,background,cat-api,cloudcat,config,meta,subscribe}.md
- dev/agent/{index,agent-conversation,agent-dom,agent-mcp,agent-model,
  agent-opfs,agent-skill,agent-skill-dev,agent-skill-install,
  agent-task,agent-builtin-tools}.md

Cross-reference anchors were translated to match the actual heading
slugs Docusaurus generates for the English headings (e.g.
background.md's "## Scheduled Script (`@crontab`)" produces
#scheduled-script-crontab, not the zh slug) — verified by rebuilding
with onBrokenAnchors: throw.

Screenshots referenced by the newly translated change/v0.16.md,
v0.17.md, v1.2.md, and dev/background.md, cloudcat.md, config.md are
genuinely language-neutral UI screenshots; rather than duplicating the
binary files into the en tree, these six docs reference the existing
zh screenshots via @site/docs/... absolute paths.

scripts/check-config.json flips i18nParityStrict to true now that the
translation backlog is cleared, so a doc added to one locale without
its mirror will fail CI going forward.

Verified via `pnpm run check`: URL inventory still the same 94 routes,
i18n parity passes (41/41 docs translated), frontmatter check passes,
and the build is clean with zero broken links/anchors/images in both
locales.
Documents the one-convention-per-concern rules from
REFACTOR_PROPOSAL.md (file path = URL, title-only frontmatter, sidebar
ordering, asset folders, i18n mirroring) plus the load-bearing URLs
that must never change and the zh/en terminology glossary, so future
contributors and agents don't need to rediscover these rules from the
proposal doc or git history.
The "dev" sidebar's "Agent 智能助手" category had no i18n string, so
the English site was falling back to the raw Chinese label in the
sidebar and breadcrumbs. Adds sidebar.dev.category.Agent 智能助手 ->
"Agent" to i18n/en/docusaurus-plugin-content-docs/current.json,
verified in the browser preview (breadcrumb now reads "Agent >
Installing and Using Skills" instead of "Agent 智能助手 > ...").
@cyfung1031

cyfung1031 commented Jul 6, 2026

Copy link
Copy Markdown
Collaborator Author

This is full refactoring & translation by AI.

merge this first.

the detail translation will be covered by #30

run: |
pnpm install --frozen-lockfile
pnpm run build
pnpm run check

@CodFrm CodFrm Jul 8, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check应该在build前面

原来需要check构建后的产物

@CodFrm CodFrm merged commit 00bc2b7 into scriptscat:main Jul 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants