|
| 1 | +import { QuartzEmitterPlugin } from "../types" |
| 2 | +import { QuartzComponentProps } from "../../components/types" |
| 3 | +import HeaderConstructor from "../../components/Header" |
| 4 | +import BodyConstructor from "../../components/Body" |
| 5 | +import { pageResources, renderPage } from "../../components/renderPage" |
| 6 | +import { QuartzPluginData, defaultProcessedContent } from "../vfile" |
| 7 | +import { FullPageLayout } from "../../cfg" |
| 8 | +import { |
| 9 | + FilePath, |
| 10 | + FullSlug, |
| 11 | + pathToRoot, |
| 12 | +} from "../../util/path" |
| 13 | +import { |
| 14 | + defaultContentPageLayout, |
| 15 | + sharedPageComponents, |
| 16 | +} from "../../../quartz.layout" |
| 17 | +import { write } from "./helpers" |
| 18 | +import DepGraph from "../../depgraph" |
| 19 | +import Blogs from "../../components/pages/Blogs" |
| 20 | + |
| 21 | +interface ExplorerWithTocPageOptions extends FullPageLayout { |
| 22 | + sort?: (f1: QuartzPluginData, f2: QuartzPluginData) => number |
| 23 | +} |
| 24 | + |
| 25 | +export const ExplorerWithTocPage: QuartzEmitterPlugin<Partial<ExplorerWithTocPageOptions>> = ( |
| 26 | + userOpts, |
| 27 | +) => { |
| 28 | + const opts: FullPageLayout = { |
| 29 | + ...sharedPageComponents, |
| 30 | + ...defaultContentPageLayout, |
| 31 | + pageBody: Blogs(), |
| 32 | + ...userOpts, |
| 33 | + } |
| 34 | + |
| 35 | + const { |
| 36 | + head: Head, |
| 37 | + header, |
| 38 | + navbar, |
| 39 | + beforeBody, |
| 40 | + pageBody, |
| 41 | + afterBody, |
| 42 | + left, |
| 43 | + right, |
| 44 | + footer: Footer, |
| 45 | + } = opts |
| 46 | + const Header = HeaderConstructor() |
| 47 | + const Body = BodyConstructor() |
| 48 | + |
| 49 | + return { |
| 50 | + name: "DesignPatterns", |
| 51 | + getQuartzComponents() { |
| 52 | + return [ |
| 53 | + Head, |
| 54 | + Header, |
| 55 | + ...navbar, |
| 56 | + Body, |
| 57 | + ...header, |
| 58 | + ...beforeBody, |
| 59 | + pageBody, |
| 60 | + ...afterBody, |
| 61 | + ...left, |
| 62 | + ...right, |
| 63 | + Footer, |
| 64 | + ] |
| 65 | + }, |
| 66 | + async getDependencyGraph(_ctx, _content, _resources) { |
| 67 | + return new DepGraph<FilePath>() |
| 68 | + }, |
| 69 | + async emit(ctx, _content, resources): Promise<FilePath[]> { |
| 70 | + const cfg = ctx.cfg.configuration |
| 71 | + const allFiles = _content.map((c) => c[1].data) |
| 72 | + const slug = "blogs" as FullSlug |
| 73 | + const title = "Pattern Blogs" |
| 74 | + const [tree, vfile] = defaultProcessedContent({ |
| 75 | + slug, |
| 76 | + text: title, |
| 77 | + frontmatter: { title: title, tags: [] }, |
| 78 | + }) |
| 79 | + const externalResources = pageResources(pathToRoot(slug), vfile.data, resources) |
| 80 | + const componentData: QuartzComponentProps = { |
| 81 | + ctx, |
| 82 | + fileData: vfile.data, |
| 83 | + externalResources, |
| 84 | + cfg, |
| 85 | + children: [], |
| 86 | + tree, |
| 87 | + allFiles: allFiles, |
| 88 | + } |
| 89 | + |
| 90 | + return [ |
| 91 | + await write({ |
| 92 | + ctx, |
| 93 | + content: renderPage(cfg, slug, componentData, opts, externalResources), |
| 94 | + slug, |
| 95 | + ext: ".html", |
| 96 | + }), |
| 97 | + ] |
| 98 | + }, |
| 99 | + } |
| 100 | +} |
0 commit comments