From d68eb5161e3e2df496cb8f456c0efe94613f8372 Mon Sep 17 00:00:00 2001 From: Zsolt Tasnadi Date: Fri, 6 Mar 2026 19:30:32 +0100 Subject: [PATCH] blog index content --- apps/frontend/src/pages/blog.astro | 78 +++++++++++++++++++++++++++--- 1 file changed, 71 insertions(+), 7 deletions(-) diff --git a/apps/frontend/src/pages/blog.astro b/apps/frontend/src/pages/blog.astro index a5c0175..d5a405e 100644 --- a/apps/frontend/src/pages/blog.astro +++ b/apps/frontend/src/pages/blog.astro @@ -9,6 +9,7 @@ interface WikiPage { path: string; title: string; description: string; + content: string; render?: string; updatedAt: string; createdAt: string; @@ -59,11 +60,43 @@ try { } const pages = listJson?.data?.pages?.list ?? []; - blogPages = pages.map((p: any) => ({ + + // 2. Fetch content for each page (WikiJS list doesn't include content) + // To keep it efficient, we only fetch the first few blog posts' content if needed, + // or we can fetch all if the list is short. + const pagesWithContent = await Promise.all(pages.map(async (p: any) => { + try { + const CONTENT_QUERY = ` + { + pages { + single(id: ${p.id}) { + content + } + } + } + `; + const contentRes = await fetch(`${WIKIJS_BASE_URL}/graphql`, { + method: 'POST', + headers, + body: JSON.stringify({ query: CONTENT_QUERY }), + }); + const contentJson = await contentRes.json(); + return { + ...p, + content: contentJson?.data?.pages?.single?.content ?? '' + }; + } catch (e) { + console.error(`Failed to fetch content for page ${p.id}`, e); + return { ...p, content: '' }; + } + })); + + blogPages = pagesWithContent.map((p: any) => ({ id: p.id, path: p.path, title: p.title || p.path, description: p.description ?? '', + content: p.content ?? '', updatedAt: p.updatedAt, createdAt: p.createdAt, locale: p.locale, @@ -93,6 +126,14 @@ function getPermalink(path: string): string { const slug = path.startsWith('blog/') ? path.replace('blog/', '') : path; return `/blog/${slug}`; } + +function getCleanPreview(content: string): string { + if (!content) return ''; + return content + .replace(/[#*`_\[\]()]/g, '') + .trim() + .slice(0, 300) + '...'; +} --- @@ -165,11 +206,19 @@ function getPermalink(path: string): string { - {page.description && ( -

- {page.description} -

- )} +
+ {page.description && ( +

+ {page.description} +

+ )} + + {page.content && ( +

+ {getCleanPreview(page.content)} +

+ )} +