various polish
This commit is contained in:
		@@ -36,7 +36,6 @@ function generateRSSFeed(cfg: GlobalConfiguration, idx: ContentIndex): string {
 | 
			
		||||
  const base = cfg.canonicalUrl ?? ""
 | 
			
		||||
  const root = `https://${base}`
 | 
			
		||||
 | 
			
		||||
  // TODO: ogimage
 | 
			
		||||
  const createURLEntry = (slug: string, content: ContentDetails): string => `<items>
 | 
			
		||||
    <title>${content.title}</title>
 | 
			
		||||
    <link>${root}/${slug}</link>
 | 
			
		||||
 
 | 
			
		||||
@@ -1,29 +1,17 @@
 | 
			
		||||
import { GlobalConfiguration } from '../cfg'
 | 
			
		||||
import { QuartzComponent } from '../components/types'
 | 
			
		||||
import { StaticResources } from '../resources'
 | 
			
		||||
import { googleFontHref, joinStyles } from '../theme'
 | 
			
		||||
import { joinStyles } from '../theme'
 | 
			
		||||
import { EmitCallback, PluginTypes } from './types'
 | 
			
		||||
import styles from '../styles/base.scss'
 | 
			
		||||
 | 
			
		||||
// @ts-ignore
 | 
			
		||||
import spaRouterScript from '../components/scripts/spa.inline'
 | 
			
		||||
// @ts-ignore
 | 
			
		||||
import popoverScript from '../components/scripts/popover.inline'
 | 
			
		||||
import popoverStyle from '../components/styles/popover.scss'
 | 
			
		||||
 | 
			
		||||
export type ComponentResources = {
 | 
			
		||||
  css: string[],
 | 
			
		||||
  beforeDOMLoaded: string[],
 | 
			
		||||
  afterDOMLoaded: string[]
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function joinScripts(scripts: string[]): string {
 | 
			
		||||
  // wrap with iife to prevent scope collision
 | 
			
		||||
  return scripts.map(script => `(function () {${script}})();`).join("\n")
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export function emitComponentResources(cfg: GlobalConfiguration, resources: StaticResources, plugins: PluginTypes, emit: EmitCallback) {
 | 
			
		||||
  const fps: string[] = []
 | 
			
		||||
export function getComponentResources(plugins: PluginTypes): ComponentResources {
 | 
			
		||||
  const allComponents: Set<QuartzComponent> = new Set()
 | 
			
		||||
  for (const emitter of plugins.emitters) {
 | 
			
		||||
    const components = emitter.getQuartzComponents()
 | 
			
		||||
@@ -50,41 +38,35 @@ export function emitComponentResources(cfg: GlobalConfiguration, resources: Stat
 | 
			
		||||
      componentResources.afterDOMLoaded.push(afterDOMLoaded)
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
  
 | 
			
		||||
  if (cfg.enablePopovers) {
 | 
			
		||||
    componentResources.afterDOMLoaded.push(popoverScript)
 | 
			
		||||
    componentResources.css.push(popoverStyle)
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  if (cfg.enableSPA) {
 | 
			
		||||
    componentResources.afterDOMLoaded.push(spaRouterScript)
 | 
			
		||||
  } else {
 | 
			
		||||
    componentResources.afterDOMLoaded.push(`
 | 
			
		||||
      window.spaNavigate = (url, _) => window.location.assign(url)
 | 
			
		||||
      const event = new CustomEvent("nav", { detail: { slug: document.body.dataset.slug } })
 | 
			
		||||
      document.dispatchEvent(event)`
 | 
			
		||||
    )
 | 
			
		||||
  }
 | 
			
		||||
  return componentResources
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
  emit({
 | 
			
		||||
    slug: "index",
 | 
			
		||||
    ext: ".css",
 | 
			
		||||
    content: joinStyles(cfg.theme, styles, ...componentResources.css)
 | 
			
		||||
  })
 | 
			
		||||
  emit({
 | 
			
		||||
    slug: "prescript",
 | 
			
		||||
    ext: ".js",
 | 
			
		||||
    content: joinScripts(componentResources.beforeDOMLoaded)
 | 
			
		||||
  })
 | 
			
		||||
  emit({
 | 
			
		||||
    slug: "postscript",
 | 
			
		||||
    ext: ".js",
 | 
			
		||||
    content: joinScripts(componentResources.afterDOMLoaded)
 | 
			
		||||
  })
 | 
			
		||||
function joinScripts(scripts: string[]): string {
 | 
			
		||||
  // wrap with iife to prevent scope collision
 | 
			
		||||
  return scripts.map(script => `(function () {${script}})();`).join("\n")
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
  fps.push("index.css", "prescript.js", "postscript.js")
 | 
			
		||||
  resources.css.push(googleFontHref(cfg.theme))
 | 
			
		||||
export async function emitComponentResources(cfg: GlobalConfiguration, res: ComponentResources, emit: EmitCallback): Promise<string[]> {
 | 
			
		||||
  const fps = await Promise.all([
 | 
			
		||||
    emit({
 | 
			
		||||
      slug: "index",
 | 
			
		||||
      ext: ".css",
 | 
			
		||||
      content: joinStyles(cfg.theme, styles, ...res.css)
 | 
			
		||||
    }),
 | 
			
		||||
    emit({
 | 
			
		||||
      slug: "prescript",
 | 
			
		||||
      ext: ".js",
 | 
			
		||||
      content: joinScripts(res.beforeDOMLoaded)
 | 
			
		||||
    }),
 | 
			
		||||
    emit({
 | 
			
		||||
      slug: "postscript",
 | 
			
		||||
      ext: ".js",
 | 
			
		||||
      content: joinScripts(res.afterDOMLoaded)
 | 
			
		||||
    })
 | 
			
		||||
  ])
 | 
			
		||||
  return fps
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export function getStaticResourcesFromPlugins(plugins: PluginTypes) {
 | 
			
		||||
 
 | 
			
		||||
@@ -1,4 +1,3 @@
 | 
			
		||||
import { PluggableList } from "unified"
 | 
			
		||||
import remarkGfm from "remark-gfm"
 | 
			
		||||
import smartypants from 'remark-smartypants'
 | 
			
		||||
import { QuartzTransformerPlugin } from "../types"
 | 
			
		||||
@@ -20,14 +19,14 @@ export const GitHubFlavoredMarkdown: QuartzTransformerPlugin<Partial<Options> |
 | 
			
		||||
  return {
 | 
			
		||||
    name: "GitHubFlavoredMarkdown",
 | 
			
		||||
    markdownPlugins() {
 | 
			
		||||
      return opts.enableSmartyPants ? [remarkGfm] : [remarkGfm, smartypants]
 | 
			
		||||
      return opts.enableSmartyPants ? [remarkGfm, smartypants] : [remarkGfm]
 | 
			
		||||
    },
 | 
			
		||||
    htmlPlugins() {
 | 
			
		||||
      if (opts.linkHeadings) {
 | 
			
		||||
        return [rehypeSlug, [rehypeAutolinkHeadings, {
 | 
			
		||||
          behavior: 'append', content: {
 | 
			
		||||
            type: 'text',
 | 
			
		||||
            value: ' §'
 | 
			
		||||
            value: ' §',
 | 
			
		||||
          }
 | 
			
		||||
        }]]
 | 
			
		||||
      } else {
 | 
			
		||||
 
 | 
			
		||||
@@ -1,5 +1,5 @@
 | 
			
		||||
import { QuartzTransformerPlugin } from "../types"
 | 
			
		||||
import { relativeToRoot, slugify, trimPathSuffix } from "../../path"
 | 
			
		||||
import { clientSideSlug, relativeToRoot, slugify, trimPathSuffix } from "../../path"
 | 
			
		||||
import path from "path"
 | 
			
		||||
import { visit } from 'unist-util-visit'
 | 
			
		||||
import isAbsoluteUrl from "is-absolute-url"
 | 
			
		||||
@@ -27,7 +27,7 @@ export const CrawlLinks: QuartzTransformerPlugin<Partial<Options> | undefined> =
 | 
			
		||||
    htmlPlugins() {
 | 
			
		||||
      return [() => {
 | 
			
		||||
        return (tree, file) => {
 | 
			
		||||
          const curSlug = file.data.slug!
 | 
			
		||||
          const curSlug = clientSideSlug(file.data.slug!)
 | 
			
		||||
          const transformLink = (target: string) => {
 | 
			
		||||
            const targetSlug = slugify(decodeURI(target).trim())
 | 
			
		||||
            if (opts.markdownLinkResolution === 'relative' && !path.isAbsolute(targetSlug)) {
 | 
			
		||||
@@ -49,7 +49,6 @@ export const CrawlLinks: QuartzTransformerPlugin<Partial<Options> | undefined> =
 | 
			
		||||
              let dest = node.properties.href
 | 
			
		||||
              node.properties.className = isAbsoluteUrl(dest) ? "external" : "internal"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
              // don't process external links or intra-document anchors
 | 
			
		||||
              if (!(isAbsoluteUrl(dest) || dest.startsWith("#"))) {
 | 
			
		||||
                node.properties.href = transformLink(dest)
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user