diff --git a/next/src/layouts/Article.astro b/next/src/layouts/Article.astro index ef6c72bcdb0e4..8b88758460bad 100644 --- a/next/src/layouts/Article.astro +++ b/next/src/layouts/Article.astro @@ -45,7 +45,7 @@ const jsonLd = [{ description: post.description, ...(post.dateStr ? { datePublished: post.dateStr } : {}), image: post.image, - author: post.author ? { '@type': 'Person', name: post.author } : { '@type': 'Organization', name: 'Apache APISIX' }, + author: post.authors?.length ? post.authors.map((name) => ({ '@type': 'Person', name })) : post.author ? { '@type': 'Person', name: post.author } : { '@type': 'Organization', name: 'Apache APISIX' }, publisher: { '@type': 'Organization', name: 'Apache APISIX', url: SITE }, mainEntityOfPage: `${SITE}${locale === 'zh' ? '/zh' : ''}${path}`, }, ...jsonLdExtra]; diff --git a/next/src/lib/content.ts b/next/src/lib/content.ts index b87dbe7fca4d8..3321f9950a747 100644 --- a/next/src/lib/content.ts +++ b/next/src/lib/content.ts @@ -71,6 +71,7 @@ export interface Post { tags: string[]; image?: string; author?: string; + authors?: string[]; /** Stable source identity used to pair real EN/ZH blog translations. */ translationKey?: string; mod: MdModule; @@ -145,6 +146,7 @@ function blogPost(path: string, mod: MdModule, locale: Locale): Post | null { // normalizeUrl collapses it; see the 2021-06-03 firsthand-experience post). const slug = (fmSlug ?? name).replace(/^\/+/, ''); const urlPath = slug.includes('/') ? slug : `${y}/${mo}/${d}/${slug}`; + const authors = authorNames(mod.frontmatter); return { url: `${localePrefix(locale)}/blog/${urlPath}/`, slug: urlPath, @@ -155,8 +157,8 @@ function blogPost(path: string, mod: MdModule, locale: Locale): Post | null { dateHuman: humanDate(new Date(`${y}-${mo}-${d}T00:00:00Z`), locale), tags: toTags(mod.frontmatter), image: mod.frontmatter.image, - author: mod.frontmatter.author - ?? (Array.isArray(mod.frontmatter.authors) ? mod.frontmatter.authors[0]?.name : undefined), + author: authors.length ? authors.join(', ') : undefined, + authors, translationKey: String( mod.frontmatter.translationKey ?? mod.frontmatter.translation_key @@ -166,6 +168,14 @@ function blogPost(path: string, mod: MdModule, locale: Locale): Post | null { }; } +function authorNames(fm: any): string[] { + if (fm.author) return [String(fm.author)]; + if (!Array.isArray(fm.authors)) return []; + return fm.authors + .map((a: any) => (typeof a === 'string' ? a : a?.name)) + .filter(Boolean); +} + function flatPost(path: string, mod: MdModule, urlBase: string, locale: Locale): Post { const slug = mod.frontmatter.slug ?? baseName(path); const date = mod.frontmatter.date ? new Date(mod.frontmatter.date) : new Date(0);