Skip to content

Commit cda36e9

Browse files
committed
fix: remove h1 from imported readme
1 parent 5436616 commit cda36e9

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

nuxt.config.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ export default defineNuxtConfig({
9898
// robots.txt only works at a domain root; under the /litestar.dev-v2/ subpath
9999
// crawlers ignore it and the module errors. Meta tags apply either way.
100100
robotsTxt: (process.env.NUXT_APP_BASE_URL || '/') === '/',
101+
credits: false,
101102
},
102103
linkChecker: {
103104
// Fail CI on broken internal links (warnings don't fail the build).
@@ -220,6 +221,26 @@ export default defineNuxtConfig({
220221
// @ts-expect-error -- TODO: fix this
221222
delete content.meta.body
222223
}
224+
225+
// Drop the README's leading <h1> so it doesn't duplicate <UPageHeader>'s title on /plugins/<slug>.
226+
if (file.id?.startsWith('readme/')) {
227+
// @ts-expect-error -- meta.body is the minimark AST for data .md files
228+
const root = content?.meta?.body?.value
229+
const stripFirstH1 = (parent: unknown[], start: number): boolean => {
230+
for (let i = start; i < parent.length; i++) {
231+
const node = parent[i]
232+
if (!Array.isArray(node)) continue
233+
const tag = node[0]
234+
if (typeof tag === 'string' && /^h[1-6]$/.test(tag)) {
235+
if (tag === 'h1') parent.splice(i, 1)
236+
return true
237+
}
238+
if (stripFirstH1(node as unknown[], 2)) return true
239+
}
240+
return false
241+
}
242+
if (Array.isArray(root)) stripFirstH1(root, 0)
243+
}
223244
},
224245
},
225246
icon: {

0 commit comments

Comments
 (0)