feat(site-migrator): rewrite same-origin URL refs and assign per-page integer ids#905
Merged
Merged
Conversation
… integer ids
extractPages now assigns a deterministic integer id to every page in items
(directory-grouped: root 5/10/15…, Nth subdir N×10000+step5) and prepends
`id: <number>` to the YAML frontmatter. Body HTML is streamed through
rewritePageRefs, which converts same-origin <a href>/<form action>/<iframe src>
and <link rel=canonical|alternate|prev|next href> into the `{{<id>}}` template
the downstream scaffold pipeline consumes, while other same-origin asset URLs
(img, script, stylesheets, srcset, etc.) become root-relative paths.
Lookups absorb trailing-slash drift and prefer exact ?query matches before the
pathname-only fallback so URLs differing only by query string keep their own
ids. Section overflow (>2000 pages) throws rather than silently aliasing into
the next section.
rewritePageRefs / getFrontmatter failures stay fail-soft: the body is still
written and the outcome carries rewriteError / metaError; migrate() aggregates
both via pagesRewriteFailed / pagesMetaFailed.
AssetResolver gains a fourth `tagAttrs` argument so resolvers can read sibling
attributes (used to gate <link href> on rel).
286db90 to
d125c60
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
extractPagesで全ページの URL に決定論的な整数 id を割り当て、---\nid: <number>\n---\nを先頭に prepend する。採番は後段 scaffold パイプラインが期待する方式(root section: 5, 10, 15…/ N 番目のサブディレクトリセクション: N×10000+step5)で、@d-zero/shared/sort/pathのpathComparatorと@d-zero/shared/sort/alphabeticalのalphabeticalComparatorで安定化済み。1 セクションあたり 2000 ページを超える場合は黙ってエイリアスせず明示的に throw。rewritePageRefsを新設し、本文中の同一オリジン参照を後段 scaffold パイプライン向けに書き換える。<a href>/<form action>/<iframe src>/<link rel=canonical|alternate|prev|next href>→{{<id>}}?q=foo#fragテンプレート。<link rel=stylesheet|icon>等)→ root-relative path。mailto:/tel:/sms:/javascript:/data:/blob:/vbscript:/file:・#fragment単独(先頭空白付きも含む)は触らない。buildPageIdLookupで 1 回だけ構築(per-page 構築だと O(N²))。trailing-slash drift を吸収しつつ exact?query一致を pathname-only fallback より優先するので、/list?p=1と/list?p=2双方がpageIdsにあれば各々の id に解決される。rewritePageRefs/getFrontmatterの失敗は fail-soft。HTML 本文は書き出し、onResultの outcome にrewriteError/metaErrorを載せて警告、MigrateReportのpagesRewriteFailed/pagesMetaFailedで集計。CLI は stderr に warn を 1 行追加するだけ。AssetResolverに 4 番目の引数tagAttrsを追加。<link href>をrelで振り分けるために必要。Test plan
yarn test(127 件パス)yarn lint(cspell / eslint / prettier / textlint 全 OK)yarn build