feat: layout.sidebars modes (fit, scroll, static) and a docs template

This commit is contained in:
saberzero1 committed 2026-11-08 00:01:29 +01:00
1 parent 0778a9a157
commit 08c2857aa6
23 files changed
+543 -22

No files matched your search

+5
View File
@@ -0,0 +1,5 @@
---
"@jackyzha0/quartz": minor
---
New `layout.sidebars` option: how each sidebar handles content taller than the screen. `fit` (default, unchanged) keeps it one screen tall and components shrink and scroll themselves; `scroll` keeps it in view and lets it scroll itself, so nothing is ever out of reach; `static` lets it scroll away with the page. Page types can override it (`byPageType.<type>.sidebars`). New `docs` template for documentation sites (`npx quartz create --template docs`), with both sidebars `static`. Frames receive the modes as a `sidebars` prop and put them on sidebar elements as `data-sidebar-mode`, which plugins can target in CSS.
+9
View File
@@ -447,6 +447,15 @@ emit: async (ctx, content) => {
Built-in settings are available too, with defaults and migrated options applied: `ctx.cfg.configuration.links.markdownLinkResolution`, `ctx.cfg.configuration.contentIndex.enableRSS`, … Both need Quartz 5.1+ — declare `"quartzVersion": ">=5.1.0"` (see [[versioning#For plugin authors]]).
### Components in sidebars
Sidebars have three modes ([[layout#Sidebar modes|`layout.sidebars`]]), set on the sidebar element as `data-sidebar-mode`:
- In `fit` (the default) a sidebar is exactly one screen tall and doesn't scroll. A component that can grow (a list, a tree) must be able to shrink: give it `min-height: 0` and its own scroll area (`overflow-y: auto`), or it pushes the components below it out of reach.
- In `scroll` and `static`, core gives every sidebar component its natural height (`flex-shrink: 0`); nothing extra is needed.
To behave differently per mode, target it in your stylesheet, e.g. `.sidebar[data-sidebar-mode="fit"] .my-list { max-height: 40vh; }`. Custom frames with sidebars should put the `sidebars` prop on their sidebar elements the same way.
### Providing Custom Frames
Plugins can ship their own [[layout#Page Frames|page frames]] — custom page layouts that control how the HTML structure (sidebars, header, content area, footer) is arranged. This is useful for page types that need fundamentally different layouts (e.g. a fullscreen canvas, a presentation mode, a dashboard).
+11 -10
View File
@@ -6,15 +6,15 @@ The `create` command initializes a new Quartz project. It helps you set up your
## Flags
| Flag | Shorthand | Description |
| ------------- | --------- | --------------------------------------------------------------------- |
| `--template` | `-t` | Configuration template (`default`, `obsidian`, `ttrpg`, or `blog`) |
| `--directory` | `-d` | The directory where Quartz will be initialized |
| `--source` | `-s` | The source directory of your Markdown files |
| `--strategy` | `-X` | How to handle the source files (`new`, `copy`, or `symlink`) |
| `--links` | `-l` | How to resolve internal links (`absolute`, `shortest`, or `relative`) |
| `--baseUrl` | `-b` | Base URL for your site (e.g. `mysite.github.io/quartz`) |
| `--verbose` | `-v` | Enable detailed logging |
| Flag | Shorthand | Description |
| ------------- | --------- | -------------------------------------------------------------------------- |
| `--template` | `-t` | Configuration template (`default`, `obsidian`, `ttrpg`, `blog`, or `docs`) |
| `--directory` | `-d` | The directory where Quartz will be initialized |
| `--source` | `-s` | The source directory of your Markdown files |
| `--strategy` | `-X` | How to handle the source files (`new`, `copy`, or `symlink`) |
| `--links` | `-l` | How to resolve internal links (`absolute`, `shortest`, or `relative`) |
| `--baseUrl` | `-b` | Base URL for your site (e.g. `mysite.github.io/quartz`) |
| `--verbose` | `-v` | Enable detailed logging |
## Templates
@@ -24,6 +24,7 @@ When you run `quartz create`, you can choose a configuration template that pre-c
- **Obsidian**: Optimized for Obsidian vaults with full Obsidian Flavored Markdown support (wikilinks, callouts, mermaid diagrams, etc.). Automatically sets link resolution to `shortest` and skips the link resolution prompt.
- **TTRPG**: Builds on the Obsidian template with the addition of the [Leaflet bases plugin](https://github.com/Requiae/quartz-leaflet-bases-plugin) and [ITS Theme](https://github.com/saberzero1/quartz-themes) (`its-theme.ttrpg-dnd`). Great for D&D and TTRPG wikis. Also skips the link resolution prompt.
- **Blog**: A blog-focused setup with [recent notes](https://github.com/quartz-community/recent-notes) enabled (showing the 5 most recent posts with tags) and [comments](https://github.com/quartz-community/comments) enabled via giscus. You'll need to fill in the `TODO:` placeholder values in `quartz.config.yaml` with your own giscus repository details.
- **Documentation**: The default setup with both sidebars set to scroll away with the page ([[layout#Sidebar modes|`layout.sidebars`]]: `static`), so long navigation and tables of contents are never cut off.
## Base URL
@@ -56,7 +57,7 @@ Quartz needs to know how to interpret the internal links in your Markdown files:
If you run `npx quartz create` without any arguments, it will guide you through an interactive setup:
1. **Choose a template**: Select a configuration template (`Default`, `Obsidian`, `TTRPG`, or `Blog`).
1. **Choose a template**: Select a configuration template (`Default`, `Obsidian`, `TTRPG`, `Blog`, or `Documentation`).
2. **Select a strategy**: Choose between `new`, `copy`, or `symlink`.
3. **Enter base URL**: Provide the URL where your site will be hosted.
4. **Select link resolution**: Choose how your links are formatted (skipped for Obsidian and TTRPG templates).
+1 -1
View File
@@ -20,7 +20,7 @@ You can run the CLI using `npx quartz`.
## Commands
- [[create|create]]: Initialize a new Quartz project with a choice of templates (default, obsidian, ttrpg, blog) and base URL configuration.
- [[create|create]]: Initialize a new Quartz project with a choice of templates (default, obsidian, ttrpg, blog, docs) and base URL configuration.
- [[build|build]]: Build your Quartz site into static HTML. Includes a development server.
- [[sync|sync]]: Push and pull changes between your local machine and GitHub.
- [[upgrade|upgrade]]: Upgrade the Quartz framework to the latest version. Also available as `npx quartz update`.
+1 -1
View File
@@ -58,7 +58,7 @@ npx quartz create
This will prompt you for:
- A **template** (`default`, `obsidian`, `ttrpg`, `blog`) — pick the one that matches your use case. See [[create#Templates]] for details on each.
- A **template** (`default`, `obsidian`, `ttrpg`, `blog`, `docs`) — pick the one that matches your use case. See [[create#Templates]] for details on each.
- A **content strategy** — choose how to populate the `content/` folder:
- **new**: Start with an empty folder
- **copy**: Copy files from an existing folder (e.g. your Obsidian vault)
+1 -1
View File
@@ -57,7 +57,7 @@ npx quartz create
This will prompt you for:
- A **template** (`default`, `obsidian`, `ttrpg`, `blog`) — pick the one closest to your old setup. `obsidian` is recommended if you use an Obsidian vault.
- A **template** (`default`, `obsidian`, `ttrpg`, `blog`, `docs`) — pick the one closest to your old setup. `obsidian` is recommended if you use an Obsidian vault.
- A **content strategy** — choose "Copy" and point it to your backed-up content folder.
If you skipped the `create` wizard or need to restore your content manually:
+1 -1
View File
@@ -56,7 +56,7 @@ Benefits:
- **No TypeScript knowledge required** for basic customization
- **JSON Schema validation** — editors with YAML support show errors inline
- **Layout defined per-plugin** — each plugin declares its own position and priority
- **Templates** — `npx quartz create` offers preconfigured templates (default, obsidian, ttrpg, blog)
- **Templates** — `npx quartz create` offers preconfigured templates (default, obsidian, ttrpg, blog, docs)
For advanced options that need JavaScript (callbacks, custom components), the `quartz.ts` override system provides full programmatic control.
+17
View File
@@ -273,6 +273,23 @@ Frames are applied as a `data-frame` attribute on the `.page` element, which you
Frame CSS should be scoped with `[data-frame="name"]` selectors to avoid conflicts with other frames.
### Sidebar modes
`layout.sidebars` sets how each sidebar handles content taller than the screen:
```yaml title="quartz.config.yaml"
layout:
sidebars:
left: static
right: fit
```
- `fit` (default): the sidebar stays in view and is exactly one screen tall. Its components shrink and scroll themselves (the explorer and table of contents get their own scroll area).
- `scroll`: the sidebar stays in view, and scrolls itself when its components are taller than the screen. Components take their natural height, so nothing can end up out of reach.
- `static`: the sidebar scrolls away with the page, like most documentation sites. The [[create#Templates|docs template]] uses this for both sidebars.
The modes apply where a sidebar is a column: the left sidebar above mobile width, the right sidebar on desktop. A page type can override them with `byPageType.<type>.sidebars`, merged over `layout.sidebars`.
### Layout breakpoints
Quartz has different layouts depending on the width the screen viewing the website.
+15
View File
@@ -168,6 +168,21 @@ export interface FullPageLayout {
footer: QuartzComponent[]
/** Page frame name (e.g. "default", "full-width", "minimal"). Defaults to "default". */
frame?: string
/** How each sidebar handles content taller than the screen (`layout.sidebars`). */
sidebars?: SidebarModes
}
/**
* - `fit` (default): the sidebar stays in view and is exactly one screen tall; components shrink
* and scroll themselves.
* - `scroll`: the sidebar stays in view and scrolls itself; components take their natural height.
* - `static`: the sidebar scrolls away with the page.
*/
export type SidebarMode = "fit" | "scroll" | "static"
export const SIDEBAR_MODES: readonly SidebarMode[] = ["fit", "scroll", "static"]
export interface SidebarModes {
left?: SidebarMode
right?: SidebarMode
}
export type PageLayout = Pick<FullPageLayout, "beforeBody" | "left" | "right">
+1 -1
View File
@@ -23,7 +23,7 @@ export const CreateArgv = {
template: {
string: true,
alias: ["t"],
choices: ["default", "obsidian", "ttrpg", "blog"],
choices: ["default", "obsidian", "ttrpg", "blog", "docs"],
describe: "template to use for initial configuration",
},
source: {
+5
View File
@@ -147,6 +147,11 @@ export async function handleCreate(argv) {
label: "Blog",
hint: "recent notes and comments enabled for blogging",
},
{
value: "docs",
label: "Documentation",
hint: "sidebars scroll with the page, for long navigation and tables of contents",
},
],
}),
)
+1 -1
View File
@@ -462,7 +462,7 @@ export function createConfigFromDefault() {
return rest
}
const VALID_TEMPLATES = ["default", "obsidian", "ttrpg", "blog"]
const VALID_TEMPLATES = ["default", "obsidian", "ttrpg", "blog", "docs"]
export function createConfigFromTemplate(templateName) {
if (!VALID_TEMPLATES.includes(templateName)) {
+279
View File
@@ -0,0 +1,279 @@
# yaml-language-server: $schema=../../plugins/quartz-plugins.schema.json
# Template: docs
# A documentation site: the default setup with sidebars that scroll away with the page
# (layout.sidebars: static), so long navigation and tables of contents are never cut off.
configuration:
pageTitle: Quartz 5
pageTitleSuffix: ""
enableSPA: true
enablePopovers: true
analytics:
provider: plausible
locale: en-US
baseUrl: quartz.jzhao.xyz
ignorePatterns:
- private
- templates
- .obsidian
theme:
fontOrigin: googleFonts
cdnCaching: true
typography:
header: Schibsted Grotesk
body: Source Sans Pro
code: IBM Plex Mono
colors:
lightMode:
light: "#faf8f8"
lightgray: "#e5e5e5"
gray: "#b8b8b8"
darkgray: "#4e4e4e"
dark: "#2b2b2b"
secondary: "#284b63"
tertiary: "#84a59d"
highlight: rgba(143, 159, 169, 0.15)
textHighlight: "#fff23688"
darkMode:
light: "#161618"
lightgray: "#393639"
gray: "#646464"
darkgray: "#d4d4d4"
dark: "#ebebec"
secondary: "#7b97aa"
tertiary: "#84a59d"
highlight: rgba(143, 159, 169, 0.15)
textHighlight: "#b3aa0288"
links:
markdownLinkResolution: shortest
contentIndex:
enableSiteMap: true
enableRSS: true
plugins:
- source: "@quartz-community/created-modified-date"
enabled: true
options:
defaultDateType: modified
priority:
- frontmatter
- git
- filesystem
order: 10
- source: "@quartz-community/syntax-highlighting"
enabled: true
options:
theme:
light: github-light
dark: github-dark
keepBackground: false
order: 20
- source: "@quartz-community/obsidian-flavored-markdown"
enabled: true
options:
enableInHtmlEmbed: false
enableCheckbox: true
order: 30
- source: "@quartz-community/github-flavored-markdown"
enabled: true
order: 40
- source: "@quartz-community/table-of-contents"
enabled: true
order: 50
layout:
position: right
priority: 30
- source: "@quartz-community/description"
enabled: true
order: 70
- source: "@quartz-community/latex"
enabled: true
options:
renderEngine: katex
order: 80
- source: "@quartz-community/citations"
enabled: false
order: 85
- source: "@quartz-community/ox-hugo"
enabled: false
order: 91
- source: "@quartz-community/roam"
enabled: false
order: 92
- source: "@quartz-community/quartz-fonts"
enabled: true
- source: "@quartz-themes/core"
enabled: false
options:
theme: tokyo-night
mode: both
- source: "@quartz-community/explicit-publish"
enabled: false
- source: "@quartz-community/unlisted-pages"
enabled: true
options: {}
order: 45
- source: "@quartz-community/encrypted-pages"
enabled: true
options:
iterations: 600000
passwordField: password
unlistWhenEncrypted: false
outputPath: static/encryptedContentIndex.json
- source: "@quartz-community/stacked-pages"
enabled: false
layout:
position: afterBody
priority: 50
display: all
- source: "@quartz-community/alias-redirects"
enabled: true
- source: "@quartz-community/favicon"
enabled: true
- source: "@quartz-community/og-image"
enabled: true
- source: "@quartz-community/cname"
enabled: true
- source: "@quartz-community/canvas-page"
enabled: true
- source: "@quartz-community/content-page"
enabled: true
- source: "@quartz-community/folder-page"
enabled: true
- source: "@quartz-community/tag-page"
enabled: true
- source: "@quartz-community/explorer"
enabled: true
layout:
position: left
priority: 50
- source: "@quartz-community/graph"
enabled: true
layout:
position: right
priority: 10
- source: "@quartz-community/search"
enabled: true
layout:
position: left
priority: 20
group: toolbar
groupOptions:
grow: true
- source: "@quartz-community/backlinks"
enabled: true
layout:
position: right
priority: 50
- source: "@quartz-community/article-title"
enabled: true
layout:
position: beforeBody
priority: 10
- source: "@quartz-community/content-meta"
enabled: true
layout:
position: beforeBody
priority: 20
- source: "@quartz-community/tag-list"
enabled: false
layout:
position: beforeBody
priority: 30
- source: "@quartz-community/page-title"
enabled: true
layout:
position: left
priority: 10
- source: "@quartz-community/darkmode"
enabled: true
layout:
position: left
priority: 30
group: toolbar
- source: "@quartz-community/reader-mode"
enabled: true
layout:
position: left
priority: 35
group: toolbar
- source: "@quartz-community/breadcrumbs"
enabled: true
layout:
position: beforeBody
priority: 5
condition: not-index
- source: "@quartz-community/comments"
enabled: false
options:
provider: giscus
options: {}
layout:
position: afterBody
priority: 10
- source: "@quartz-community/footer"
enabled: true
options:
links:
GitHub: https://github.com/jackyzha0/quartz
Discord Community: https://discord.gg/cRFFHYye7t
layout:
position: footer
priority: 50
- source: "@quartz-community/recent-notes"
enabled: false
- source: "@quartz-community/spacer"
enabled: true
options: {}
order: 25
layout:
position: left
priority: 25
display: mobile-only
- source: "@quartz-community/bases-page"
enabled: true
options: {}
order: 50
- source: "@quartz-community/note-properties"
enabled: true
options:
includeAll: false
includedProperties:
- description
- tags
- aliases
excludedProperties: []
hidePropertiesView: false
order: 5
layout:
position: beforeBody
priority: 15
display: all
layout:
# fit (default): one screen tall, components shrink and scroll · scroll: stays in view and
# scrolls itself · static: scrolls away with the page
sidebars:
left: static
right: static
groups:
toolbar:
priority: 35
direction: row
gap: 0.5rem
byPageType:
"404":
positions:
beforeBody: []
left: []
right: []
content: {}
folder:
exclude:
- reader-mode
positions:
right: []
tag:
exclude:
- reader-mode
positions:
right: []
canvas: {}
bases: {}
+3 -2
View File
@@ -20,10 +20,11 @@ export const DefaultFrame: PageFrame = {
left,
right,
footer,
sidebars,
}: PageFrameProps) {
return (
<>
<div class="left sidebar">
<div class="left sidebar" data-sidebar-mode={sidebars?.left ?? "fit"}>
{left.map((BodyComponent) => (
<BodyComponent {...componentData} />
))}
@@ -49,7 +50,7 @@ export const DefaultFrame: PageFrame = {
))}
</div>
</div>
<div class="right sidebar">
<div class="right sidebar" data-sidebar-mode={sidebars?.right ?? "fit"}>
{right.map((BodyComponent) => (
<BodyComponent {...componentData} />
))}
+53
View File
@@ -4,6 +4,8 @@ import { resolveFrame, frameRegistry } from "./index"
import { DefaultFrame } from "./DefaultFrame"
import { FullWidthFrame } from "./FullWidthFrame"
import type { PageFrame } from "./types"
import { render as renderToString } from "preact-render-to-string"
import { parseSidebars } from "../../plugins/loader/config-loader"
const customFrame: PageFrame = {
name: "custom-test-frame",
@@ -51,3 +53,54 @@ describe("resolveFrame", () => {
assert.strictEqual(calls.length, 1)
})
})
describe("sidebar modes", () => {
const empty = () => null
const render = (sidebars?: {
left: "fit" | "scroll" | "static"
right: "fit" | "scroll" | "static"
}) =>
renderToString(
DefaultFrame.render({
componentData: {} as never,
head: empty as never,
header: [],
beforeBody: [],
pageBody: empty as never,
afterBody: [],
left: [],
right: [],
footer: [],
sidebars,
}),
)
test("the default frame marks each sidebar with its mode", () => {
const html = render({ left: "static", right: "scroll" })
assert.match(html, /class="left sidebar" data-sidebar-mode="static"/)
assert.match(html, /class="right sidebar" data-sidebar-mode="scroll"/)
})
test("defaults to fit", () => {
assert.match(render(), /class="left sidebar" data-sidebar-mode="fit"/)
})
test("parseSidebars validates sides and modes", () => {
const warnings: string[] = []
const modes = parseSidebars(
{ left: "static", right: "scrol", top: "fit" },
"layout.sidebars",
(w) => warnings.push(w),
)
assert.deepStrictEqual(modes, { left: "static" })
assert.strictEqual(warnings.length, 2)
assert.ok(
warnings.some((w) => /right: unknown mode "scrol" \(did you mean "scroll"\?\)/.test(w)),
)
assert.ok(warnings.some((w) => /unknown sidebar "top"/.test(w)))
assert.deepStrictEqual(
parseSidebars(undefined, "x", () => {}),
{},
)
})
})
+6
View File
@@ -1,5 +1,6 @@
import { JSX } from "preact"
import { QuartzComponent, QuartzComponentProps } from "../types"
import type { SidebarMode } from "../../cfg"
/**
* Props passed to a PageFrame's render function.
@@ -18,6 +19,11 @@ export interface PageFrameProps {
pageBody: QuartzComponent
/** Components rendered after the page body */
afterBody: QuartzComponent[]
/**
* Sidebar modes from `layout.sidebars` (default "fit"). Frames with sidebars put them on the
* sidebar element as `data-sidebar-mode`; the core stylesheet does the rest.
*/
sidebars?: { left: SidebarMode; right: SidebarMode }
/** Left sidebar components */
left: QuartzComponent[]
/** Right sidebar components */
+4 -1
View File
@@ -10,7 +10,7 @@ import {
import { FullSlug, RelativeURL, joinSegments, normalizeHastElement } from "../util/path"
import { clone } from "../util/clone"
import { Root, Element, ElementContent } from "hast"
import { GlobalConfiguration } from "../cfg"
import { GlobalConfiguration, SidebarModes } from "../cfg"
import { i18n } from "../i18n"
import { styleText } from "util"
import { resolveFrame } from "./frames"
@@ -27,6 +27,7 @@ interface RenderComponents {
right: QuartzComponent[]
footer: QuartzComponent[]
frame?: string
sidebars?: SidebarModes
}
const headerRegex = new RegExp(/h[1-6]/)
@@ -340,6 +341,7 @@ export function renderPage(
right,
footer,
frame: frameName,
sidebars,
} = components
const Body = BodyConstructor()
const frame = resolveFrame(frameName)
@@ -370,6 +372,7 @@ export function renderPage(
left,
right,
footer,
sidebars: { left: sidebars?.left ?? "fit", right: sidebars?.right ?? "fit" },
}),
]}
</Body>
+47 -2
View File
@@ -3,7 +3,14 @@ import path from "path"
import YAML from "yaml"
import { styleText } from "util"
import { fileURLToPath } from "node:url"
import { QuartzConfig, GlobalConfiguration, FullPageLayout } from "../../cfg"
import {
QuartzConfig,
GlobalConfiguration,
FullPageLayout,
SIDEBAR_MODES,
SidebarMode,
SidebarModes,
} from "../../cfg"
import { QuartzComponent, QuartzComponentConstructor } from "../../components/types"
import { PluginTypes } from "../types"
import {
@@ -928,7 +935,36 @@ function layoutNameAliases(pluginName: string): string[] {
}
return [pluginName]
}
const PAGE_TYPE_OVERRIDE_KEYS = ["exclude", "positions", "template"]
const PAGE_TYPE_OVERRIDE_KEYS = ["exclude", "positions", "template", "sidebars"]
/** @internal Exported for testing. Read `layout.sidebars` (or a page type's override): `{ left?, right? }` of fit | scroll | static. */
export function parseSidebars(
raw: unknown,
where: string,
warn: (message: string) => void,
): SidebarModes {
if (raw === undefined || raw === null) return {}
if (typeof raw !== "object" || Array.isArray(raw)) {
warn(`${where}: expected { left, right } with fit, scroll or static — ignored.`)
return {}
}
const modes: SidebarModes = {}
for (const [side, value] of Object.entries(raw as Record<string, unknown>)) {
if (side !== "left" && side !== "right") {
warn(`${where}: unknown sidebar "${side}" — use left or right.`)
continue
}
if (!SIDEBAR_MODES.includes(value as SidebarMode)) {
const hint = suggest(String(value), [...SIDEBAR_MODES])
warn(
`${where}.${side}: unknown mode ${JSON.stringify(value)}${hint ? ` (did you mean "${hint}"?)` : ""} — using fit. Modes: ${SIDEBAR_MODES.join(", ")}.`,
)
continue
}
modes[side] = value as SidebarMode
}
return modes
}
/**
* Build the layout (defaults + per-page-type overrides) from a parsed
@@ -959,6 +995,8 @@ export function buildQuartzLayout(
const defaultLayout = buildLayoutForEntries(enabledEntries, layoutConfig, defaultDiag)
report.defaults = defaultDiag.placements
defaultDiag.warnings.forEach(warn)
const defaultSidebars = parseSidebars(layoutConfig.sidebars, "layout.sidebars", warn)
if (Object.keys(defaultSidebars).length > 0) defaultLayout.sidebars = defaultSidebars
const knownPluginNames = allEntries.flatMap((e) => layoutNameAliases(extractPluginName(e.source)))
const enabledPluginNames = new Set(
@@ -1043,6 +1081,13 @@ export function buildQuartzLayout(
entry.frame = override.template
}
if (override.sidebars !== undefined) {
entry.sidebars = {
...defaultSidebars,
...parseSidebars(override.sidebars, `byPageType.${pageType}.sidebars`, warn),
}
}
byPageType[pageType] = entry
report.byPageType[pageType] = {
exclude: exclude.filter((n) => enabledPluginNames.has(n)),
+4
View File
@@ -183,11 +183,15 @@ export interface PageTypeLayoutOverride {
positions?: Partial<Record<LayoutPosition, PluginLayoutDeclaration[]>>
/** Override the page frame template (e.g. "default", "full-width", "minimal") */
template?: string
/** Override sidebar modes for this page type (merged over `layout.sidebars`) */
sidebars?: { left?: string; right?: string }
}
/** Top-level layout section of quartz.config.yaml */
export interface LayoutConfig {
groups?: Record<string, FlexGroupConfig>
/** How each sidebar handles content taller than the screen: fit (default), scroll, static */
sidebars?: { left?: string; right?: string }
byPageType?: Record<string, PageTypeLayoutOverride>
}
@@ -30,6 +30,17 @@ function makePageType(
}
describe("resolveLayout", () => {
test("sidebar modes: a page type's override is merged per side over the defaults", () => {
const pt = makePageType()
const result = resolveLayout(
pt,
{ head: StubHead, sidebars: { left: "static", right: "scroll" } },
{ [pt.layout]: { sidebars: { right: "fit" } } },
)
assert.deepStrictEqual(result.sidebars, { left: "static", right: "fit" })
assert.deepStrictEqual(resolveLayout(pt, { head: StubHead }, {}).sidebars, {})
})
test("footer defaults to [] when sharedDefaults omits footer", () => {
const result = resolveLayout(makePageType(), { head: StubHead }, {})
assert.deepStrictEqual(result.footer, [])
+2
View File
@@ -36,6 +36,8 @@ export function resolveLayout(
right: overrides.right ?? sharedDefaults.right ?? [],
footer: overrides.footer ?? sharedDefaults.footer ?? [],
frame,
// layout.sidebars, with a page type's override merged per side
sidebars: { ...sharedDefaults.sidebars, ...overrides.sidebars },
}
}
+31 -1
View File
@@ -339,7 +339,7 @@
},
"rssSlug": {
"type": "string",
"description": "RSS feed slug (index \u2192 index.xml). Default index."
"description": "RSS feed slug (index → index.xml). Default index."
},
"includeEmptyFiles": {
"type": "boolean",
@@ -505,6 +505,21 @@
},
"description": "Layout groups configuration"
},
"sidebars": {
"type": "object",
"additionalProperties": false,
"description": "How each sidebar handles content taller than the screen: fit (default; one screen tall, components shrink and scroll), scroll (stays in view, scrolls itself), static (scrolls away with the page).",
"properties": {
"left": {
"enum": ["fit", "scroll", "static"],
"description": "Left sidebar mode"
},
"right": {
"enum": ["fit", "scroll", "static"],
"description": "Right sidebar mode"
}
}
},
"byPageType": {
"type": "object",
"additionalProperties": {
@@ -552,6 +567,21 @@
"template": {
"type": "string",
"description": "Page frame to use for this page type (e.g. default, full-width, minimal)"
},
"sidebars": {
"type": "object",
"additionalProperties": false,
"description": "Sidebar modes for this page type (merged over layout.sidebars).",
"properties": {
"left": {
"enum": ["fit", "scroll", "static"],
"description": "Left sidebar mode"
},
"right": {
"enum": ["fit", "scroll", "static"],
"description": "Right sidebar mode"
}
}
}
}
},
+35
View File
@@ -4,6 +4,28 @@
@use "./syntax.scss";
@use "./callouts.scss";
// layout.sidebars — how a sidebar handles content taller than the screen. `fit` (the default,
// no rules here) keeps it exactly one screen tall: its components shrink and scroll themselves.
@mixin sidebar-modes {
// stays in view, scrolls itself; components take their natural height
&[data-sidebar-mode="scroll"] {
overflow-y: auto;
overscroll-behavior: contain;
& > * {
flex-shrink: 0;
}
}
// scrolls away with the page
&[data-sidebar-mode="static"] {
position: static;
height: auto;
align-self: start;
& > * {
flex-shrink: 0;
}
}
}
html {
scroll-behavior: smooth;
text-size-adjust: none;
@@ -267,6 +289,19 @@ a {
}
}
}
// sidebar modes apply where a sidebar is a column: the left one above mobile width, the
// right one on desktop (narrower layouts turn them into rows)
& .sidebar.left {
@media all and not ($mobile) {
@include sidebar-modes;
}
}
& .sidebar.right {
@media all and ($desktop) {
@include sidebar-modes;
}
}
& .page-header,
& .page-footer {
margin-top: 1rem;