docs: make role of getQuartzComponents more clear and also make it optional
This commit is contained in:
		@@ -6,9 +6,6 @@ import { getAliasSlugs } from "../transformers/frontmatter"
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
export const AliasRedirects: QuartzEmitterPlugin = () => ({
 | 
					export const AliasRedirects: QuartzEmitterPlugin = () => ({
 | 
				
			||||||
  name: "AliasRedirects",
 | 
					  name: "AliasRedirects",
 | 
				
			||||||
  getQuartzComponents() {
 | 
					 | 
				
			||||||
    return []
 | 
					 | 
				
			||||||
  },
 | 
					 | 
				
			||||||
  async getDependencyGraph(ctx, content, _resources) {
 | 
					  async getDependencyGraph(ctx, content, _resources) {
 | 
				
			||||||
    const graph = new DepGraph<FilePath>()
 | 
					    const graph = new DepGraph<FilePath>()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -22,7 +19,6 @@ export const AliasRedirects: QuartzEmitterPlugin = () => ({
 | 
				
			|||||||
    return graph
 | 
					    return graph
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
  async emit(ctx, content, _resources): Promise<FilePath[]> {
 | 
					  async emit(ctx, content, _resources): Promise<FilePath[]> {
 | 
				
			||||||
    const { argv } = ctx
 | 
					 | 
				
			||||||
    const fps: FilePath[] = []
 | 
					    const fps: FilePath[] = []
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    for (const [_tree, file] of content) {
 | 
					    for (const [_tree, file] of content) {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -15,9 +15,6 @@ const filesToCopy = async (argv: Argv, cfg: QuartzConfig) => {
 | 
				
			|||||||
export const Assets: QuartzEmitterPlugin = () => {
 | 
					export const Assets: QuartzEmitterPlugin = () => {
 | 
				
			||||||
  return {
 | 
					  return {
 | 
				
			||||||
    name: "Assets",
 | 
					    name: "Assets",
 | 
				
			||||||
    getQuartzComponents() {
 | 
					 | 
				
			||||||
      return []
 | 
					 | 
				
			||||||
    },
 | 
					 | 
				
			||||||
    async getDependencyGraph(ctx, _content, _resources) {
 | 
					    async getDependencyGraph(ctx, _content, _resources) {
 | 
				
			||||||
      const { argv, cfg } = ctx
 | 
					      const { argv, cfg } = ctx
 | 
				
			||||||
      const graph = new DepGraph<FilePath>()
 | 
					      const graph = new DepGraph<FilePath>()
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -11,9 +11,6 @@ export function extractDomainFromBaseUrl(baseUrl: string) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
export const CNAME: QuartzEmitterPlugin = () => ({
 | 
					export const CNAME: QuartzEmitterPlugin = () => ({
 | 
				
			||||||
  name: "CNAME",
 | 
					  name: "CNAME",
 | 
				
			||||||
  getQuartzComponents() {
 | 
					 | 
				
			||||||
    return []
 | 
					 | 
				
			||||||
  },
 | 
					 | 
				
			||||||
  async getDependencyGraph(_ctx, _content, _resources) {
 | 
					  async getDependencyGraph(_ctx, _content, _resources) {
 | 
				
			||||||
    return new DepGraph<FilePath>()
 | 
					    return new DepGraph<FilePath>()
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -24,7 +24,7 @@ type ComponentResources = {
 | 
				
			|||||||
function getComponentResources(ctx: BuildCtx): ComponentResources {
 | 
					function getComponentResources(ctx: BuildCtx): ComponentResources {
 | 
				
			||||||
  const allComponents: Set<QuartzComponent> = new Set()
 | 
					  const allComponents: Set<QuartzComponent> = new Set()
 | 
				
			||||||
  for (const emitter of ctx.cfg.plugins.emitters) {
 | 
					  for (const emitter of ctx.cfg.plugins.emitters) {
 | 
				
			||||||
    const components = emitter.getQuartzComponents(ctx)
 | 
					    const components = emitter.getQuartzComponents?.(ctx) ?? []
 | 
				
			||||||
    for (const component of components) {
 | 
					    for (const component of components) {
 | 
				
			||||||
      allComponents.add(component)
 | 
					      allComponents.add(component)
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@@ -200,9 +200,6 @@ function addGlobalPageResources(ctx: BuildCtx, componentResources: ComponentReso
 | 
				
			|||||||
export const ComponentResources: QuartzEmitterPlugin = () => {
 | 
					export const ComponentResources: QuartzEmitterPlugin = () => {
 | 
				
			||||||
  return {
 | 
					  return {
 | 
				
			||||||
    name: "ComponentResources",
 | 
					    name: "ComponentResources",
 | 
				
			||||||
    getQuartzComponents() {
 | 
					 | 
				
			||||||
      return []
 | 
					 | 
				
			||||||
    },
 | 
					 | 
				
			||||||
    async getDependencyGraph(_ctx, _content, _resources) {
 | 
					    async getDependencyGraph(_ctx, _content, _resources) {
 | 
				
			||||||
      return new DepGraph<FilePath>()
 | 
					      return new DepGraph<FilePath>()
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -196,6 +196,5 @@ export const ContentIndex: QuartzEmitterPlugin<Partial<Options>> = (opts) => {
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
    getQuartzComponents: () => [],
 | 
					 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -6,9 +6,6 @@ import DepGraph from "../../depgraph"
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
export const Static: QuartzEmitterPlugin = () => ({
 | 
					export const Static: QuartzEmitterPlugin = () => ({
 | 
				
			||||||
  name: "Static",
 | 
					  name: "Static",
 | 
				
			||||||
  getQuartzComponents() {
 | 
					 | 
				
			||||||
    return []
 | 
					 | 
				
			||||||
  },
 | 
					 | 
				
			||||||
  async getDependencyGraph({ argv, cfg }, _content, _resources) {
 | 
					  async getDependencyGraph({ argv, cfg }, _content, _resources) {
 | 
				
			||||||
    const graph = new DepGraph<FilePath>()
 | 
					    const graph = new DepGraph<FilePath>()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -39,7 +39,12 @@ export type QuartzEmitterPlugin<Options extends OptionType = undefined> = (
 | 
				
			|||||||
export type QuartzEmitterPluginInstance = {
 | 
					export type QuartzEmitterPluginInstance = {
 | 
				
			||||||
  name: string
 | 
					  name: string
 | 
				
			||||||
  emit(ctx: BuildCtx, content: ProcessedContent[], resources: StaticResources): Promise<FilePath[]>
 | 
					  emit(ctx: BuildCtx, content: ProcessedContent[], resources: StaticResources): Promise<FilePath[]>
 | 
				
			||||||
  getQuartzComponents(ctx: BuildCtx): QuartzComponent[]
 | 
					  /**
 | 
				
			||||||
 | 
					   * Returns the components (if any) that are used in rendering the page.
 | 
				
			||||||
 | 
					   * This helps Quartz optimize the page by only including necessary resources
 | 
				
			||||||
 | 
					   * for components that are actually used.
 | 
				
			||||||
 | 
					   */
 | 
				
			||||||
 | 
					  getQuartzComponents?: (ctx: BuildCtx) => QuartzComponent[]
 | 
				
			||||||
  getDependencyGraph?(
 | 
					  getDependencyGraph?(
 | 
				
			||||||
    ctx: BuildCtx,
 | 
					    ctx: BuildCtx,
 | 
				
			||||||
    content: ProcessedContent[],
 | 
					    content: ProcessedContent[],
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user