refactor: unify QuartzComponent type to structural interface (Phase C)

- Changed QuartzComponent from ComponentType<QuartzComponentProps> to callable type ((props: QuartzComponentProps) => any)
- Added optional displayName property for better debugging
- Removed ComponentType import from preact
- Removed all 13 'as QuartzComponent' type casts from quartz.layout.ts
- Community plugin components now directly assignable without casts
This commit is contained in:
saberzero1 2026-02-13 18:26:19 +01:00
parent e6d3695657
commit f8a682ab45
No known key found for this signature in database
2 changed files with 17 additions and 17 deletions

View File

@ -1,21 +1,20 @@
import { PageLayout, SharedLayout } from "./quartz/cfg" import { PageLayout, SharedLayout } from "./quartz/cfg"
import * as Component from "./quartz/components" import * as Component from "./quartz/components"
import { QuartzComponent } from "./quartz/components/types"
import * as Plugin from "./.quartz/plugins" import * as Plugin from "./.quartz/plugins"
// Create plugin components once and reuse across layouts // Create plugin components once and reuse across layouts
const explorerComponent = Plugin.Explorer() as QuartzComponent const explorerComponent = Plugin.Explorer()
const graphComponent = Plugin.Graph() as QuartzComponent const graphComponent = Plugin.Graph()
const searchComponent = Plugin.Search() as QuartzComponent const searchComponent = Plugin.Search()
const backlinksComponent = Plugin.Backlinks() as QuartzComponent const backlinksComponent = Plugin.Backlinks()
const tocComponent = Plugin.TableOfContents() as QuartzComponent const tocComponent = Plugin.TableOfContents()
const articleTitleComponent = Plugin.ArticleTitle() as QuartzComponent const articleTitleComponent = Plugin.ArticleTitle()
const contentMetaComponent = Plugin.ContentMeta() as QuartzComponent const contentMetaComponent = Plugin.ContentMeta()
const tagListComponent = Plugin.TagList() as QuartzComponent const tagListComponent = Plugin.TagList()
const pageTitleComponent = Plugin.PageTitle() as QuartzComponent const pageTitleComponent = Plugin.PageTitle()
const darkmodeComponent = Plugin.Darkmode() as QuartzComponent const darkmodeComponent = Plugin.Darkmode()
const readerModeComponent = Plugin.ReaderMode() as QuartzComponent const readerModeComponent = Plugin.ReaderMode()
const breadcrumbsComponent = Plugin.Breadcrumbs() as QuartzComponent const breadcrumbsComponent = Plugin.Breadcrumbs()
// components shared across all pages // components shared across all pages
export const sharedPageComponents: SharedLayout = { export const sharedPageComponents: SharedLayout = {
@ -24,14 +23,14 @@ export const sharedPageComponents: SharedLayout = {
afterBody: [ afterBody: [
// Plugin.Comments({ // Plugin.Comments({
// provider: "giscus", // provider: "giscus",
// options: {}) as QuartzComponent, // options: {}}),
], ],
footer: Plugin.Footer({ footer: Plugin.Footer({
links: { links: {
GitHub: "https://github.com/jackyzha0/quartz", GitHub: "https://github.com/jackyzha0/quartz",
"Discord Community": "https://discord.gg/cRFFHYye7t", "Discord Community": "https://discord.gg/cRFFHYye7t",
}, },
}) as QuartzComponent, }),
} }
// components for pages that display a single page (e.g. a single note) // components for pages that display a single page (e.g. a single note)

View File

@ -1,4 +1,4 @@
import { ComponentType, JSX } from "preact" import { JSX } from "preact"
import { StaticResources, StringResource } from "../util/resources" import { StaticResources, StringResource } from "../util/resources"
import { QuartzPluginData } from "../plugins/vfile" import { QuartzPluginData } from "../plugins/vfile"
import { GlobalConfiguration } from "../cfg" import { GlobalConfiguration } from "../cfg"
@ -18,7 +18,8 @@ export type QuartzComponentProps = {
[key: string]: any [key: string]: any
} }
export type QuartzComponent = ComponentType<QuartzComponentProps> & { export type QuartzComponent = ((props: QuartzComponentProps) => any) & {
displayName?: string
css?: StringResource css?: StringResource
beforeDOMLoaded?: StringResource beforeDOMLoaded?: StringResource
afterDOMLoaded?: StringResource afterDOMLoaded?: StringResource