fix indexing causing main thread freeze, various polish
This commit is contained in:
		@@ -15,11 +15,13 @@ export type ContentDetails = {
 | 
			
		||||
interface Options {
 | 
			
		||||
  enableSiteMap: boolean
 | 
			
		||||
  enableRSS: boolean
 | 
			
		||||
  includeEmptyFiles: boolean
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
const defaultOptions: Options = {
 | 
			
		||||
  enableSiteMap: true,
 | 
			
		||||
  enableRSS: true,
 | 
			
		||||
  includeEmptyFiles: false,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function generateSiteMap(cfg: GlobalConfiguration, idx: ContentIndex): string {
 | 
			
		||||
@@ -57,7 +59,7 @@ function generateRSSFeed(cfg: GlobalConfiguration, idx: ContentIndex): string {
 | 
			
		||||
  </rss>`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export const ContentIndex: QuartzEmitterPlugin<Options> = (opts) => {
 | 
			
		||||
export const ContentIndex: QuartzEmitterPlugin<Partial<Options>> = (opts) => {
 | 
			
		||||
  opts = { ...defaultOptions, ...opts }
 | 
			
		||||
  return {
 | 
			
		||||
    name: "ContentIndex",
 | 
			
		||||
@@ -67,6 +69,7 @@ export const ContentIndex: QuartzEmitterPlugin<Options> = (opts) => {
 | 
			
		||||
      for (const [_tree, file] of content) {
 | 
			
		||||
        const slug = file.data.slug!
 | 
			
		||||
        const date = file.data.dates?.modified ?? new Date()
 | 
			
		||||
        if (opts?.includeEmptyFiles || (file.data.text && file.data.text !== "")) {
 | 
			
		||||
        linkIndex.set(slug, {
 | 
			
		||||
          title: file.data.frontmatter?.title!,
 | 
			
		||||
          links: file.data.links ?? [],
 | 
			
		||||
@@ -75,6 +78,7 @@ export const ContentIndex: QuartzEmitterPlugin<Options> = (opts) => {
 | 
			
		||||
          date: date,
 | 
			
		||||
          description: file.data.description ?? ""
 | 
			
		||||
        })
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      if (opts?.enableSiteMap) {
 | 
			
		||||
@@ -106,6 +110,7 @@ export const ContentIndex: QuartzEmitterPlugin<Options> = (opts) => {
 | 
			
		||||
          return [slug, content]
 | 
			
		||||
        })
 | 
			
		||||
      )
 | 
			
		||||
 | 
			
		||||
      await emit({
 | 
			
		||||
        content: JSON.stringify(simplifiedIndex),
 | 
			
		||||
        slug: fp,
 | 
			
		||||
 
 | 
			
		||||
@@ -6,6 +6,7 @@ import { pageResources, renderPage } from "../../components/renderPage"
 | 
			
		||||
import { ProcessedContent, defaultProcessedContent } from "../vfile"
 | 
			
		||||
import { FullPageLayout } from "../../cfg"
 | 
			
		||||
import path from "path"
 | 
			
		||||
import { clientSideSlug } from "../../path"
 | 
			
		||||
 | 
			
		||||
export const FolderPage: QuartzEmitterPlugin<FullPageLayout> = (opts) => {
 | 
			
		||||
  if (!opts) {
 | 
			
		||||
@@ -36,7 +37,7 @@ export const FolderPage: QuartzEmitterPlugin<FullPageLayout> = (opts) => {
 | 
			
		||||
      ])))
 | 
			
		||||
 | 
			
		||||
      for (const [tree, file] of content) {
 | 
			
		||||
        const slug = file.data.slug!
 | 
			
		||||
        const slug = clientSideSlug(file.data.slug!)
 | 
			
		||||
        if (folders.has(slug)) {
 | 
			
		||||
          folderDescriptions[slug] = [tree, file]
 | 
			
		||||
        }
 | 
			
		||||
 
 | 
			
		||||
@@ -5,6 +5,7 @@ import BodyConstructor from "../../components/Body"
 | 
			
		||||
import { pageResources, renderPage } from "../../components/renderPage"
 | 
			
		||||
import { ProcessedContent, defaultProcessedContent } from "../vfile"
 | 
			
		||||
import { FullPageLayout } from "../../cfg"
 | 
			
		||||
import { clientSideSlug } from "../../path"
 | 
			
		||||
 | 
			
		||||
export const TagPage: QuartzEmitterPlugin<FullPageLayout> = (opts) => {
 | 
			
		||||
  if (!opts) {
 | 
			
		||||
@@ -30,7 +31,7 @@ export const TagPage: QuartzEmitterPlugin<FullPageLayout> = (opts) => {
 | 
			
		||||
      ])))
 | 
			
		||||
 | 
			
		||||
      for (const [tree, file] of content) {
 | 
			
		||||
        const slug = file.data.slug!
 | 
			
		||||
        const slug = clientSideSlug(file.data.slug!)
 | 
			
		||||
        if (slug.startsWith("tags/")) {
 | 
			
		||||
          const tag = slug.slice("tags/".length)
 | 
			
		||||
          if (tags.has(tag)) {
 | 
			
		||||
 
 | 
			
		||||
@@ -20,26 +20,30 @@ export function getComponentResources(plugins: PluginTypes): ComponentResources
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  const componentResources: ComponentResources = {
 | 
			
		||||
    css: [],
 | 
			
		||||
    beforeDOMLoaded: [],
 | 
			
		||||
    afterDOMLoaded: []
 | 
			
		||||
  const componentResources = {
 | 
			
		||||
    css: new Set<string>(),
 | 
			
		||||
    beforeDOMLoaded: new Set<string>(),
 | 
			
		||||
    afterDOMLoaded: new Set<string>()
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  for (const component of allComponents) {
 | 
			
		||||
    const { css, beforeDOMLoaded, afterDOMLoaded } = component
 | 
			
		||||
    if (css) {
 | 
			
		||||
      componentResources.css.push(css)
 | 
			
		||||
      componentResources.css.add(css)
 | 
			
		||||
    }
 | 
			
		||||
    if (beforeDOMLoaded) {
 | 
			
		||||
      componentResources.beforeDOMLoaded.push(beforeDOMLoaded)
 | 
			
		||||
      componentResources.beforeDOMLoaded.add(beforeDOMLoaded)
 | 
			
		||||
    }
 | 
			
		||||
    if (afterDOMLoaded) {
 | 
			
		||||
      componentResources.afterDOMLoaded.push(afterDOMLoaded)
 | 
			
		||||
      componentResources.afterDOMLoaded.add(afterDOMLoaded)
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  return componentResources
 | 
			
		||||
  
 | 
			
		||||
  return {
 | 
			
		||||
    css: [...componentResources.css],
 | 
			
		||||
    beforeDOMLoaded: [...componentResources.beforeDOMLoaded],
 | 
			
		||||
    afterDOMLoaded: [...componentResources.afterDOMLoaded]
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function joinScripts(scripts: string[]): string {
 | 
			
		||||
@@ -78,10 +82,10 @@ export function getStaticResourcesFromPlugins(plugins: PluginTypes) {
 | 
			
		||||
  for (const transformer of plugins.transformers) {
 | 
			
		||||
    const res = transformer.externalResources ? transformer.externalResources() : {}
 | 
			
		||||
    if (res?.js) {
 | 
			
		||||
      staticResources.js = staticResources.js.concat(res.js)
 | 
			
		||||
      staticResources.js.push(...res.js)
 | 
			
		||||
    }
 | 
			
		||||
    if (res?.css) {
 | 
			
		||||
      staticResources.css = staticResources.css.concat(res.css)
 | 
			
		||||
      staticResources.css.push(...res.css)
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user