diff --git a/apps/site/src/components/ArticleNotes.astro b/apps/site/src/components/ArticleNotes.astro new file mode 100644 index 00000000..ad1690ec --- /dev/null +++ b/apps/site/src/components/ArticleNotes.astro @@ -0,0 +1,58 @@ +--- +import { Icon } from "astro-icon/components"; +import { stripHtml } from "~/lib/format"; +import type { ArticleNote } from "~/lib/journal-article"; +import { decodeEntities } from "~/lib/sources/journal"; + +/* + * The take-home message and purpose of an empirical article: about the + * article rather than part of it, so they sit beside the text. A long note + * shows its first lines and opens on click. + */ + +interface Props { + notes: ArticleNote[]; + /** Leave out the ids in the notes' HTML, for a second copy on the same page */ + copy?: boolean; + class?: string; +} + +const { notes, copy = false, class: className } = Astro.props; + +/** Notes longer than this many words start closed */ +const OPEN_UP_TO = 70; +const PREVIEW_WORDS = 28; + +const preview = (note: ArticleNote) => `${decodeEntities(stripHtml(note.html)).split(" ").slice(0, PREVIEW_WORDS).join(" ")}…`; +const html = (note: ArticleNote) => (copy ? note.html.replace(/\sid="[^"]*"/g, "") : note.html); +const text = "journal-body prose prose-sm max-w-none [--tw-prose-body:var(--color-ink)] prose-p:my-2 first:prose-p:mt-0 last:prose-p:mb-0"; +const title = "font-heading text-sm font-bold tracking-wide text-journal uppercase"; +--- + +{ + notes.length > 0 && ( +