@@ -132,18 +132,16 @@ function escapeHtml(str) {
132132}
133133
134134/**
135- * Build the pre-populated markup that goes inside <div id="app">.
136- * Mirrors the layout produced at runtime by renderHeader() + renderDocPage()
137- * + renderFooter() in website/src/main.js, but statically — so crawlers see
138- * real content in the initial HTML response.
135+ * Wrap the doc fragment in the structure that website/src/components/doc-page.js
136+ * produces at runtime: a centered article container with a #doc-content div.
137+ * The content is injected into the shell's #page-content div so crawlers and
138+ * non-JS fetchers see real content in the initial HTML response.
139139 */
140- function buildAppMarkup ( fragmentHtml ) {
140+ function buildDocContentMarkup ( fragmentHtml ) {
141141 return `
142- <main class="flex-1">
143- <article class="mx-auto max-w-4xl px-4 py-8 sm:px-6 lg:px-8">
144- <div id="doc-content" class="asciidoc-content">${ fragmentHtml } </div>
145- </article>
146- </main>
142+ <article class="mx-auto max-w-4xl px-4 py-8 sm:px-6 lg:px-8">
143+ <div id="doc-content" class="asciidoc-content">${ fragmentHtml } </div>
144+ </article>
147145 `
148146}
149147
@@ -187,11 +185,19 @@ function prerenderRoute(shell, route) {
187185 `<link rel="canonical" href="${ canonicalUrl } " />`
188186 )
189187
190- // Inject pre-rendered content into #app
191- html = html . replace (
192- / < d i v \s + i d = " a p p " \s * > \s * < \/ d i v > / ,
193- `<div id="app">${ buildAppMarkup ( fragment ) } </div>`
194- )
188+ // Inject pre-rendered content into the static shell's #page-content div.
189+ // The shell (set up in website/index.html and preserved through vite build)
190+ // contains:
191+ // <div id="page-content" ... style="..."></div>
192+ // We match that empty div by id and fill it with the doc content so crawlers
193+ // receive real HTML while JS users still get the SPA hydration on top.
194+ const pageContentRegex = / ( < d i v \s + i d = " p a g e - c o n t e n t " [ ^ > ] * > ) \s * ( < \/ d i v > ) /
195+ if ( ! pageContentRegex . test ( html ) ) {
196+ throw new Error (
197+ `Shell #page-content div not found in dist/index.html. Did website/index.html lose the skeleton structure?`
198+ )
199+ }
200+ html = html . replace ( pageContentRegex , `$1${ buildDocContentMarkup ( fragment ) } $2` )
195201
196202 const outDir = path . join ( DIST , route . path )
197203 const outFile = path . join ( outDir , 'index.html' )
0 commit comments