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