From c84a9d180fa924ae2c8b257530be5e035c8b8d46 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Fri, 22 May 2026 15:50:42 +0100 Subject: [PATCH] Use shared auto index for blog --- site/quartz/components/GameCultBlogFolder.tsx | 73 -------------- .../components/GameCultCompositeContent.tsx | 13 ++- site/quartz/components/gamecult.ts | 94 ++----------------- 3 files changed, 19 insertions(+), 161 deletions(-) delete mode 100644 site/quartz/components/GameCultBlogFolder.tsx diff --git a/site/quartz/components/GameCultBlogFolder.tsx b/site/quartz/components/GameCultBlogFolder.tsx deleted file mode 100644 index cb2126b..0000000 --- a/site/quartz/components/GameCultBlogFolder.tsx +++ /dev/null @@ -1,73 +0,0 @@ -import { QuartzPluginData } from "../plugins/vfile" -import { Date } from "./Date" -import { QuartzComponent, QuartzComponentConstructor, QuartzComponentProps } from "./types" -import { resolveRelative } from "../util/path" -import { collectGameCultBlogPosts, getGameCultAuthorLabel } from "./gamecult" - -function getBlogCardDescription(page: QuartzPluginData) { - const frontmatterDescription = page.frontmatter?.description - if (typeof frontmatterDescription === "string" && frontmatterDescription.trim().length > 0) { - return frontmatterDescription.trim() - } - - const pageDescription = page.description - if (typeof pageDescription === "string" && pageDescription.trim().length > 0) { - return pageDescription.trim() - } - - const socialDeck = page.frontmatter?.socialDeck - if (typeof socialDeck === "string" && socialDeck.trim().length > 0) { - return socialDeck.trim() - } - - return "This post exists, which is already more than many ideas manage." -} - -export default (() => { - const GameCultBlogFolder: QuartzComponent = ({ cfg, fileData, allFiles }: QuartzComponentProps) => { - const posts = collectGameCultBlogPosts(allFiles) - const intro = fileData.description - - return ( -
- {intro && ( -
-

{intro}

-
- )} -
- {posts.map((post) => { - const title = post.frontmatter?.title ?? post.slug ?? "Untitled post" - const href = resolveRelative(fileData.slug!, post.slug!) - const author = getGameCultAuthorLabel(post) - const date = post.dates?.published ?? post.dates?.created ?? post.dates?.modified - - return ( - - ) - })} -
-
- ) - } - - return GameCultBlogFolder -}) satisfies QuartzComponentConstructor diff --git a/site/quartz/components/GameCultCompositeContent.tsx b/site/quartz/components/GameCultCompositeContent.tsx index fb6281d..541635b 100644 --- a/site/quartz/components/GameCultCompositeContent.tsx +++ b/site/quartz/components/GameCultCompositeContent.tsx @@ -13,7 +13,7 @@ import { } from "../util/path" import { QuartzComponent, QuartzComponentConstructor, QuartzComponentProps } from "./types" import FolderContent from "./pages/FolderContent" -import GameCultBlogFolder from "./GameCultBlogFolder" +import AutoIndexFolder from "./AutoIndexFolder" import { resolveGameCultReferenceSlug, resolveGameCultSourceFile, stripTopTagline } from "./gamecult" interface Options { @@ -170,7 +170,16 @@ function getCompositeSections( export default ((opts?: Partial) => { const options: Options = { ...defaultOptions, ...opts } const DefaultFolderContent = FolderContent() - const BlogFolderContent = GameCultBlogFolder() + const BlogFolderContent = AutoIndexFolder({ + rootSlug: "Blog", + classPrefix: "gamecult-blog", + hideFrontmatterKey: "hideFromBlogIndex", + defaultAuthor: "GameCult", + emptyDescription: "This post exists, which is already more than many ideas manage.", + showDescriptionIntro: true, + sidebarTagline: "Recent notes, fiction, experiments, and other escaped materials.", + sidebarSummary: (count) => `${count} public posts, newest trouble first.`, + }) const GameCultCompositeContent: QuartzComponent = (props: QuartzComponentProps) => { const { fileData, tree, allFiles } = props diff --git a/site/quartz/components/gamecult.ts b/site/quartz/components/gamecult.ts index 080187b..d3a8746 100644 --- a/site/quartz/components/gamecult.ts +++ b/site/quartz/components/gamecult.ts @@ -3,6 +3,7 @@ import { toString } from "hast-util-to-string" import { QuartzPluginData } from "../plugins/vfile" import { FullSlug, simplifySlug, splitAnchor, stripSlashes } from "../util/path" import { clone } from "../util/clone" +import { buildAutoIndexSidebarData } from "./AutoIndexFolder" export type GameCultSidebarLink = { label: string @@ -29,10 +30,6 @@ export type GameCultPageContext = { sidebar?: GameCultSidebarData } -type GameCultBlogPost = QuartzPluginData & { - slug: FullSlug -} - type FrontmatterSidebarLink = { label?: unknown slug?: unknown @@ -410,87 +407,6 @@ function extractFrontmatterOverviewGroups(file: QuartzPluginData): GameCultSideb return groups.length > 0 ? groups : undefined } -function blogDateValue(file: QuartzPluginData) { - return file.dates?.published ?? file.dates?.created ?? file.dates?.modified -} - -export function getGameCultAuthorLabel(file: QuartzPluginData) { - const author = file.frontmatter?.author - if (typeof author === "string" && author.trim().length > 0) { - return author.trim() - } - - const authors = file.frontmatter?.authors - if (Array.isArray(authors)) { - const names = authors - .filter((entry): entry is string => typeof entry === "string" && entry.trim().length > 0) - .map((entry) => entry.trim()) - - if (names.length > 0) { - return names.join(", ") - } - } - - return "GameCult" -} - -export function collectGameCultBlogPosts(allFiles: QuartzPluginData[]): GameCultBlogPost[] { - return allFiles - .filter( - (file): file is GameCultBlogPost => - typeof file.slug === "string" && - file.slug.startsWith("Blog/") && - file.slug !== "Blog/index" && - file.frontmatter?.hideFromBlogIndex !== true && - !!file.frontmatter?.title, - ) - .sort((a, b) => { - const aDate = blogDateValue(a) - const bDate = blogDateValue(b) - - if (aDate && bDate) { - return bDate.getTime() - aDate.getTime() - } - - if (aDate && !bDate) { - return -1 - } - - if (!aDate && bDate) { - return 1 - } - - return (a.frontmatter?.title ?? "").localeCompare(b.frontmatter?.title ?? "") - }) -} - -function buildBlogSidebarData(file: QuartzPluginData, allFiles: QuartzPluginData[]): GameCultSidebarData { - const posts = collectGameCultBlogPosts(allFiles) - const groupsByYear = new Map() - - for (const post of posts) { - const date = blogDateValue(post) - const year = date ? date.getUTCFullYear().toString() : "Undated" - const existing = groupsByYear.get(year) ?? [] - existing.push({ - label: post.frontmatter?.title ?? post.slug, - slug: post.slug, - }) - groupsByYear.set(year, existing) - } - - return { - title: file.frontmatter?.title ?? "Blog", - slug: file.slug as FullSlug, - tagline: "Recent notes, fiction, experiments, and other escaped materials.", - summary: `${posts.length} public posts, newest trouble first.`, - groups: [...groupsByYear.entries()].map(([title, links]) => ({ - title, - links, - })), - } -} - function overviewCandidates(currentSlug: FullSlug, includeCurrent = true) { if (currentSlug === "index") { return includeCurrent ? (["index"] as FullSlug[]) : [] @@ -575,7 +491,13 @@ export function buildGameCultPageContext( const overviewNote = findSidebarOverviewNote(currentFile.slug, allFiles) const sidebar = overviewNote ? overviewNote.slug === ("Blog/index" as FullSlug) - ? buildBlogSidebarData(overviewNote, allFiles) + ? buildAutoIndexSidebarData(overviewNote, allFiles, { + rootSlug: "Blog", + hideFrontmatterKey: "hideFromBlogIndex", + defaultAuthor: "GameCult", + sidebarTagline: "Recent notes, fiction, experiments, and other escaped materials.", + sidebarSummary: (count) => `${count} public posts, newest trouble first.`, + }) : extractOverviewData(overviewNote) : undefined