From 2bfe90b7e64839d8ec6319fe93b76472b0285114 Mon Sep 17 00:00:00 2001 From: Jacky Zhao Date: Sun, 11 Jun 2023 23:46:38 -0700 Subject: [PATCH] add config to components --- quartz.config.ts | 6 +++--- quartz/components/ArticleTitle.tsx | 6 ++++-- quartz/components/Body.tsx | 7 +++++-- quartz/components/Content.tsx | 6 ++++-- quartz/components/Darkmode.tsx | 5 ++++- quartz/components/Head.tsx | 8 +++++--- quartz/components/Header.tsx | 6 ++++-- quartz/components/PageTitle.tsx | 6 ++++-- quartz/components/ReadingTime.tsx | 6 ++++-- quartz/components/Spacer.tsx | 6 +++++- quartz/components/TableOfContents.tsx | 6 ++++-- quartz/components/types.ts | 2 +- quartz/plugins/emitters/contentPage.tsx | 9 ++++++--- 13 files changed, 53 insertions(+), 26 deletions(-) diff --git a/quartz.config.ts b/quartz.config.ts index ab7e990..d1fe184 100644 --- a/quartz.config.ts +++ b/quartz.config.ts @@ -56,9 +56,9 @@ const config: QuartzConfig = { ], emitters: [ Plugin.ContentPage({ - head: Component.Head, - header: [Component.PageTitle, Component.Spacer, Component.Darkmode], - body: [Component.ArticleTitle, Component.ReadingTime, Component.TableOfContents, Component.Content] + head: Component.Head(), + header: [Component.PageTitle(), Component.Spacer(), Component.Darkmode()], + body: [Component.ArticleTitle(), Component.ReadingTime(), Component.TableOfContents(), Component.Content()] }) ] }, diff --git a/quartz/components/ArticleTitle.tsx b/quartz/components/ArticleTitle.tsx index 02725c6..37950c4 100644 --- a/quartz/components/ArticleTitle.tsx +++ b/quartz/components/ArticleTitle.tsx @@ -1,6 +1,6 @@ -import { QuartzComponentProps } from "./types" +import { QuartzComponentConstructor, QuartzComponentProps } from "./types" -export default function ArticleTitle({ fileData }: QuartzComponentProps) { +function ArticleTitle({ fileData }: QuartzComponentProps) { const title = fileData.frontmatter?.title const displayTitle = fileData.slug === "index" ? undefined : title if (displayTitle) { @@ -9,3 +9,5 @@ export default function ArticleTitle({ fileData }: QuartzComponentProps) { return null } } + +export default (() => ArticleTitle) satisfies QuartzComponentConstructor diff --git a/quartz/components/Body.tsx b/quartz/components/Body.tsx index b8ad34b..0130828 100644 --- a/quartz/components/Body.tsx +++ b/quartz/components/Body.tsx @@ -1,8 +1,8 @@ import clipboardScript from './scripts/clipboard.inline' import clipboardStyle from './styles/clipboard.scss' -import { QuartzComponentProps } from "./types" +import { QuartzComponentConstructor, QuartzComponentProps } from "./types" -export default function Body({ children }: QuartzComponentProps) { +function Body({ children }: QuartzComponentProps) { return
{children}
@@ -10,3 +10,6 @@ export default function Body({ children }: QuartzComponentProps) { Body.afterDOMLoaded = clipboardScript Body.css = clipboardStyle + +export default (() => Body) satisfies QuartzComponentConstructor + diff --git a/quartz/components/Content.tsx b/quartz/components/Content.tsx index c010f2a..71d0f35 100644 --- a/quartz/components/Content.tsx +++ b/quartz/components/Content.tsx @@ -1,9 +1,11 @@ -import { QuartzComponentProps } from "./types" +import { QuartzComponentConstructor, QuartzComponentProps } from "./types" import { Fragment, jsx, jsxs } from 'preact/jsx-runtime' import { toJsxRuntime } from "hast-util-to-jsx-runtime" -export default function Content({ tree }: QuartzComponentProps) { +function Content({ tree }: QuartzComponentProps) { // @ts-ignore (preact makes it angry) const content = toJsxRuntime(tree, { Fragment, jsx, jsxs, elementAttributeNameCase: 'html' }) return content } + +export default (() => Content) satisfies QuartzComponentConstructor diff --git a/quartz/components/Darkmode.tsx b/quartz/components/Darkmode.tsx index 2170253..49f61c7 100644 --- a/quartz/components/Darkmode.tsx +++ b/quartz/components/Darkmode.tsx @@ -3,8 +3,9 @@ // see: https://v8.dev/features/modules#defer import darkmodeScript from "./scripts/darkmode.inline" import styles from './styles/darkmode.scss' +import { QuartzComponentConstructor } from "./types" -export default function Darkmode() { +function Darkmode() { return