Skip to content

Commit

Permalink
feat(layout): add afterBody
Browse files Browse the repository at this point in the history
  • Loading branch information
jackyzha0 committed Jul 10, 2024
1 parent 4b407e7 commit 247625c
Show file tree
Hide file tree
Showing 12 changed files with 63 additions and 13 deletions.
4 changes: 2 additions & 2 deletions docs/advanced/making plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -260,11 +260,11 @@ export const ContentPage: QuartzEmitterPlugin = () => {
...defaultContentPageLayout,
pageBody: Content(),
}
const { head, header, beforeBody, pageBody, left, right, footer } = layout
const { head, header, beforeBody, pageBody, afterBody, left, right, footer } = layout
return {
name: "ContentPage",
getQuartzComponents() {
return [head, ...header, ...beforeBody, pageBody, ...left, ...right, footer]
return [head, ...header, ...beforeBody, pageBody, ...afterBody, ...left, ...right, footer]
},
async emit(ctx, content, resources, emit): Promise<FilePath[]> {
const cfg = ctx.cfg.configuration
Expand Down
Binary file modified docs/images/quartz layout.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions docs/layout.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export interface FullPageLayout {
header: QuartzComponent[] // laid out horizontally
beforeBody: QuartzComponent[] // laid out vertically
pageBody: QuartzComponent // single component
afterBody: QuartzComponent[] // laid out vertically
left: QuartzComponent[] // vertical on desktop, horizontal on mobile
right: QuartzComponent[] // vertical on desktop, horizontal on mobile
footer: QuartzComponent // single component
Expand Down
1 change: 1 addition & 0 deletions quartz.layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import * as Component from "./quartz/components"
export const sharedPageComponents: SharedLayout = {
head: Component.Head(),
header: [],
afterBody: [],
footer: Component.Footer({
links: {
GitHub: "https://github.com/jackyzha0/quartz",
Expand Down
3 changes: 2 additions & 1 deletion quartz/cfg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,11 @@ export interface FullPageLayout {
header: QuartzComponent[]
beforeBody: QuartzComponent[]
pageBody: QuartzComponent
afterBody: QuartzComponent[]
left: QuartzComponent[]
right: QuartzComponent[]
footer: QuartzComponent
}

export type PageLayout = Pick<FullPageLayout, "beforeBody" | "left" | "right">
export type SharedLayout = Pick<FullPageLayout, "head" | "header" | "footer">
export type SharedLayout = Pick<FullPageLayout, "head" | "header" | "footer" | "afterBody">
1 change: 0 additions & 1 deletion quartz/components/Footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ export default ((opts?: Options) => {
const links = opts?.links ?? []
return (
<footer class={`${displayClass ?? ""}`}>
<hr />
<p>
{i18n(cfg.locale).components.footer.createdWith}{" "}
<a href="https://quartz.jzhao.xyz/">Quartz v{version}</a> © {year}
Expand Down
8 changes: 8 additions & 0 deletions quartz/components/renderPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ interface RenderComponents {
header: QuartzComponent[]
beforeBody: QuartzComponent[]
pageBody: QuartzComponent
afterBody: QuartzComponent[]
left: QuartzComponent[]
right: QuartzComponent[]
footer: QuartzComponent
Expand Down Expand Up @@ -187,6 +188,7 @@ export function renderPage(
header,
beforeBody,
pageBody: Content,
afterBody,
left,
right,
footer: Footer,
Expand Down Expand Up @@ -232,6 +234,12 @@ export function renderPage(
</div>
</div>
<Content {...componentData} />
<hr />
<div class="page-footer">
{afterBody.map((BodyComponent) => (
<BodyComponent {...componentData} />
))}
</div>
</div>
{RightComponent}
</Body>
Expand Down
15 changes: 13 additions & 2 deletions quartz/plugins/emitters/contentPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,25 @@ export const ContentPage: QuartzEmitterPlugin<Partial<FullPageLayout>> = (userOp
...userOpts,
}

const { head: Head, header, beforeBody, pageBody, left, right, footer: Footer } = opts
const { head: Head, header, beforeBody, pageBody, afterBody, left, right, footer: Footer } = opts
const Header = HeaderConstructor()
const Body = BodyConstructor()

return {
name: "ContentPage",
getQuartzComponents() {
return [Head, Header, Body, ...header, ...beforeBody, pageBody, ...left, ...right, Footer]
return [
Head,
Header,
Body,
...header,
...beforeBody,
pageBody,
...afterBody,
...left,
...right,
Footer,
]
},
async getDependencyGraph(ctx, content, _resources) {
const graph = new DepGraph<FilePath>()
Expand Down
15 changes: 13 additions & 2 deletions quartz/plugins/emitters/folderPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,25 @@ export const FolderPage: QuartzEmitterPlugin<Partial<FolderPageOptions>> = (user
...userOpts,
}

const { head: Head, header, beforeBody, pageBody, left, right, footer: Footer } = opts
const { head: Head, header, beforeBody, pageBody, afterBody, left, right, footer: Footer } = opts
const Header = HeaderConstructor()
const Body = BodyConstructor()

return {
name: "FolderPage",
getQuartzComponents() {
return [Head, Header, Body, ...header, ...beforeBody, pageBody, ...left, ...right, Footer]
return [
Head,
Header,
Body,
...header,
...beforeBody,
pageBody,
...afterBody,
...left,
...right,
Footer,
]
},
async getDependencyGraph(_ctx, content, _resources) {
// Example graph:
Expand Down
15 changes: 13 additions & 2 deletions quartz/plugins/emitters/tagPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,25 @@ export const TagPage: QuartzEmitterPlugin<Partial<TagPageOptions>> = (userOpts)
...userOpts,
}

const { head: Head, header, beforeBody, pageBody, left, right, footer: Footer } = opts
const { head: Head, header, beforeBody, pageBody, afterBody, left, right, footer: Footer } = opts
const Header = HeaderConstructor()
const Body = BodyConstructor()

return {
name: "TagPage",
getQuartzComponents() {
return [Head, Header, Body, ...header, ...beforeBody, pageBody, ...left, ...right, Footer]
return [
Head,
Header,
Body,
...header,
...beforeBody,
pageBody,
...afterBody,
...left,
...right,
Footer,
]
},
async getDependencyGraph(ctx, content, _resources) {
const graph = new DepGraph<FilePath>()
Expand Down
1 change: 0 additions & 1 deletion quartz/plugins/transformers/ofm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { QuartzTransformerPlugin } from "../types"
import { Root, Html, BlockContent, DefinitionContent, Paragraph, Code } from "mdast"
import { Element, Literal, Root as HtmlRoot } from "hast"
import { ReplaceFunction, findAndReplace as mdastFindReplace } from "mdast-util-find-and-replace"
import { slug as slugAnchor } from "github-slugger"
import rehypeRaw from "rehype-raw"
import { SKIP, visit } from "unist-util-visit"
import path from "path"
Expand Down
12 changes: 10 additions & 2 deletions quartz/styles/base.scss
Original file line number Diff line number Diff line change
Expand Up @@ -201,11 +201,19 @@ a {
}
}

& .page-header {
& .page-header,
& .page-footer {
width: $pageWidth;
margin: $topSpacing auto 0 auto;
margin-top: 1rem;

@media all and (max-width: $fullPageWidth) {
width: initial;
}
}

& .page-header {
margin: $topSpacing auto 0 auto;
@media all and (max-width: $fullPageWidth) {
margin-top: 2rem;
}
}
Expand Down

0 comments on commit 247625c

Please sign in to comment.