mirror of
https://github.com/OpenSquawk/OpenSquawk
synced 2026-08-06 09:16:26 +08:00
Align public messaging and add news banners
This commit is contained in:
@@ -6,6 +6,7 @@ export interface NewsPost {
|
||||
body: string
|
||||
html: string
|
||||
readingTime: string
|
||||
bannerFile: string
|
||||
}
|
||||
|
||||
interface FrontMatter {
|
||||
@@ -15,6 +16,7 @@ interface FrontMatter {
|
||||
excerpt?: string
|
||||
description?: string
|
||||
readingTime?: string
|
||||
banner?: string
|
||||
}
|
||||
|
||||
const rawNewsModules = import.meta.glob('~~/content/news/*.md', {
|
||||
@@ -51,6 +53,7 @@ function parseNewsFile(path: string, raw: string): NewsPost | null {
|
||||
const excerpt = truncateText(excerptSource || firstParagraph(cleanBody), 220)
|
||||
const html = markdownToHtml(cleanBody)
|
||||
const readingTime = attributes.readingTime || formatReadingTime(cleanBody)
|
||||
const bannerFile = normalizeBannerFile(attributes.banner, slug)
|
||||
|
||||
return {
|
||||
slug,
|
||||
@@ -60,6 +63,7 @@ function parseNewsFile(path: string, raw: string): NewsPost | null {
|
||||
body: cleanBody,
|
||||
html,
|
||||
readingTime,
|
||||
bannerFile,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -146,6 +150,14 @@ function formatReadingTime(content: string): string {
|
||||
return `${minutes} Min Lesezeit`
|
||||
}
|
||||
|
||||
function normalizeBannerFile(banner: string | undefined, slug: string): string {
|
||||
const value = (banner || '').trim()
|
||||
if (!value) {
|
||||
return `${slug}.svg`
|
||||
}
|
||||
return value.includes('.') ? value : `${value}.svg`
|
||||
}
|
||||
|
||||
function markdownToHtml(markdown: string): string {
|
||||
const lines = markdown.split(/\r?\n/)
|
||||
let html = ''
|
||||
|
||||
Reference in New Issue
Block a user