mirror of
https://github.com/jackyzha0/quartz.git
synced 2025-12-27 14:54:05 -06:00
feat(layout): add new component navbar to layout option
This commit is contained in:
parent
137d55eb1b
commit
fd9a8579f7
@ -4,6 +4,7 @@ import * as Component from "./quartz/components"
|
||||
// components shared across all pages
|
||||
export const sharedPageComponents: SharedLayout = {
|
||||
head: Component.Head(),
|
||||
navbar: [],
|
||||
header: [],
|
||||
afterBody: [],
|
||||
footer: Component.Footer({
|
||||
|
||||
@ -84,6 +84,7 @@ export interface QuartzConfig {
|
||||
|
||||
export interface FullPageLayout {
|
||||
head: QuartzComponent
|
||||
navbar: QuartzComponent[]
|
||||
header: QuartzComponent[]
|
||||
beforeBody: QuartzComponent[]
|
||||
pageBody: QuartzComponent
|
||||
@ -94,4 +95,4 @@ export interface FullPageLayout {
|
||||
}
|
||||
|
||||
export type PageLayout = Pick<FullPageLayout, "beforeBody" | "left" | "right">
|
||||
export type SharedLayout = Pick<FullPageLayout, "head" | "header" | "footer" | "afterBody">
|
||||
export type SharedLayout = Pick<FullPageLayout, "head" | "navbar" | "header" | "footer" | "afterBody">
|
||||
|
||||
37
quartz/components/Navbar.tsx
Normal file
37
quartz/components/Navbar.tsx
Normal file
@ -0,0 +1,37 @@
|
||||
import { QuartzComponent, QuartzComponentConstructor, QuartzComponentProps } from "./types"
|
||||
|
||||
const Navbar: QuartzComponent = ({ children }: QuartzComponentProps) => {
|
||||
return children.length > 0 ? (
|
||||
<nav>
|
||||
<ul>
|
||||
{children.map((child, index) => (
|
||||
<li key={index}>{child}</li>
|
||||
))}
|
||||
</ul>
|
||||
</nav>
|
||||
) : null;
|
||||
};
|
||||
|
||||
Navbar.css = `
|
||||
nav {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: flex-end;
|
||||
padding: 1rem 2rem;
|
||||
}
|
||||
|
||||
nav ul {
|
||||
display: flex;
|
||||
list-style: none;
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
gap: 1.5rem;
|
||||
}
|
||||
|
||||
nav li {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
`
|
||||
|
||||
export default (() => Navbar) satisfies QuartzComponentConstructor
|
||||
@ -2,6 +2,7 @@ import { render } from "preact-render-to-string"
|
||||
import { QuartzComponent, QuartzComponentProps } from "./types"
|
||||
import HeaderConstructor from "./Header"
|
||||
import BodyConstructor from "./Body"
|
||||
import NavbarContructor from "./Navbar";
|
||||
import { JSResourceToScriptElement, StaticResources } from "../util/resources"
|
||||
import { clone, FullSlug, RelativeURL, joinSegments, normalizeHastElement } from "../util/path"
|
||||
import { visit } from "unist-util-visit"
|
||||
@ -11,6 +12,7 @@ import { i18n } from "../i18n"
|
||||
|
||||
interface RenderComponents {
|
||||
head: QuartzComponent
|
||||
navbar: QuartzComponent[]
|
||||
header: QuartzComponent[]
|
||||
beforeBody: QuartzComponent[]
|
||||
pageBody: QuartzComponent
|
||||
@ -190,6 +192,7 @@ export function renderPage(
|
||||
|
||||
const {
|
||||
head: Head,
|
||||
navbar,
|
||||
header,
|
||||
beforeBody,
|
||||
pageBody: Content,
|
||||
@ -200,6 +203,7 @@ export function renderPage(
|
||||
} = components
|
||||
const Header = HeaderConstructor()
|
||||
const Body = BodyConstructor()
|
||||
const Navbar = NavbarContructor()
|
||||
|
||||
const LeftComponent = (
|
||||
<div class="left sidebar">
|
||||
@ -223,6 +227,11 @@ export function renderPage(
|
||||
<Head {...componentData} />
|
||||
<body data-slug={slug}>
|
||||
<div id="quartz-root" class="page">
|
||||
<Navbar {...componentData}>
|
||||
{navbar.map((NavbarComponent) => (
|
||||
<NavbarComponent {...componentData} />
|
||||
))}
|
||||
</Navbar>
|
||||
<Body {...componentData}>
|
||||
{LeftComponent}
|
||||
<div class="center">
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
import { QuartzEmitterPlugin } from "../types"
|
||||
import { QuartzComponentProps } from "../../components/types"
|
||||
import BodyConstructor from "../../components/Body"
|
||||
import NavbarContructor from "../../components/Navbar"
|
||||
import { pageResources, renderPage } from "../../components/renderPage"
|
||||
import { FullPageLayout } from "../../cfg"
|
||||
import { FilePath, FullSlug } from "../../util/path"
|
||||
@ -20,13 +21,14 @@ export const NotFoundPage: QuartzEmitterPlugin = () => {
|
||||
right: [],
|
||||
}
|
||||
|
||||
const { head: Head, pageBody, footer: Footer } = opts
|
||||
const { head: Head, navbar, pageBody, footer: Footer } = opts
|
||||
const Body = BodyConstructor()
|
||||
const Navbar = NavbarContructor()
|
||||
|
||||
return {
|
||||
name: "404Page",
|
||||
getQuartzComponents() {
|
||||
return [Head, Body, pageBody, Footer]
|
||||
return [Head, Navbar, ...navbar, Body, pageBody, Footer]
|
||||
},
|
||||
async getDependencyGraph(_ctx, _content, _resources) {
|
||||
return new DepGraph<FilePath>()
|
||||
|
||||
@ -6,6 +6,7 @@ import { QuartzEmitterPlugin } from "../types"
|
||||
import { QuartzComponentProps } from "../../components/types"
|
||||
import HeaderConstructor from "../../components/Header"
|
||||
import BodyConstructor from "../../components/Body"
|
||||
import NavbarContructor from "../../components/Navbar";
|
||||
import { pageResources, renderPage } from "../../components/renderPage"
|
||||
import { FullPageLayout } from "../../cfg"
|
||||
import { Argv } from "../../util/ctx"
|
||||
@ -59,15 +60,18 @@ export const ContentPage: QuartzEmitterPlugin<Partial<FullPageLayout>> = (userOp
|
||||
...userOpts,
|
||||
}
|
||||
|
||||
const { head: Head, header, beforeBody, pageBody, afterBody, left, right, footer: Footer } = opts
|
||||
const { head: Head, navbar, header, beforeBody, pageBody, afterBody, left, right, footer: Footer } = opts
|
||||
const Header = HeaderConstructor()
|
||||
const Body = BodyConstructor()
|
||||
const Navbar = NavbarContructor()
|
||||
|
||||
return {
|
||||
name: "ContentPage",
|
||||
getQuartzComponents() {
|
||||
return [
|
||||
Head,
|
||||
Navbar,
|
||||
...navbar,
|
||||
Header,
|
||||
Body,
|
||||
...header,
|
||||
|
||||
@ -2,6 +2,7 @@ import { QuartzEmitterPlugin } from "../types"
|
||||
import { QuartzComponentProps } from "../../components/types"
|
||||
import HeaderConstructor from "../../components/Header"
|
||||
import BodyConstructor from "../../components/Body"
|
||||
import NavbarContructor from "../../components/Navbar"
|
||||
import { pageResources, renderPage } from "../../components/renderPage"
|
||||
import { ProcessedContent, QuartzPluginData, defaultProcessedContent } from "../vfile"
|
||||
import { FullPageLayout } from "../../cfg"
|
||||
@ -33,15 +34,18 @@ export const FolderPage: QuartzEmitterPlugin<Partial<FolderPageOptions>> = (user
|
||||
...userOpts,
|
||||
}
|
||||
|
||||
const { head: Head, header, beforeBody, pageBody, afterBody, left, right, footer: Footer } = opts
|
||||
const { head: Head, navbar, header, beforeBody, pageBody, afterBody, left, right, footer: Footer } = opts
|
||||
const Header = HeaderConstructor()
|
||||
const Body = BodyConstructor()
|
||||
const Navbar = NavbarContructor()
|
||||
|
||||
return {
|
||||
name: "FolderPage",
|
||||
getQuartzComponents() {
|
||||
return [
|
||||
Head,
|
||||
Navbar,
|
||||
...navbar,
|
||||
Header,
|
||||
Body,
|
||||
...header,
|
||||
|
||||
@ -2,6 +2,7 @@ import { QuartzEmitterPlugin } from "../types"
|
||||
import { QuartzComponentProps } from "../../components/types"
|
||||
import HeaderConstructor from "../../components/Header"
|
||||
import BodyConstructor from "../../components/Body"
|
||||
import NavbarContructor from "../../components/Navbar"
|
||||
import { pageResources, renderPage } from "../../components/renderPage"
|
||||
import { ProcessedContent, QuartzPluginData, defaultProcessedContent } from "../vfile"
|
||||
import { FullPageLayout } from "../../cfg"
|
||||
@ -30,15 +31,18 @@ export const TagPage: QuartzEmitterPlugin<Partial<TagPageOptions>> = (userOpts)
|
||||
...userOpts,
|
||||
}
|
||||
|
||||
const { head: Head, header, beforeBody, pageBody, afterBody, left, right, footer: Footer } = opts
|
||||
const { head: Head, navbar, header, beforeBody, pageBody, afterBody, left, right, footer: Footer } = opts
|
||||
const Header = HeaderConstructor()
|
||||
const Body = BodyConstructor()
|
||||
const Navbar = NavbarContructor()
|
||||
|
||||
return {
|
||||
name: "TagPage",
|
||||
getQuartzComponents() {
|
||||
return [
|
||||
Head,
|
||||
Navbar,
|
||||
...navbar,
|
||||
Header,
|
||||
Body,
|
||||
...header,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user