finish path refactoring, add sourcemap + better trace support
This commit is contained in:
		@@ -1,4 +1,4 @@
 | 
			
		||||
import { CanonicalSlug, FilePath, ServerSlug, relativeToRoot } from "../../path"
 | 
			
		||||
import { CanonicalSlug, FilePath, ServerSlug, canonicalizeServer, resolveRelative } from "../../path"
 | 
			
		||||
import { QuartzEmitterPlugin } from "../types"
 | 
			
		||||
import path from 'path'
 | 
			
		||||
 | 
			
		||||
@@ -11,7 +11,7 @@ export const AliasRedirects: QuartzEmitterPlugin = () => ({
 | 
			
		||||
    const fps: FilePath[] = []
 | 
			
		||||
 | 
			
		||||
    for (const [_tree, file] of content) {
 | 
			
		||||
      const ogSlug = file.data.slug!
 | 
			
		||||
      const ogSlug = canonicalizeServer(file.data.slug!)
 | 
			
		||||
      const dir = path.relative(contentFolder, file.dirname ?? contentFolder)
 | 
			
		||||
 | 
			
		||||
      let aliases: CanonicalSlug[] = []
 | 
			
		||||
@@ -22,12 +22,10 @@ export const AliasRedirects: QuartzEmitterPlugin = () => ({
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      for (const alias of aliases) {
 | 
			
		||||
        const slug = (alias.startsWith("/")
 | 
			
		||||
          ? alias
 | 
			
		||||
          : path.posix.join(dir, alias)) as ServerSlug
 | 
			
		||||
        const slug = path.posix.join(dir, alias) as ServerSlug
 | 
			
		||||
 | 
			
		||||
        const fp = slug + ".html" as FilePath
 | 
			
		||||
        const redirUrl = relativeToRoot(slug, ogSlug)
 | 
			
		||||
        const redirUrl = resolveRelative(canonicalizeServer(slug), ogSlug)
 | 
			
		||||
        await emit({
 | 
			
		||||
          content: `
 | 
			
		||||
            <!DOCTYPE html>
 | 
			
		||||
 
 | 
			
		||||
@@ -1,5 +1,5 @@
 | 
			
		||||
import { GlobalConfiguration } from "../../cfg"
 | 
			
		||||
import { CanonicalSlug, ClientSlug } from "../../path"
 | 
			
		||||
import { CanonicalSlug, ClientSlug, FilePath, ServerSlug, canonicalizeServer } from "../../path"
 | 
			
		||||
import { QuartzEmitterPlugin } from "../types"
 | 
			
		||||
import path from "path"
 | 
			
		||||
 | 
			
		||||
@@ -65,10 +65,10 @@ export const ContentIndex: QuartzEmitterPlugin<Partial<Options>> = (opts) => {
 | 
			
		||||
  return {
 | 
			
		||||
    name: "ContentIndex",
 | 
			
		||||
    async emit(_contentDir, cfg, content, _resources, emit) {
 | 
			
		||||
      const emitted: string[] = []
 | 
			
		||||
      const emitted: FilePath[] = []
 | 
			
		||||
      const linkIndex: ContentIndex = new Map()
 | 
			
		||||
      for (const [_tree, file] of content) {
 | 
			
		||||
        const slug = file.data.slug!
 | 
			
		||||
        const slug = canonicalizeServer(file.data.slug!)
 | 
			
		||||
        const date = file.data.dates?.modified ?? new Date()
 | 
			
		||||
        if (opts?.includeEmptyFiles || (file.data.text && file.data.text !== "")) {
 | 
			
		||||
        linkIndex.set(slug, {
 | 
			
		||||
@@ -85,22 +85,22 @@ export const ContentIndex: QuartzEmitterPlugin<Partial<Options>> = (opts) => {
 | 
			
		||||
      if (opts?.enableSiteMap) {
 | 
			
		||||
        await emit({
 | 
			
		||||
          content: generateSiteMap(cfg, linkIndex),
 | 
			
		||||
          slug: "sitemap",
 | 
			
		||||
          slug: "sitemap" as ServerSlug,
 | 
			
		||||
          ext: ".xml"
 | 
			
		||||
        })
 | 
			
		||||
        emitted.push("sitemap.xml")
 | 
			
		||||
        emitted.push("sitemap.xml" as FilePath)
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      if (opts?.enableRSS) {
 | 
			
		||||
        await emit({
 | 
			
		||||
          content: generateRSSFeed(cfg, linkIndex),
 | 
			
		||||
          slug: "index",
 | 
			
		||||
          slug: "index" as ServerSlug,
 | 
			
		||||
          ext: ".xml"
 | 
			
		||||
        })
 | 
			
		||||
        emitted.push("index.xml")
 | 
			
		||||
        emitted.push("index.xml" as FilePath)
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      const fp = path.join("static", "contentIndex")
 | 
			
		||||
      const fp = path.join("static", "contentIndex") as ServerSlug
 | 
			
		||||
      const simplifiedIndex = Object.fromEntries(
 | 
			
		||||
        Array.from(linkIndex).map(([slug, content]) => {
 | 
			
		||||
          // remove description and from content index as nothing downstream
 | 
			
		||||
@@ -117,7 +117,7 @@ export const ContentIndex: QuartzEmitterPlugin<Partial<Options>> = (opts) => {
 | 
			
		||||
        slug: fp,
 | 
			
		||||
        ext: ".json",
 | 
			
		||||
      })
 | 
			
		||||
      emitted.push(`${fp}.json`)
 | 
			
		||||
      emitted.push(`${fp}.json` as FilePath)
 | 
			
		||||
 | 
			
		||||
      return emitted
 | 
			
		||||
    },
 | 
			
		||||
 
 | 
			
		||||
@@ -4,7 +4,7 @@ import HeaderConstructor from "../../components/Header"
 | 
			
		||||
import BodyConstructor from "../../components/Body"
 | 
			
		||||
import { pageResources, renderPage } from "../../components/renderPage"
 | 
			
		||||
import { FullPageLayout } from "../../cfg"
 | 
			
		||||
import { FilePath } from "../../path"
 | 
			
		||||
import { FilePath, canonicalizeServer } from "../../path"
 | 
			
		||||
 | 
			
		||||
export const ContentPage: QuartzEmitterPlugin<FullPageLayout> = (opts) => {
 | 
			
		||||
  if (!opts) {
 | 
			
		||||
@@ -24,7 +24,7 @@ export const ContentPage: QuartzEmitterPlugin<FullPageLayout> = (opts) => {
 | 
			
		||||
      const fps: FilePath[] = []
 | 
			
		||||
      const allFiles = content.map(c => c[1].data)
 | 
			
		||||
      for (const [tree, file] of content) {
 | 
			
		||||
        const slug = file.data.slug!
 | 
			
		||||
        const slug = canonicalizeServer(file.data.slug!)
 | 
			
		||||
        const externalResources = pageResources(slug, resources)
 | 
			
		||||
        const componentData: QuartzComponentProps = {
 | 
			
		||||
          fileData: file.data,
 | 
			
		||||
 
 | 
			
		||||
@@ -6,7 +6,7 @@ import { pageResources, renderPage } from "../../components/renderPage"
 | 
			
		||||
import { ProcessedContent, defaultProcessedContent } from "../vfile"
 | 
			
		||||
import { FullPageLayout } from "../../cfg"
 | 
			
		||||
import path from "path"
 | 
			
		||||
import { FilePath, toServerSlug } from "../../path"
 | 
			
		||||
import { CanonicalSlug, FilePath, ServerSlug, canonicalizeServer, joinSegments } from "../../path"
 | 
			
		||||
 | 
			
		||||
export const FolderPage: QuartzEmitterPlugin<FullPageLayout> = (opts) => {
 | 
			
		||||
  if (!opts) {
 | 
			
		||||
@@ -23,28 +23,34 @@ export const FolderPage: QuartzEmitterPlugin<FullPageLayout> = (opts) => {
 | 
			
		||||
      return [Head, Header, Body, ...header, ...beforeBody, Content, ...left, ...right, Footer]
 | 
			
		||||
    },
 | 
			
		||||
    async emit(_contentDir, cfg, content, resources, emit): Promise<FilePath[]> {
 | 
			
		||||
      const fps: string[] = []
 | 
			
		||||
      const fps: FilePath[] = []
 | 
			
		||||
      const allFiles = content.map(c => c[1].data)
 | 
			
		||||
 | 
			
		||||
      const folders: Set<string> = new Set(allFiles.flatMap(data => data.slug ? [path.dirname(data.slug)] : []))
 | 
			
		||||
      const folders: Set<CanonicalSlug> = new Set(allFiles.flatMap(data => {
 | 
			
		||||
        const slug = data.slug
 | 
			
		||||
        const folderName = path.dirname(slug ?? "") as CanonicalSlug
 | 
			
		||||
        if (slug && folderName !== ".") {
 | 
			
		||||
          return [folderName]
 | 
			
		||||
        }
 | 
			
		||||
        return []
 | 
			
		||||
      }))
 | 
			
		||||
 | 
			
		||||
      // remove special prefixes
 | 
			
		||||
      folders.delete(".")
 | 
			
		||||
      folders.delete("tags")
 | 
			
		||||
      folders.delete("tags" as CanonicalSlug)
 | 
			
		||||
 | 
			
		||||
      const folderDescriptions: Record<string, ProcessedContent> = Object.fromEntries([...folders].map(folder => ([
 | 
			
		||||
        folder, defaultProcessedContent({ slug: folder, frontmatter: { title: `Folder: ${folder}`, tags: [] } })
 | 
			
		||||
        folder, defaultProcessedContent({ slug: joinSegments(folder, "index") as ServerSlug, frontmatter: { title: `Folder: ${folder}`, tags: [] } })
 | 
			
		||||
      ])))
 | 
			
		||||
 | 
			
		||||
      for (const [tree, file] of content) {
 | 
			
		||||
        const slug = toServerSlug(file.data.slug!)
 | 
			
		||||
        const slug = canonicalizeServer(file.data.slug!)
 | 
			
		||||
        if (folders.has(slug)) {
 | 
			
		||||
          folderDescriptions[slug] = [tree, file]
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      for (const folder of folders) {
 | 
			
		||||
        const slug = folder 
 | 
			
		||||
        const slug = folder
 | 
			
		||||
        const externalResources = pageResources(slug, resources)
 | 
			
		||||
        const [tree, file] = folderDescriptions[folder]
 | 
			
		||||
        const componentData: QuartzComponentProps = {
 | 
			
		||||
@@ -63,7 +69,7 @@ export const FolderPage: QuartzEmitterPlugin<FullPageLayout> = (opts) => {
 | 
			
		||||
          externalResources
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
        const fp = file.data.slug + ".html"
 | 
			
		||||
        const fp = file.data.slug! + ".html" as FilePath
 | 
			
		||||
        await emit({
 | 
			
		||||
          content,
 | 
			
		||||
          slug: file.data.slug!,
 | 
			
		||||
 
 | 
			
		||||
@@ -5,7 +5,7 @@ import BodyConstructor from "../../components/Body"
 | 
			
		||||
import { pageResources, renderPage } from "../../components/renderPage"
 | 
			
		||||
import { ProcessedContent, defaultProcessedContent } from "../vfile"
 | 
			
		||||
import { FullPageLayout } from "../../cfg"
 | 
			
		||||
import { FilePath, ServerSlug, toServerSlug } from "../../path"
 | 
			
		||||
import { CanonicalSlug, FilePath, ServerSlug } from "../../path"
 | 
			
		||||
 | 
			
		||||
export const TagPage: QuartzEmitterPlugin<FullPageLayout> = (opts) => {
 | 
			
		||||
  if (!opts) {
 | 
			
		||||
@@ -31,7 +31,7 @@ export const TagPage: QuartzEmitterPlugin<FullPageLayout> = (opts) => {
 | 
			
		||||
      ])))
 | 
			
		||||
 | 
			
		||||
      for (const [tree, file] of content) {
 | 
			
		||||
        const slug = toServerSlug(file.data.slug!)
 | 
			
		||||
        const slug = file.data.slug!
 | 
			
		||||
        if (slug.startsWith("tags/")) {
 | 
			
		||||
          const tag = slug.slice("tags/".length)
 | 
			
		||||
          if (tags.has(tag)) {
 | 
			
		||||
@@ -41,7 +41,7 @@ export const TagPage: QuartzEmitterPlugin<FullPageLayout> = (opts) => {
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      for (const tag of tags) {
 | 
			
		||||
        const slug = `tags/${tag}`
 | 
			
		||||
        const slug = `tags/${tag}` as CanonicalSlug
 | 
			
		||||
        const externalResources = pageResources(slug, resources)
 | 
			
		||||
        const [tree, file] = tagDescriptions[tag]
 | 
			
		||||
        const componentData: QuartzComponentProps = {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user