fix(andreknie.de): normalize SEO metadata and document structure
This commit is contained in:
@@ -25,7 +25,7 @@ function readContentDir(subdir) {
|
||||
return {
|
||||
...data,
|
||||
slug,
|
||||
body: marked(content),
|
||||
body: renderMarkdownContent(content),
|
||||
_source: `${subdir}/${filename}`
|
||||
}
|
||||
}
|
||||
@@ -41,6 +41,18 @@ function readContentDir(subdir) {
|
||||
.filter(Boolean)
|
||||
}
|
||||
|
||||
export function renderMarkdownContent(content) {
|
||||
const tokens = marked.lexer(content)
|
||||
const firstContentToken = tokens.findIndex(token => token.type !== 'space')
|
||||
const firstToken = tokens[firstContentToken]
|
||||
|
||||
if (firstToken?.type === 'heading' && firstToken.depth === 1) {
|
||||
tokens.splice(firstContentToken, 1)
|
||||
}
|
||||
|
||||
return marked.parser(tokens)
|
||||
}
|
||||
|
||||
function readMetaFile(filename) {
|
||||
const filepath = join(CONTENT_DIR, 'meta', filename)
|
||||
if (!existsSync(filepath)) return null
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { renderMarkdownContent } from './vite-plugin-content.js'
|
||||
|
||||
describe('markdown content rendering', () => {
|
||||
it('removes only an initial level-one heading', () => {
|
||||
const html = renderMarkdownContent('# Duplicate title\n\nIntro\n\n## Section')
|
||||
|
||||
expect(html).not.toContain('<h1>Duplicate title</h1>')
|
||||
expect(html).toContain('<p>Intro</p>')
|
||||
expect(html).toContain('<h2>Section</h2>')
|
||||
})
|
||||
|
||||
it('keeps content when no initial level-one heading exists', () => {
|
||||
const html = renderMarkdownContent('Intro\n\n# Deliberate heading')
|
||||
|
||||
expect(html).toContain('<p>Intro</p>')
|
||||
expect(html).toContain('<h1>Deliberate heading</h1>')
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user