feat(andreknie.de): improve accessibility and initial loading

This commit is contained in:
2026-07-28 23:53:18 +02:00
parent cf0fbd077e
commit 88bd952a60
27 changed files with 393 additions and 109 deletions
@@ -7,8 +7,10 @@ import * as yaml from 'js-yaml'
const CONTENT_DIR = resolve(process.cwd(), 'content')
const VIRTUAL_MODULE_ID = 'virtual:content'
const RESOLVED_VIRTUAL_MODULE_ID = '\0' + VIRTUAL_MODULE_ID
const DETAILS_VIRTUAL_MODULE_ID = 'virtual:content-details'
const RESOLVED_DETAILS_VIRTUAL_MODULE_ID = '\0' + DETAILS_VIRTUAL_MODULE_ID
function readContentDir(subdir) {
function readContentDir(subdir, includeBodies = false) {
const dir = join(CONTENT_DIR, subdir)
if (!existsSync(dir)) return []
@@ -22,10 +24,12 @@ function readContentDir(subdir) {
if (ext === '.md') {
const raw = readFileSync(filepath, 'utf-8')
const { data, content } = matter(raw)
const body = renderMarkdownContent(content)
const searchText = body.replace(/<[^>]+>/g, ' ').replace(/\s+/g, ' ').trim()
return {
...data,
slug,
body: renderMarkdownContent(content),
...(includeBodies ? { body } : { searchText }),
_source: `${subdir}/${filename}`
}
}
@@ -60,15 +64,15 @@ function readMetaFile(filename) {
return yaml.load(raw)
}
function loadAllContent() {
function loadAllContent(includeBodies = false) {
return {
posts: readContentDir('posts'),
kniepunkt: readContentDir('kniepunkt'),
podcast: readContentDir('podcast'),
talks: readContentDir('talks'),
consulting: readContentDir('consulting'),
resources: readContentDir('resources'),
events: readContentDir('events'),
posts: readContentDir('posts', includeBodies),
kniepunkt: readContentDir('kniepunkt', includeBodies),
podcast: readContentDir('podcast', includeBodies),
talks: readContentDir('talks', includeBodies),
consulting: readContentDir('consulting', includeBodies),
resources: readContentDir('resources', includeBodies),
events: readContentDir('events', includeBodies),
meta: {
profile: readMetaFile('profile.yaml'),
stats: readMetaFile('stats.yaml'),
@@ -87,12 +91,17 @@ export default function contentPlugin() {
name: 'vite-plugin-content',
resolveId(id) {
if (id === VIRTUAL_MODULE_ID) return RESOLVED_VIRTUAL_MODULE_ID
if (id === DETAILS_VIRTUAL_MODULE_ID) return RESOLVED_DETAILS_VIRTUAL_MODULE_ID
},
load(id) {
if (id === RESOLVED_VIRTUAL_MODULE_ID) {
const content = loadAllContent()
return `export default ${JSON.stringify(content)}`
}
if (id === RESOLVED_DETAILS_VIRTUAL_MODULE_ID) {
const content = loadAllContent(true)
return `export default ${JSON.stringify(content)}`
}
},
handleHotUpdate({ file, server }) {
if (file.includes('content')) {