diff --git a/apps/member/src/app/admin/index.tsx b/apps/member/src/app/admin/index.tsx index 97e1c08..9d39c39 100644 --- a/apps/member/src/app/admin/index.tsx +++ b/apps/member/src/app/admin/index.tsx @@ -807,6 +807,13 @@ function Events({ api, site }: { api: AdminApi; site: Site }) { ); } +/** A text box whose typed text stays as typed, while the parsed value goes to onChange. */ +function TextAsList({ label, initial, onChange, hint, multiline }: { label: string; initial: string; onChange: (v: string) => void; hint?: string; multiline?: boolean }) { + const [text, setText] = useState(initial); + return { setText(v); onChange(v); }} />; +} + function Pages({ api, site }: { api: AdminApi; site: Site }) { const t = useTheme(); const [pages, setPages] = useState(null); @@ -846,9 +853,21 @@ function Pages({ api, site }: { api: AdminApi; site: Site }) { setEdit({ ...edit, summary: v })} hint="Shown on cards and used as the search-result description if you leave the SEO description empty." /> setEdit({ ...edit, body: v })} multiline style={{ minHeight: 220, textAlignVertical: 'top' }} hint={edit.slug === 'home' ? 'Your home page. Title is the headline, Summary the intro. In the body: lines starting with "- " are the checklist, a line starting with "## " starts a section, and each card is a title line with its text on the next line. Leave a blank line between blocks.' - : 'Separate paragraphs with a blank line.'} /> - setEdit({ ...edit, seoTitle: v })} /> - setEdit({ ...edit, seoDescription: v })} /> + : 'Separate paragraphs with a blank line. "## " starts a heading, lines starting with "- " make a list, a short title line with text under it makes a question and answer, and [link text](https://…) or [link text](/other-page) makes a link.'} /> + setEdit({ ...edit, seoTitle: v })} hint="What search results show. Aim for under 60 characters." /> + setEdit({ ...edit, seoDescription: v })} hint="Aim for 120 to 160 characters." /> + {edit.placement === 'guides' ? ( + <> + setEdit({ ...edit, notice: v === 'none' ? undefined : v })} /> + setEdit({ ...edit, reviewedAt: v.trim() || undefined })} hint="The date you last checked the facts. Shown on the article. Update it when you re-check medical or research news." /> + `${x.title} | ${x.url}`).join('\n')} + onChange={(v) => setEdit((e) => e && ({ ...e, sources: v.split('\n').map((l) => l.split('|')).filter((x) => x.length >= 2 && x[0].trim()).map(([t, ...u]) => ({ title: t.trim(), url: u.join('|').trim() })) }))} /> + setEdit((e) => e && ({ ...e, related: v.split(',').map((x) => x.trim()).filter(Boolean) }))} /> + + ) : null} setEdit({ ...edit, published: v })} /> diff --git a/apps/web/app/[slug]/page.tsx b/apps/web/app/[slug]/page.tsx index 2cb558c..c006031 100644 --- a/apps/web/app/[slug]/page.tsx +++ b/apps/web/app/[slug]/page.tsx @@ -1,38 +1,98 @@ import type { Metadata } from 'next'; import { notFound } from 'next/navigation'; -import { HOME_SLUG } from '@whatbox/core'; -import { baseUrl, getPage, getSite } from '../../lib/site'; +import { categorySlug, faqPairs, HOME_SLUG, readingMinutes, relatedArticles } from '@whatbox/core'; +import { baseUrl, getPage, getPages, getSite } from '../../lib/site'; +import { Body } from '../body'; type Props = { params: Promise<{ slug: string }> }; +const longDate = (d: string) => new Date(d.length === 10 ? d + 'T12:00:00Z' : d).toLocaleDateString('en-US', { year: 'numeric', month: 'long', day: 'numeric', timeZone: 'UTC' }); + export async function generateMetadata({ params }: Props): Promise { const { slug } = await params; const page = slug === HOME_SLUG ? null : await getPage(slug); if (!page) return {}; + const title = page.seoTitle || page.title; + const description = page.seoDescription || page.summary; + const url = `${await baseUrl()}/${page.slug}`; return { - title: page.seoTitle || page.title, - description: page.seoDescription || page.summary, - alternates: { canonical: `${await baseUrl()}/${page.slug}` }, - openGraph: { title: page.seoTitle || page.title, description: page.seoDescription || page.summary, type: page.kind === 'article' ? 'article' : 'website' }, + title: { absolute: title.length > 50 ? title : `${title} | ${(await getSite()).name}` }, + description, + alternates: { canonical: url }, + openGraph: { title, description, url, type: page.kind === 'article' ? 'article' : 'website', ...(page.kind === 'article' ? { modifiedTime: page.updatedAt } : {}) }, + twitter: { card: 'summary', title, description }, }; } export default async function ContentPage({ params }: Props) { const { slug } = await params; if (slug === HOME_SLUG) notFound(); // the landing copy, shown at / - const [page, site] = await Promise.all([getPage(slug), getSite()]); + const [page, site, pages, base] = await Promise.all([getPage(slug), getSite(), getPages(), baseUrl()]); if (!page) notFound(); - const ld = page.kind === 'article' - ? { '@context': 'https://schema.org', '@type': 'Article', headline: page.title, description: page.summary, dateModified: page.updatedAt, publisher: { '@type': 'Organization', name: site.name } } - : null; + const url = `${base}/${page.slug}`; + const isArticle = page.kind === 'article'; + const cat = page.category ? { name: page.category, url: `/guides/${categorySlug(page.category)}` } : null; + const org = { '@type': 'Organization', name: site.name, url: base + '/' }; + const ld: object[] = []; + if (isArticle) { + ld.push({ + '@context': 'https://schema.org', '@type': 'Article', headline: page.title, description: page.seoDescription || page.summary, + dateModified: page.updatedAt, ...(page.reviewedAt ? { datePublished: page.reviewedAt } : {}), + mainEntityOfPage: url, author: org, publisher: org, ...(cat ? { articleSection: cat.name } : {}), + ...(page.sources?.length ? { citation: page.sources.map((s) => s.url) } : {}), + }); + ld.push({ + '@context': 'https://schema.org', '@type': 'BreadcrumbList', itemListElement: [ + { '@type': 'ListItem', position: 1, name: site.name, item: base + '/' }, + { '@type': 'ListItem', position: 2, name: 'Resources', item: base + '/guides' }, + ...(cat ? [{ '@type': 'ListItem', position: 3, name: cat.name, item: base + cat.url }] : []), + { '@type': 'ListItem', position: cat ? 4 : 3, name: page.title, item: url }, + ], + }); + } + const faq = faqPairs(page); + if (faq.length >= 2) ld.push({ '@context': 'https://schema.org', '@type': 'FAQPage', mainEntity: faq.map((f) => ({ '@type': 'Question', name: f.q, acceptedAnswer: { '@type': 'Answer', text: f.a } })) }); + const related = isArticle ? relatedArticles(page, pages) : []; return (
- {ld ?