mirror of
https://github.com/jackyzha0/quartz.git
synced 2026-03-24 15:05:42 -05:00
format
This commit is contained in:
parent
388ab1f228
commit
3dc4a40d91
135
quartz/build.ts
135
quartz/build.ts
@ -1,24 +1,24 @@
|
||||
import sourceMapSupport from "source-map-support"
|
||||
sourceMapSupport.install(options)
|
||||
import path from "path"
|
||||
import { PerfTimer } from "./util/perf"
|
||||
import { rimraf } from "rimraf"
|
||||
import { GlobbyFilterFunction, isGitIgnored } from "globby"
|
||||
import {PerfTimer} from "./util/perf"
|
||||
import {rimraf} from "rimraf"
|
||||
import {GlobbyFilterFunction, isGitIgnored} from "globby"
|
||||
import chalk from "chalk"
|
||||
import { parseMarkdown } from "./processors/parse"
|
||||
import { filterContent } from "./processors/filter"
|
||||
import { emitContent } from "./processors/emit"
|
||||
import {parseMarkdown} from "./processors/parse"
|
||||
import {filterContent} from "./processors/filter"
|
||||
import {emitContent} from "./processors/emit"
|
||||
import cfg from "../quartz.config"
|
||||
import { FilePath, FullSlug, joinSegments, slugifyFilePath } from "./util/path"
|
||||
import {FilePath, FullSlug, joinSegments, slugifyFilePath} from "./util/path"
|
||||
import chokidar from "chokidar"
|
||||
import { ProcessedContent } from "./plugins/vfile"
|
||||
import { Argv, BuildCtx } from "./util/ctx"
|
||||
import { glob, toPosixPath } from "./util/glob"
|
||||
import { trace } from "./util/trace"
|
||||
import { options } from "./util/sourcemap"
|
||||
import { Mutex } from "async-mutex"
|
||||
import {ProcessedContent} from "./plugins/vfile"
|
||||
import {Argv, BuildCtx} from "./util/ctx"
|
||||
import {glob, toPosixPath} from "./util/glob"
|
||||
import {trace} from "./util/trace"
|
||||
import {options} from "./util/sourcemap"
|
||||
import {Mutex} from "async-mutex"
|
||||
import DepGraph from "./depgraph"
|
||||
import { getStaticResourcesFromPlugins } from "./plugins"
|
||||
import {getStaticResourcesFromPlugins} from "./plugins"
|
||||
|
||||
type Dependencies = Record<string, DepGraph<FilePath> | null>
|
||||
|
||||
@ -65,17 +65,25 @@ async function buildQuartz(argv: Argv, mut: Mutex, clientRefresh: () => void) {
|
||||
|
||||
const release = await mut.acquire()
|
||||
perf.addEvent("clean")
|
||||
await rimraf(path.join(output, "*"), { glob: true })
|
||||
console.log(`Cleaned output directory \`${output}\` in ${perf.timeSince("clean")}`)
|
||||
await rimraf(path.join(output, "*"), {glob: true})
|
||||
console.log(
|
||||
`Cleaned output directory \`${output}\` in ${perf.timeSince("clean")}`,
|
||||
)
|
||||
|
||||
perf.addEvent("glob")
|
||||
const allFiles = await glob("**/*.*", argv.directory, cfg.configuration.ignorePatterns)
|
||||
const allFiles = await glob(
|
||||
"**/*.*",
|
||||
argv.directory,
|
||||
cfg.configuration.ignorePatterns,
|
||||
)
|
||||
const fps = allFiles.filter((fp) => fp.endsWith(".md")).sort()
|
||||
console.log(
|
||||
`Found ${fps.length} input files from \`${argv.directory}\` in ${perf.timeSince("glob")}`,
|
||||
)
|
||||
|
||||
const filePaths = fps.map((fp) => joinSegments(argv.directory, fp) as FilePath)
|
||||
const filePaths = fps.map(
|
||||
(fp) => joinSegments(argv.directory, fp) as FilePath,
|
||||
)
|
||||
ctx.allSlugs = allFiles.map((fp) => slugifyFilePath(fp as FilePath))
|
||||
|
||||
const parsedFiles = await parseMarkdown(ctx, filePaths)
|
||||
@ -88,12 +96,18 @@ async function buildQuartz(argv: Argv, mut: Mutex, clientRefresh: () => void) {
|
||||
const staticResources = getStaticResourcesFromPlugins(ctx)
|
||||
for (const emitter of cfg.plugins.emitters) {
|
||||
dependencies[emitter.name] =
|
||||
(await emitter.getDependencyGraph?.(ctx, filteredContent, staticResources)) ?? null
|
||||
(await emitter.getDependencyGraph?.(
|
||||
ctx,
|
||||
filteredContent,
|
||||
staticResources,
|
||||
)) ?? null
|
||||
}
|
||||
}
|
||||
|
||||
await emitContent(ctx, filteredContent)
|
||||
console.log(chalk.green(`Done processing ${fps.length} files in ${perf.timeSince()}`))
|
||||
console.log(
|
||||
chalk.green(`Done processing ${fps.length} files in ${perf.timeSince()}`),
|
||||
)
|
||||
release()
|
||||
|
||||
if (argv.serve) {
|
||||
@ -109,7 +123,7 @@ async function startServing(
|
||||
clientRefresh: () => void,
|
||||
dependencies: Dependencies, // emitter name: dep graph
|
||||
) {
|
||||
const { argv } = ctx
|
||||
const {argv} = ctx
|
||||
|
||||
// cache file parse results
|
||||
const contentMap = new Map<FilePath, ProcessedContent>()
|
||||
@ -137,11 +151,17 @@ async function startServing(
|
||||
ignoreInitial: true,
|
||||
})
|
||||
|
||||
const buildFromEntry = argv.fastRebuild ? partialRebuildFromEntrypoint : rebuildFromEntrypoint
|
||||
const buildFromEntry = argv.fastRebuild
|
||||
? partialRebuildFromEntrypoint
|
||||
: rebuildFromEntrypoint
|
||||
watcher
|
||||
.on("add", (fp) => buildFromEntry(fp, "add", clientRefresh, buildData))
|
||||
.on("change", (fp) => buildFromEntry(fp, "change", clientRefresh, buildData))
|
||||
.on("unlink", (fp) => buildFromEntry(fp, "delete", clientRefresh, buildData))
|
||||
.on("change", (fp) =>
|
||||
buildFromEntry(fp, "change", clientRefresh, buildData),
|
||||
)
|
||||
.on("unlink", (fp) =>
|
||||
buildFromEntry(fp, "delete", clientRefresh, buildData),
|
||||
)
|
||||
|
||||
return async () => {
|
||||
await watcher.close()
|
||||
@ -154,8 +174,8 @@ async function partialRebuildFromEntrypoint(
|
||||
clientRefresh: () => void,
|
||||
buildData: BuildData, // note: this function mutates buildData
|
||||
) {
|
||||
const { ctx, ignored, dependencies, contentMap, mut, toRemove } = buildData
|
||||
const { argv, cfg } = ctx
|
||||
const {ctx, ignored, dependencies, contentMap, mut, toRemove} = buildData
|
||||
const {argv, cfg} = ctx
|
||||
|
||||
// don't do anything for gitignored files
|
||||
if (ignored(filepath)) {
|
||||
@ -184,12 +204,18 @@ async function partialRebuildFromEntrypoint(
|
||||
case "add":
|
||||
// add to cache when new file is added
|
||||
processedFiles = await parseMarkdown(ctx, [fp])
|
||||
processedFiles.forEach(([tree, vfile]) => contentMap.set(vfile.data.filePath!, [tree, vfile]))
|
||||
processedFiles.forEach(([tree, vfile]) =>
|
||||
contentMap.set(vfile.data.filePath!, [tree, vfile]),
|
||||
)
|
||||
|
||||
// update the dep graph by asking all emitters whether they depend on this file
|
||||
for (const emitter of cfg.plugins.emitters) {
|
||||
const emitterGraph =
|
||||
(await emitter.getDependencyGraph?.(ctx, processedFiles, staticResources)) ?? null
|
||||
(await emitter.getDependencyGraph?.(
|
||||
ctx,
|
||||
processedFiles,
|
||||
staticResources,
|
||||
)) ?? null
|
||||
|
||||
if (emitterGraph) {
|
||||
const existingGraph = dependencies[emitter.name]
|
||||
@ -205,20 +231,29 @@ async function partialRebuildFromEntrypoint(
|
||||
case "change":
|
||||
// invalidate cache when file is changed
|
||||
processedFiles = await parseMarkdown(ctx, [fp])
|
||||
processedFiles.forEach(([tree, vfile]) => contentMap.set(vfile.data.filePath!, [tree, vfile]))
|
||||
processedFiles.forEach(([tree, vfile]) =>
|
||||
contentMap.set(vfile.data.filePath!, [tree, vfile]),
|
||||
)
|
||||
|
||||
// only content files can have added/removed dependencies because of transclusions
|
||||
if (path.extname(fp) === ".md") {
|
||||
for (const emitter of cfg.plugins.emitters) {
|
||||
// get new dependencies from all emitters for this file
|
||||
const emitterGraph =
|
||||
(await emitter.getDependencyGraph?.(ctx, processedFiles, staticResources)) ?? null
|
||||
(await emitter.getDependencyGraph?.(
|
||||
ctx,
|
||||
processedFiles,
|
||||
staticResources,
|
||||
)) ?? null
|
||||
|
||||
// only update the graph if the emitter plugin uses the changed file
|
||||
// eg. Assets plugin ignores md files, so we skip updating the graph
|
||||
if (emitterGraph?.hasNode(fp)) {
|
||||
// merge the new dependencies into the dep graph
|
||||
dependencies[emitter.name]?.updateIncomingEdgesForNode(emitterGraph, fp)
|
||||
dependencies[emitter.name]?.updateIncomingEdgesForNode(
|
||||
emitterGraph,
|
||||
fp,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -281,7 +316,11 @@ async function partialRebuildFromEntrypoint(
|
||||
.filter((file) => !toRemove.has(file))
|
||||
.map((file) => contentMap.get(file)!)
|
||||
|
||||
const emittedFps = await emitter.emit(ctx, upstreamContent, staticResources)
|
||||
const emittedFps = await emitter.emit(
|
||||
ctx,
|
||||
upstreamContent,
|
||||
staticResources,
|
||||
)
|
||||
|
||||
if (ctx.argv.verbose) {
|
||||
for (const file of emittedFps) {
|
||||
@ -293,7 +332,9 @@ async function partialRebuildFromEntrypoint(
|
||||
}
|
||||
}
|
||||
|
||||
console.log(`Emitted ${emittedFiles} files to \`${argv.output}\` in ${perf.timeSince("rebuild")}`)
|
||||
console.log(
|
||||
`Emitted ${emittedFiles} files to \`${argv.output}\` in ${perf.timeSince("rebuild")}`,
|
||||
)
|
||||
|
||||
// CLEANUP
|
||||
const destinationsToDelete = new Set<FilePath>()
|
||||
@ -328,10 +369,18 @@ async function rebuildFromEntrypoint(
|
||||
clientRefresh: () => void,
|
||||
buildData: BuildData, // note: this function mutates buildData
|
||||
) {
|
||||
const { ctx, ignored, mut, initialSlugs, contentMap, toRebuild, toRemove, trackedAssets } =
|
||||
buildData
|
||||
const {
|
||||
ctx,
|
||||
ignored,
|
||||
mut,
|
||||
initialSlugs,
|
||||
contentMap,
|
||||
toRebuild,
|
||||
toRemove,
|
||||
trackedAssets,
|
||||
} = buildData
|
||||
|
||||
const { argv } = ctx
|
||||
const {argv} = ctx
|
||||
|
||||
// don't do anything for gitignored files
|
||||
if (ignored(fp)) {
|
||||
@ -387,19 +436,25 @@ async function rebuildFromEntrypoint(
|
||||
const filteredContent = filterContent(ctx, parsedFiles)
|
||||
|
||||
// re-update slugs
|
||||
const trackedSlugs = [...new Set([...contentMap.keys(), ...toRebuild, ...trackedAssets])]
|
||||
const trackedSlugs = [
|
||||
...new Set([...contentMap.keys(), ...toRebuild, ...trackedAssets]),
|
||||
]
|
||||
.filter((fp) => !toRemove.has(fp))
|
||||
.map((fp) => slugifyFilePath(path.posix.relative(argv.directory, fp) as FilePath))
|
||||
.map((fp) =>
|
||||
slugifyFilePath(path.posix.relative(argv.directory, fp) as FilePath),
|
||||
)
|
||||
|
||||
ctx.allSlugs = [...new Set([...initialSlugs, ...trackedSlugs])]
|
||||
|
||||
// TODO: we can probably traverse the link graph to figure out what's safe to delete here
|
||||
// instead of just deleting everything
|
||||
await rimraf(path.join(argv.output, ".*"), { glob: true })
|
||||
await rimraf(path.join(argv.output, ".*"), {glob: true})
|
||||
await emitContent(ctx, filteredContent)
|
||||
console.log(chalk.green(`Done rebuilding in ${perf.timeSince()}`))
|
||||
} catch (err) {
|
||||
console.log(chalk.yellow(`Rebuild failed. Waiting on a change to fix the error...`))
|
||||
console.log(
|
||||
chalk.yellow(`Rebuild failed. Waiting on a change to fix the error...`),
|
||||
)
|
||||
if (argv.verbose) {
|
||||
console.log(chalk.red(err))
|
||||
}
|
||||
|
||||
@ -84,4 +84,7 @@ 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" | "header" | "footer" | "afterBody"
|
||||
>
|
||||
|
||||
@ -1,7 +1,14 @@
|
||||
import { QuartzComponent, QuartzComponentConstructor, QuartzComponentProps } from "./types"
|
||||
import { classNames } from "../util/lang"
|
||||
import {
|
||||
QuartzComponent,
|
||||
QuartzComponentConstructor,
|
||||
QuartzComponentProps,
|
||||
} from "./types"
|
||||
import {classNames} from "../util/lang"
|
||||
|
||||
const ArticleTitle: QuartzComponent = ({ fileData, displayClass }: QuartzComponentProps) => {
|
||||
const ArticleTitle: QuartzComponent = ({
|
||||
fileData,
|
||||
displayClass,
|
||||
}: QuartzComponentProps) => {
|
||||
const title = fileData.frontmatter?.title
|
||||
if (title) {
|
||||
return <h1 class={classNames(displayClass, "article-title")}>{title}</h1>
|
||||
|
||||
@ -1,8 +1,12 @@
|
||||
import { QuartzComponent, QuartzComponentConstructor, QuartzComponentProps } from "./types"
|
||||
import {
|
||||
QuartzComponent,
|
||||
QuartzComponentConstructor,
|
||||
QuartzComponentProps,
|
||||
} from "./types"
|
||||
import style from "./styles/backlinks.scss"
|
||||
import { resolveRelative, simplifySlug } from "../util/path"
|
||||
import { i18n } from "../i18n"
|
||||
import { classNames } from "../util/lang"
|
||||
import {resolveRelative, simplifySlug} from "../util/path"
|
||||
import {i18n} from "../i18n"
|
||||
import {classNames} from "../util/lang"
|
||||
|
||||
const Backlinks: QuartzComponent = ({
|
||||
fileData,
|
||||
@ -19,7 +23,9 @@ const Backlinks: QuartzComponent = ({
|
||||
{backlinkFiles.length > 0 ? (
|
||||
backlinkFiles.map((f) => (
|
||||
<li>
|
||||
<a href={resolveRelative(fileData.slug!, f.slug!)} class="internal">
|
||||
<a
|
||||
href={resolveRelative(fileData.slug!, f.slug!)}
|
||||
class="internal">
|
||||
{f.frontmatter?.title}
|
||||
</a>
|
||||
</li>
|
||||
|
||||
@ -1,9 +1,13 @@
|
||||
// @ts-ignore
|
||||
import clipboardScript from "./scripts/clipboard.inline"
|
||||
import clipboardStyle from "./styles/clipboard.scss"
|
||||
import { QuartzComponent, QuartzComponentConstructor, QuartzComponentProps } from "./types"
|
||||
import {
|
||||
QuartzComponent,
|
||||
QuartzComponentConstructor,
|
||||
QuartzComponentProps,
|
||||
} from "./types"
|
||||
|
||||
const Body: QuartzComponent = ({ children }: QuartzComponentProps) => {
|
||||
const Body: QuartzComponent = ({children}: QuartzComponentProps) => {
|
||||
return <div id="quartz-body">{children}</div>
|
||||
}
|
||||
|
||||
|
||||
@ -1,8 +1,12 @@
|
||||
import { QuartzComponent, QuartzComponentConstructor, QuartzComponentProps } from "./types"
|
||||
import {
|
||||
QuartzComponent,
|
||||
QuartzComponentConstructor,
|
||||
QuartzComponentProps,
|
||||
} from "./types"
|
||||
import breadcrumbsStyle from "./styles/breadcrumbs.scss"
|
||||
import { FullSlug, SimpleSlug, joinSegments, resolveRelative } from "../util/path"
|
||||
import { QuartzPluginData } from "../plugins/vfile"
|
||||
import { classNames } from "../util/lang"
|
||||
import {FullSlug, SimpleSlug, joinSegments, resolveRelative} from "../util/path"
|
||||
import {QuartzPluginData} from "../plugins/vfile"
|
||||
import {classNames} from "../util/lang"
|
||||
|
||||
type CrumbData = {
|
||||
displayName: string
|
||||
@ -40,7 +44,11 @@ const defaultOptions: BreadcrumbOptions = {
|
||||
showCurrentPage: true,
|
||||
}
|
||||
|
||||
function formatCrumb(displayName: string, baseSlug: FullSlug, currentSlug: SimpleSlug): CrumbData {
|
||||
function formatCrumb(
|
||||
displayName: string,
|
||||
baseSlug: FullSlug,
|
||||
currentSlug: SimpleSlug,
|
||||
): CrumbData {
|
||||
return {
|
||||
displayName: displayName.replaceAll("-", " "),
|
||||
path: resolveRelative(baseSlug, currentSlug),
|
||||
@ -49,7 +57,7 @@ function formatCrumb(displayName: string, baseSlug: FullSlug, currentSlug: Simpl
|
||||
|
||||
export default ((opts?: Partial<BreadcrumbOptions>) => {
|
||||
// Merge options with defaults
|
||||
const options: BreadcrumbOptions = { ...defaultOptions, ...opts }
|
||||
const options: BreadcrumbOptions = {...defaultOptions, ...opts}
|
||||
|
||||
// computed index of folder name to its associated file data
|
||||
let folderIndex: Map<string, QuartzPluginData> | undefined
|
||||
@ -65,7 +73,11 @@ export default ((opts?: Partial<BreadcrumbOptions>) => {
|
||||
}
|
||||
|
||||
// Format entry for root element
|
||||
const firstEntry = formatCrumb(options.rootName, fileData.slug!, "/" as SimpleSlug)
|
||||
const firstEntry = formatCrumb(
|
||||
options.rootName,
|
||||
fileData.slug!,
|
||||
"/" as SimpleSlug,
|
||||
)
|
||||
const crumbs: CrumbData[] = [firstEntry]
|
||||
|
||||
if (!folderIndex && options.resolveFrontmatterTitle) {
|
||||
@ -92,7 +104,9 @@ export default ((opts?: Partial<BreadcrumbOptions>) => {
|
||||
let curPathSegment = slugParts[i]
|
||||
|
||||
// Try to resolve frontmatter folder title
|
||||
const currentFile = folderIndex?.get(slugParts.slice(0, i + 1).join("/"))
|
||||
const currentFile = folderIndex?.get(
|
||||
slugParts.slice(0, i + 1).join("/"),
|
||||
)
|
||||
if (currentFile) {
|
||||
const title = currentFile.frontmatter!.title
|
||||
if (title !== "index") {
|
||||
@ -123,11 +137,15 @@ export default ((opts?: Partial<BreadcrumbOptions>) => {
|
||||
}
|
||||
|
||||
return (
|
||||
<nav class={classNames(displayClass, "breadcrumb-container")} aria-label="breadcrumbs">
|
||||
<nav
|
||||
class={classNames(displayClass, "breadcrumb-container")}
|
||||
aria-label="breadcrumbs">
|
||||
{crumbs.map((crumb, index) => (
|
||||
<div class="breadcrumb-element">
|
||||
<a href={crumb.path}>{crumb.displayName}</a>
|
||||
{index !== crumbs.length - 1 && <p>{` ${options.spacerSymbol} `}</p>}
|
||||
{index !== crumbs.length - 1 && (
|
||||
<p>{` ${options.spacerSymbol} `}</p>
|
||||
)}
|
||||
</div>
|
||||
))}
|
||||
</nav>
|
||||
|
||||
@ -1,5 +1,9 @@
|
||||
import { QuartzComponent, QuartzComponentConstructor, QuartzComponentProps } from "./types"
|
||||
import { classNames } from "../util/lang"
|
||||
import {
|
||||
QuartzComponent,
|
||||
QuartzComponentConstructor,
|
||||
QuartzComponentProps,
|
||||
} from "./types"
|
||||
import {classNames} from "../util/lang"
|
||||
// @ts-ignore
|
||||
import script from "./scripts/comments.inline"
|
||||
|
||||
@ -22,7 +26,10 @@ function boolToStringBool(b: boolean): string {
|
||||
}
|
||||
|
||||
export default ((opts: Options) => {
|
||||
const Comments: QuartzComponent = ({ displayClass, cfg }: QuartzComponentProps) => {
|
||||
const Comments: QuartzComponent = ({
|
||||
displayClass,
|
||||
cfg,
|
||||
}: QuartzComponentProps) => {
|
||||
return (
|
||||
<div
|
||||
class={classNames(displayClass, "giscus")}
|
||||
@ -32,9 +39,10 @@ export default ((opts: Options) => {
|
||||
data-category-id={opts.options.categoryId}
|
||||
data-mapping={opts.options.mapping ?? "url"}
|
||||
data-strict={boolToStringBool(opts.options.strict ?? true)}
|
||||
data-reactions-enabled={boolToStringBool(opts.options.reactionsEnabled ?? true)}
|
||||
data-input-position={opts.options.inputPosition ?? "bottom"}
|
||||
></div>
|
||||
data-reactions-enabled={boolToStringBool(
|
||||
opts.options.reactionsEnabled ?? true,
|
||||
)}
|
||||
data-input-position={opts.options.inputPosition ?? "bottom"}></div>
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
import { formatDate, getDate } from "./Date"
|
||||
import { QuartzComponentConstructor, QuartzComponentProps } from "./types"
|
||||
import {formatDate, getDate} from "./Date"
|
||||
import {QuartzComponentConstructor, QuartzComponentProps} from "./types"
|
||||
import readingTime from "reading-time"
|
||||
import { classNames } from "../util/lang"
|
||||
import { i18n } from "../i18n"
|
||||
import { JSX } from "preact"
|
||||
import {classNames} from "../util/lang"
|
||||
import {i18n} from "../i18n"
|
||||
import {JSX} from "preact"
|
||||
import style from "./styles/contentMeta.scss"
|
||||
|
||||
interface ContentMetaOptions {
|
||||
@ -21,9 +21,13 @@ const defaultOptions: ContentMetaOptions = {
|
||||
|
||||
export default ((opts?: Partial<ContentMetaOptions>) => {
|
||||
// Merge options with defaults
|
||||
const options: ContentMetaOptions = { ...defaultOptions, ...opts }
|
||||
const options: ContentMetaOptions = {...defaultOptions, ...opts}
|
||||
|
||||
function ContentMetadata({ cfg, fileData, displayClass }: QuartzComponentProps) {
|
||||
function ContentMetadata({
|
||||
cfg,
|
||||
fileData,
|
||||
displayClass,
|
||||
}: QuartzComponentProps) {
|
||||
const text = fileData.text
|
||||
|
||||
if (text) {
|
||||
@ -35,8 +39,10 @@ export default ((opts?: Partial<ContentMetaOptions>) => {
|
||||
|
||||
// Display reading time if enabled
|
||||
if (options.showReadingTime) {
|
||||
const { minutes, words: _words } = readingTime(text)
|
||||
const displayedTime = i18n(cfg.locale).components.contentMeta.readingTime({
|
||||
const {minutes, words: _words} = readingTime(text)
|
||||
const displayedTime = i18n(
|
||||
cfg.locale,
|
||||
).components.contentMeta.readingTime({
|
||||
minutes: Math.ceil(minutes),
|
||||
})
|
||||
segments.push(displayedTime)
|
||||
@ -45,7 +51,9 @@ export default ((opts?: Partial<ContentMetaOptions>) => {
|
||||
const segmentsElements = segments.map((segment) => <span>{segment}</span>)
|
||||
|
||||
return (
|
||||
<p show-comma={options.showComma} class={classNames(displayClass, "content-meta")}>
|
||||
<p
|
||||
show-comma={options.showComma}
|
||||
class={classNames(displayClass, "content-meta")}>
|
||||
{segmentsElements}
|
||||
</p>
|
||||
)
|
||||
|
||||
@ -3,14 +3,26 @@
|
||||
// see: https://v8.dev/features/modules#defer
|
||||
import darkmodeScript from "./scripts/darkmode.inline"
|
||||
import styles from "./styles/darkmode.scss"
|
||||
import { QuartzComponent, QuartzComponentConstructor, QuartzComponentProps } from "./types"
|
||||
import { i18n } from "../i18n"
|
||||
import { classNames } from "../util/lang"
|
||||
import {
|
||||
QuartzComponent,
|
||||
QuartzComponentConstructor,
|
||||
QuartzComponentProps,
|
||||
} from "./types"
|
||||
import {i18n} from "../i18n"
|
||||
import {classNames} from "../util/lang"
|
||||
|
||||
const Darkmode: QuartzComponent = ({ displayClass, cfg }: QuartzComponentProps) => {
|
||||
const Darkmode: QuartzComponent = ({
|
||||
displayClass,
|
||||
cfg,
|
||||
}: QuartzComponentProps) => {
|
||||
return (
|
||||
<div class={classNames(displayClass, "darkmode")}>
|
||||
<input class="toggle" id="darkmode-toggle" type="checkbox" tabIndex={-1} />
|
||||
<input
|
||||
class="toggle"
|
||||
id="darkmode-toggle"
|
||||
type="checkbox"
|
||||
tabIndex={-1}
|
||||
/>
|
||||
<label id="toggle-label-light" for="darkmode-toggle" tabIndex={-1}>
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
@ -21,8 +33,7 @@ const Darkmode: QuartzComponent = ({ displayClass, cfg }: QuartzComponentProps)
|
||||
y="0px"
|
||||
viewBox="0 0 35 35"
|
||||
style="enable-background:new 0 0 35 35"
|
||||
xmlSpace="preserve"
|
||||
>
|
||||
xmlSpace="preserve">
|
||||
<title>{i18n(cfg.locale).components.themeToggle.darkMode}</title>
|
||||
<path d="M6,17.5C6,16.672,5.328,16,4.5,16h-3C0.672,16,0,16.672,0,17.5 S0.672,19,1.5,19h3C5.328,19,6,18.328,6,17.5z M7.5,26c-0.414,0-0.789,0.168-1.061,0.439l-2,2C4.168,28.711,4,29.086,4,29.5 C4,30.328,4.671,31,5.5,31c0.414,0,0.789-0.168,1.06-0.44l2-2C8.832,28.289,9,27.914,9,27.5C9,26.672,8.329,26,7.5,26z M17.5,6 C18.329,6,19,5.328,19,4.5v-3C19,0.672,18.329,0,17.5,0S16,0.672,16,1.5v3C16,5.328,16.671,6,17.5,6z M27.5,9 c0.414,0,0.789-0.168,1.06-0.439l2-2C30.832,6.289,31,5.914,31,5.5C31,4.672,30.329,4,29.5,4c-0.414,0-0.789,0.168-1.061,0.44 l-2,2C26.168,6.711,26,7.086,26,7.5C26,8.328,26.671,9,27.5,9z M6.439,8.561C6.711,8.832,7.086,9,7.5,9C8.328,9,9,8.328,9,7.5 c0-0.414-0.168-0.789-0.439-1.061l-2-2C6.289,4.168,5.914,4,5.5,4C4.672,4,4,4.672,4,5.5c0,0.414,0.168,0.789,0.439,1.06 L6.439,8.561z M33.5,16h-3c-0.828,0-1.5,0.672-1.5,1.5s0.672,1.5,1.5,1.5h3c0.828,0,1.5-0.672,1.5-1.5S34.328,16,33.5,16z M28.561,26.439C28.289,26.168,27.914,26,27.5,26c-0.828,0-1.5,0.672-1.5,1.5c0,0.414,0.168,0.789,0.439,1.06l2,2 C28.711,30.832,29.086,31,29.5,31c0.828,0,1.5-0.672,1.5-1.5c0-0.414-0.168-0.789-0.439-1.061L28.561,26.439z M17.5,29 c-0.829,0-1.5,0.672-1.5,1.5v3c0,0.828,0.671,1.5,1.5,1.5s1.5-0.672,1.5-1.5v-3C19,29.672,18.329,29,17.5,29z M17.5,7 C11.71,7,7,11.71,7,17.5S11.71,28,17.5,28S28,23.29,28,17.5S23.29,7,17.5,7z M17.5,25c-4.136,0-7.5-3.364-7.5-7.5 c0-4.136,3.364-7.5,7.5-7.5c4.136,0,7.5,3.364,7.5,7.5C25,21.636,21.636,25,17.5,25z"></path>
|
||||
</svg>
|
||||
@ -37,8 +48,7 @@ const Darkmode: QuartzComponent = ({ displayClass, cfg }: QuartzComponentProps)
|
||||
y="0px"
|
||||
viewBox="0 0 100 100"
|
||||
style="enable-background:new 0 0 100 100"
|
||||
xmlSpace="preserve"
|
||||
>
|
||||
xmlSpace="preserve">
|
||||
<title>{i18n(cfg.locale).components.themeToggle.lightMode}</title>
|
||||
<path d="M96.76,66.458c-0.853-0.852-2.15-1.064-3.23-0.534c-6.063,2.991-12.858,4.571-19.655,4.571 C62.022,70.495,50.88,65.88,42.5,57.5C29.043,44.043,25.658,23.536,34.076,6.47c0.532-1.08,0.318-2.379-0.534-3.23 c-0.851-0.852-2.15-1.064-3.23-0.534c-4.918,2.427-9.375,5.619-13.246,9.491c-9.447,9.447-14.65,22.008-14.65,35.369 c0,13.36,5.203,25.921,14.65,35.368s22.008,14.65,35.368,14.65c13.361,0,25.921-5.203,35.369-14.65 c3.872-3.871,7.064-8.328,9.491-13.246C97.826,68.608,97.611,67.309,96.76,66.458z"></path>
|
||||
</svg>
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import { GlobalConfiguration } from "../cfg"
|
||||
import { ValidLocale } from "../i18n"
|
||||
import { QuartzPluginData } from "../plugins/vfile"
|
||||
import {GlobalConfiguration} from "../cfg"
|
||||
import {ValidLocale} from "../i18n"
|
||||
import {QuartzPluginData} from "../plugins/vfile"
|
||||
|
||||
interface Props {
|
||||
date: Date
|
||||
@ -9,7 +9,10 @@ interface Props {
|
||||
|
||||
export type ValidDateType = keyof Required<QuartzPluginData>["dates"]
|
||||
|
||||
export function getDate(cfg: GlobalConfiguration, data: QuartzPluginData): Date | undefined {
|
||||
export function getDate(
|
||||
cfg: GlobalConfiguration,
|
||||
data: QuartzPluginData,
|
||||
): Date | undefined {
|
||||
if (!cfg.defaultDateType) {
|
||||
throw new Error(
|
||||
`Field 'defaultDateType' was not set in the configuration object of quartz.config.ts. See https://quartz.jzhao.xyz/configuration#general-configuration for more details.`,
|
||||
@ -26,6 +29,6 @@ export function formatDate(d: Date, locale: ValidLocale = "en-US"): string {
|
||||
})
|
||||
}
|
||||
|
||||
export function Date({ date, locale }: Props) {
|
||||
export function Date({date, locale}: Props) {
|
||||
return <>{formatDate(date, locale)}</>
|
||||
}
|
||||
|
||||
@ -1,4 +1,8 @@
|
||||
import { QuartzComponent, QuartzComponentConstructor, QuartzComponentProps } from "./types"
|
||||
import {
|
||||
QuartzComponent,
|
||||
QuartzComponentConstructor,
|
||||
QuartzComponentProps,
|
||||
} from "./types"
|
||||
|
||||
export default ((component?: QuartzComponent) => {
|
||||
if (component) {
|
||||
|
||||
@ -1,12 +1,16 @@
|
||||
import { QuartzComponent, QuartzComponentConstructor, QuartzComponentProps } from "./types"
|
||||
import {
|
||||
QuartzComponent,
|
||||
QuartzComponentConstructor,
|
||||
QuartzComponentProps,
|
||||
} from "./types"
|
||||
import explorerStyle from "./styles/explorer.scss"
|
||||
|
||||
// @ts-ignore
|
||||
import script from "./scripts/explorer.inline"
|
||||
import { ExplorerNode, FileNode, Options } from "./ExplorerNode"
|
||||
import { QuartzPluginData } from "../plugins/vfile"
|
||||
import { classNames } from "../util/lang"
|
||||
import { i18n } from "../i18n"
|
||||
import {ExplorerNode, FileNode, Options} from "./ExplorerNode"
|
||||
import {QuartzPluginData} from "../plugins/vfile"
|
||||
import {classNames} from "../util/lang"
|
||||
import {i18n} from "../i18n"
|
||||
|
||||
// Options interface defined in `ExplorerNode` to avoid circular dependency
|
||||
const defaultOptions = {
|
||||
@ -39,7 +43,7 @@ const defaultOptions = {
|
||||
|
||||
export default ((userOpts?: Partial<Options>) => {
|
||||
// Parse config
|
||||
const opts: Options = { ...defaultOptions, ...userOpts }
|
||||
const opts: Options = {...defaultOptions, ...userOpts}
|
||||
|
||||
// memoized
|
||||
let fileTree: FileNode
|
||||
@ -68,7 +72,9 @@ export default ((userOpts?: Partial<Options>) => {
|
||||
|
||||
// Get all folders of tree. Initialize with collapsed state
|
||||
// Stringify to pass json tree as data attribute ([data-tree])
|
||||
const folders = fileTree.getFolderPaths(opts.folderDefaultState === "collapsed")
|
||||
const folders = fileTree.getFolderPaths(
|
||||
opts.folderDefaultState === "collapsed",
|
||||
)
|
||||
jsonTree = JSON.stringify(folders)
|
||||
}
|
||||
|
||||
@ -94,8 +100,7 @@ export default ((userOpts?: Partial<Options>) => {
|
||||
data-savestate={opts.useSavedState}
|
||||
data-tree={jsonTree}
|
||||
aria-controls="explorer-content"
|
||||
aria-expanded={opts.folderDefaultState === "open"}
|
||||
>
|
||||
aria-expanded={opts.folderDefaultState === "open"}>
|
||||
<h2>{opts.title ?? i18n(cfg.locale).components.explorer.title}</h2>
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
@ -107,8 +112,7 @@ export default ((userOpts?: Partial<Options>) => {
|
||||
stroke-width="2"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
class="fold"
|
||||
>
|
||||
class="fold">
|
||||
<polyline points="6 9 12 15 18 9"></polyline>
|
||||
</svg>
|
||||
</button>
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
// @ts-ignore
|
||||
import { QuartzPluginData } from "../plugins/vfile"
|
||||
import {QuartzPluginData} from "../plugins/vfile"
|
||||
import {
|
||||
joinSegments,
|
||||
resolveRelative,
|
||||
@ -32,7 +32,10 @@ export type FolderState = {
|
||||
collapsed: boolean
|
||||
}
|
||||
|
||||
function getPathSegment(fp: FilePath | undefined, idx: number): string | undefined {
|
||||
function getPathSegment(
|
||||
fp: FilePath | undefined,
|
||||
idx: number,
|
||||
): string | undefined {
|
||||
if (!fp) {
|
||||
return undefined
|
||||
}
|
||||
@ -48,7 +51,12 @@ export class FileNode {
|
||||
file: QuartzPluginData | null
|
||||
depth: number
|
||||
|
||||
constructor(slugSegment: string, displayName?: string, file?: QuartzPluginData, depth?: number) {
|
||||
constructor(
|
||||
slugSegment: string,
|
||||
displayName?: string,
|
||||
file?: QuartzPluginData,
|
||||
depth?: number,
|
||||
) {
|
||||
this.children = []
|
||||
this.name = slugSegment
|
||||
this.displayName = displayName ?? file?.frontmatter?.title ?? slugSegment
|
||||
@ -73,7 +81,9 @@ export class FileNode {
|
||||
}
|
||||
} else {
|
||||
// direct child
|
||||
this.children.push(new FileNode(nextSegment, undefined, fileData.file, this.depth + 1))
|
||||
this.children.push(
|
||||
new FileNode(nextSegment, undefined, fileData.file, this.depth + 1),
|
||||
)
|
||||
}
|
||||
|
||||
return
|
||||
@ -99,7 +109,7 @@ export class FileNode {
|
||||
|
||||
// Add new file to tree
|
||||
add(file: QuartzPluginData) {
|
||||
this.insert({ file: file, path: simplifySlug(file.slug!).split("/") })
|
||||
this.insert({file: file, path: simplifySlug(file.slug!).split("/")})
|
||||
}
|
||||
|
||||
/**
|
||||
@ -133,7 +143,7 @@ export class FileNode {
|
||||
if (!node.file) {
|
||||
const folderPath = joinSegments(currentPath, node.name)
|
||||
if (folderPath !== "") {
|
||||
folderPaths.push({ path: folderPath, collapsed })
|
||||
folderPaths.push({path: folderPath, collapsed})
|
||||
}
|
||||
|
||||
node.children.forEach((child) => traverse(child, folderPath))
|
||||
@ -162,13 +172,19 @@ type ExplorerNodeProps = {
|
||||
fullPath?: string
|
||||
}
|
||||
|
||||
export function ExplorerNode({ node, opts, fullPath, fileData }: ExplorerNodeProps) {
|
||||
export function ExplorerNode({
|
||||
node,
|
||||
opts,
|
||||
fullPath,
|
||||
fileData,
|
||||
}: ExplorerNodeProps) {
|
||||
// Get options
|
||||
const folderBehavior = opts.folderClickBehavior
|
||||
const isDefaultOpen = opts.folderDefaultState === "open"
|
||||
|
||||
// Calculate current folderPath
|
||||
const folderPath = node.name !== "" ? joinSegments(fullPath ?? "", node.name) : ""
|
||||
const folderPath =
|
||||
node.name !== "" ? joinSegments(fullPath ?? "", node.name) : ""
|
||||
const href = resolveRelative(fileData.slug!, folderPath as SimpleSlug) + "/"
|
||||
|
||||
return (
|
||||
@ -176,7 +192,9 @@ export function ExplorerNode({ node, opts, fullPath, fileData }: ExplorerNodePro
|
||||
{node.file ? (
|
||||
// Single file node
|
||||
<li key={node.file.slug}>
|
||||
<a href={resolveRelative(fileData.slug!, node.file.slug!)} data-for={node.file.slug}>
|
||||
<a
|
||||
href={resolveRelative(fileData.slug!, node.file.slug!)}
|
||||
data-for={node.file.slug}>
|
||||
{node.displayName}
|
||||
</a>
|
||||
</li>
|
||||
@ -196,8 +214,7 @@ export function ExplorerNode({ node, opts, fullPath, fileData }: ExplorerNodePro
|
||||
stroke-width="2"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
class="folder-icon"
|
||||
>
|
||||
class="folder-icon">
|
||||
<polyline points="6 9 12 15 18 9"></polyline>
|
||||
</svg>
|
||||
{/* render <a> tag if folderBehavior is "link", otherwise render <button> with collapse click event */}
|
||||
@ -215,15 +232,15 @@ export function ExplorerNode({ node, opts, fullPath, fileData }: ExplorerNodePro
|
||||
</div>
|
||||
)}
|
||||
{/* Recursively render children of folder */}
|
||||
<div class={`folder-outer ${node.depth === 0 || isDefaultOpen ? "open" : ""}`}>
|
||||
<div
|
||||
class={`folder-outer ${node.depth === 0 || isDefaultOpen ? "open" : ""}`}>
|
||||
<ul
|
||||
// Inline style for left folder paddings
|
||||
style={{
|
||||
paddingLeft: node.name !== "" ? "1.4rem" : "0",
|
||||
}}
|
||||
class="content"
|
||||
data-folderul={folderPath}
|
||||
>
|
||||
data-folderul={folderPath}>
|
||||
{node.children.map((childNode, i) => (
|
||||
<ExplorerNode
|
||||
node={childNode}
|
||||
|
||||
@ -1,14 +1,21 @@
|
||||
import { QuartzComponent, QuartzComponentConstructor, QuartzComponentProps } from "./types"
|
||||
import {
|
||||
QuartzComponent,
|
||||
QuartzComponentConstructor,
|
||||
QuartzComponentProps,
|
||||
} from "./types"
|
||||
import style from "./styles/footer.scss"
|
||||
import { version } from "../../package.json"
|
||||
import { i18n } from "../i18n"
|
||||
import {version} from "../../package.json"
|
||||
import {i18n} from "../i18n"
|
||||
|
||||
interface Options {
|
||||
links: Record<string, string>
|
||||
}
|
||||
|
||||
export default ((opts?: Options) => {
|
||||
const Footer: QuartzComponent = ({ displayClass, cfg }: QuartzComponentProps) => {
|
||||
const Footer: QuartzComponent = ({
|
||||
displayClass,
|
||||
cfg,
|
||||
}: QuartzComponentProps) => {
|
||||
const year = new Date().getFullYear()
|
||||
const links = opts?.links ?? []
|
||||
return (
|
||||
|
||||
@ -1,9 +1,13 @@
|
||||
import { QuartzComponent, QuartzComponentConstructor, QuartzComponentProps } from "./types"
|
||||
import {
|
||||
QuartzComponent,
|
||||
QuartzComponentConstructor,
|
||||
QuartzComponentProps,
|
||||
} from "./types"
|
||||
// @ts-ignore
|
||||
import script from "./scripts/graph.inline"
|
||||
import style from "./styles/graph.scss"
|
||||
import { i18n } from "../i18n"
|
||||
import { classNames } from "../util/lang"
|
||||
import {i18n} from "../i18n"
|
||||
import {classNames} from "../util/lang"
|
||||
|
||||
export interface D3Config {
|
||||
drag: boolean
|
||||
@ -57,9 +61,12 @@ const defaultOptions: GraphOptions = {
|
||||
}
|
||||
|
||||
export default ((opts?: GraphOptions) => {
|
||||
const Graph: QuartzComponent = ({ displayClass, cfg }: QuartzComponentProps) => {
|
||||
const localGraph = { ...defaultOptions.localGraph, ...opts?.localGraph }
|
||||
const globalGraph = { ...defaultOptions.globalGraph, ...opts?.globalGraph }
|
||||
const Graph: QuartzComponent = ({
|
||||
displayClass,
|
||||
cfg,
|
||||
}: QuartzComponentProps) => {
|
||||
const localGraph = {...defaultOptions.localGraph, ...opts?.localGraph}
|
||||
const globalGraph = {...defaultOptions.globalGraph, ...opts?.globalGraph}
|
||||
return (
|
||||
<div class={classNames(displayClass, "graph")}>
|
||||
<h3>{i18n(cfg.locale).components.graph.title}</h3>
|
||||
@ -74,8 +81,7 @@ export default ((opts?: GraphOptions) => {
|
||||
y="0px"
|
||||
viewBox="0 0 55 55"
|
||||
fill="currentColor"
|
||||
xmlSpace="preserve"
|
||||
>
|
||||
xmlSpace="preserve">
|
||||
<path
|
||||
d="M49,0c-3.309,0-6,2.691-6,6c0,1.035,0.263,2.009,0.726,2.86l-9.829,9.829C32.542,17.634,30.846,17,29,17
|
||||
s-3.542,0.634-4.898,1.688l-7.669-7.669C16.785,10.424,17,9.74,17,9c0-2.206-1.794-4-4-4S9,6.794,9,9s1.794,4,4,4
|
||||
@ -92,7 +98,9 @@ export default ((opts?: GraphOptions) => {
|
||||
</svg>
|
||||
</div>
|
||||
<div id="global-graph-outer">
|
||||
<div id="global-graph-container" data-cfg={JSON.stringify(globalGraph)}></div>
|
||||
<div
|
||||
id="global-graph-container"
|
||||
data-cfg={JSON.stringify(globalGraph)}></div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
|
||||
@ -1,15 +1,25 @@
|
||||
import { i18n } from "../i18n"
|
||||
import { FullSlug, joinSegments, pathToRoot } from "../util/path"
|
||||
import { JSResourceToScriptElement } from "../util/resources"
|
||||
import { googleFontHref } from "../util/theme"
|
||||
import { QuartzComponent, QuartzComponentConstructor, QuartzComponentProps } from "./types"
|
||||
import {i18n} from "../i18n"
|
||||
import {FullSlug, joinSegments, pathToRoot} from "../util/path"
|
||||
import {JSResourceToScriptElement} from "../util/resources"
|
||||
import {googleFontHref} from "../util/theme"
|
||||
import {
|
||||
QuartzComponent,
|
||||
QuartzComponentConstructor,
|
||||
QuartzComponentProps,
|
||||
} from "./types"
|
||||
|
||||
export default (() => {
|
||||
const Head: QuartzComponent = ({ cfg, fileData, externalResources }: QuartzComponentProps) => {
|
||||
const title = fileData.frontmatter?.title ?? i18n(cfg.locale).propertyDefaults.title
|
||||
const Head: QuartzComponent = ({
|
||||
cfg,
|
||||
fileData,
|
||||
externalResources,
|
||||
}: QuartzComponentProps) => {
|
||||
const title =
|
||||
fileData.frontmatter?.title ?? i18n(cfg.locale).propertyDefaults.title
|
||||
const description =
|
||||
fileData.description?.trim() ?? i18n(cfg.locale).propertyDefaults.description
|
||||
const { css, js } = externalResources
|
||||
fileData.description?.trim() ??
|
||||
i18n(cfg.locale).propertyDefaults.description
|
||||
const {css, js} = externalResources
|
||||
|
||||
const url = new URL(`https://${cfg.baseUrl ?? "example.com"}`)
|
||||
const path = url.pathname as FullSlug
|
||||
@ -39,7 +49,13 @@ export default (() => {
|
||||
<meta name="description" content={description} />
|
||||
<meta name="generator" content="Quartz" />
|
||||
{css.map((href) => (
|
||||
<link key={href} href={href} rel="stylesheet" type="text/css" spa-preserve />
|
||||
<link
|
||||
key={href}
|
||||
href={href}
|
||||
rel="stylesheet"
|
||||
type="text/css"
|
||||
spa-preserve
|
||||
/>
|
||||
))}
|
||||
{js
|
||||
.filter((resource) => resource.loadTime === "beforeDOMReady")
|
||||
|
||||
@ -1,6 +1,10 @@
|
||||
import { QuartzComponent, QuartzComponentConstructor, QuartzComponentProps } from "./types"
|
||||
import {
|
||||
QuartzComponent,
|
||||
QuartzComponentConstructor,
|
||||
QuartzComponentProps,
|
||||
} from "./types"
|
||||
|
||||
const Header: QuartzComponent = ({ children }: QuartzComponentProps) => {
|
||||
const Header: QuartzComponent = ({children}: QuartzComponentProps) => {
|
||||
return children.length > 0 ? <header>{children}</header> : null
|
||||
}
|
||||
|
||||
|
||||
@ -1,4 +1,8 @@
|
||||
import { QuartzComponent, QuartzComponentConstructor, QuartzComponentProps } from "./types"
|
||||
import {
|
||||
QuartzComponent,
|
||||
QuartzComponentConstructor,
|
||||
QuartzComponentProps,
|
||||
} from "./types"
|
||||
|
||||
export default ((component?: QuartzComponent) => {
|
||||
if (component) {
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
import { FullSlug, resolveRelative } from "../util/path"
|
||||
import { QuartzPluginData } from "../plugins/vfile"
|
||||
import { Date, getDate } from "./Date"
|
||||
import { QuartzComponent, QuartzComponentProps } from "./types"
|
||||
import { GlobalConfiguration } from "../cfg"
|
||||
import {FullSlug, resolveRelative} from "../util/path"
|
||||
import {QuartzPluginData} from "../plugins/vfile"
|
||||
import {Date, getDate} from "./Date"
|
||||
import {QuartzComponent, QuartzComponentProps} from "./types"
|
||||
import {GlobalConfiguration} from "../cfg"
|
||||
|
||||
export type SortFn = (f1: QuartzPluginData, f2: QuartzPluginData) => number
|
||||
|
||||
@ -30,7 +30,13 @@ type Props = {
|
||||
sort?: SortFn
|
||||
} & QuartzComponentProps
|
||||
|
||||
export const PageList: QuartzComponent = ({ cfg, fileData, allFiles, limit, sort }: Props) => {
|
||||
export const PageList: QuartzComponent = ({
|
||||
cfg,
|
||||
fileData,
|
||||
allFiles,
|
||||
limit,
|
||||
sort,
|
||||
}: Props) => {
|
||||
const sorter = sort ?? byDateAndAlphabetical(cfg)
|
||||
let list = allFiles.sort(sorter)
|
||||
if (limit) {
|
||||
@ -53,7 +59,9 @@ export const PageList: QuartzComponent = ({ cfg, fileData, allFiles, limit, sort
|
||||
)}
|
||||
<div class="desc">
|
||||
<h3>
|
||||
<a href={resolveRelative(fileData.slug!, page.slug!)} class="internal">
|
||||
<a
|
||||
href={resolveRelative(fileData.slug!, page.slug!)}
|
||||
class="internal">
|
||||
{title}
|
||||
</a>
|
||||
</h3>
|
||||
@ -63,8 +71,10 @@ export const PageList: QuartzComponent = ({ cfg, fileData, allFiles, limit, sort
|
||||
<li>
|
||||
<a
|
||||
class="internal tag-link"
|
||||
href={resolveRelative(fileData.slug!, `tags/${tag}` as FullSlug)}
|
||||
>
|
||||
href={resolveRelative(
|
||||
fileData.slug!,
|
||||
`tags/${tag}` as FullSlug,
|
||||
)}>
|
||||
{tag}
|
||||
</a>
|
||||
</li>
|
||||
|
||||
@ -1,9 +1,17 @@
|
||||
import { pathToRoot } from "../util/path"
|
||||
import { QuartzComponent, QuartzComponentConstructor, QuartzComponentProps } from "./types"
|
||||
import { classNames } from "../util/lang"
|
||||
import { i18n } from "../i18n"
|
||||
import {pathToRoot} from "../util/path"
|
||||
import {
|
||||
QuartzComponent,
|
||||
QuartzComponentConstructor,
|
||||
QuartzComponentProps,
|
||||
} from "./types"
|
||||
import {classNames} from "../util/lang"
|
||||
import {i18n} from "../i18n"
|
||||
|
||||
const PageTitle: QuartzComponent = ({ fileData, cfg, displayClass }: QuartzComponentProps) => {
|
||||
const PageTitle: QuartzComponent = ({
|
||||
fileData,
|
||||
cfg,
|
||||
displayClass,
|
||||
}: QuartzComponentProps) => {
|
||||
const title = cfg?.pageTitle ?? i18n(cfg.locale).propertyDefaults.title
|
||||
const baseDir = pathToRoot(fileData.slug!)
|
||||
return (
|
||||
|
||||
@ -1,12 +1,16 @@
|
||||
import { QuartzComponent, QuartzComponentConstructor, QuartzComponentProps } from "./types"
|
||||
import { FullSlug, SimpleSlug, resolveRelative } from "../util/path"
|
||||
import { QuartzPluginData } from "../plugins/vfile"
|
||||
import { byDateAndAlphabetical } from "./PageList"
|
||||
import {
|
||||
QuartzComponent,
|
||||
QuartzComponentConstructor,
|
||||
QuartzComponentProps,
|
||||
} from "./types"
|
||||
import {FullSlug, SimpleSlug, resolveRelative} from "../util/path"
|
||||
import {QuartzPluginData} from "../plugins/vfile"
|
||||
import {byDateAndAlphabetical} from "./PageList"
|
||||
import style from "./styles/recentNotes.scss"
|
||||
import { Date, getDate } from "./Date"
|
||||
import { GlobalConfiguration } from "../cfg"
|
||||
import { i18n } from "../i18n"
|
||||
import { classNames } from "../util/lang"
|
||||
import {Date, getDate} from "./Date"
|
||||
import {GlobalConfiguration} from "../cfg"
|
||||
import {i18n} from "../i18n"
|
||||
import {classNames} from "../util/lang"
|
||||
|
||||
interface Options {
|
||||
title?: string
|
||||
@ -32,7 +36,7 @@ export default ((userOpts?: Partial<Options>) => {
|
||||
displayClass,
|
||||
cfg,
|
||||
}: QuartzComponentProps) => {
|
||||
const opts = { ...defaultOptions(cfg), ...userOpts }
|
||||
const opts = {...defaultOptions(cfg), ...userOpts}
|
||||
const pages = allFiles.filter(opts.filter).sort(opts.sort)
|
||||
const remaining = Math.max(0, pages.length - opts.limit)
|
||||
return (
|
||||
@ -40,7 +44,8 @@ export default ((userOpts?: Partial<Options>) => {
|
||||
<h3>{opts.title ?? i18n(cfg.locale).components.recentNotes.title}</h3>
|
||||
<ul class="recent-ul">
|
||||
{pages.slice(0, opts.limit).map((page) => {
|
||||
const title = page.frontmatter?.title ?? i18n(cfg.locale).propertyDefaults.title
|
||||
const title =
|
||||
page.frontmatter?.title ?? i18n(cfg.locale).propertyDefaults.title
|
||||
const tags = page.frontmatter?.tags ?? []
|
||||
|
||||
return (
|
||||
@ -48,7 +53,9 @@ export default ((userOpts?: Partial<Options>) => {
|
||||
<div class="section">
|
||||
<div class="desc">
|
||||
<h3>
|
||||
<a href={resolveRelative(fileData.slug!, page.slug!)} class="internal">
|
||||
<a
|
||||
href={resolveRelative(fileData.slug!, page.slug!)}
|
||||
class="internal">
|
||||
{title}
|
||||
</a>
|
||||
</h3>
|
||||
@ -64,8 +71,10 @@ export default ((userOpts?: Partial<Options>) => {
|
||||
<li>
|
||||
<a
|
||||
class="internal tag-link"
|
||||
href={resolveRelative(fileData.slug!, `tags/${tag}` as FullSlug)}
|
||||
>
|
||||
href={resolveRelative(
|
||||
fileData.slug!,
|
||||
`tags/${tag}` as FullSlug,
|
||||
)}>
|
||||
{tag}
|
||||
</a>
|
||||
</li>
|
||||
@ -80,7 +89,9 @@ export default ((userOpts?: Partial<Options>) => {
|
||||
{opts.linkToMore && remaining > 0 && (
|
||||
<p>
|
||||
<a href={resolveRelative(fileData.slug!, opts.linkToMore)}>
|
||||
{i18n(cfg.locale).components.recentNotes.seeRemainingMore({ remaining })}
|
||||
{i18n(cfg.locale).components.recentNotes.seeRemainingMore({
|
||||
remaining,
|
||||
})}
|
||||
</a>
|
||||
</p>
|
||||
)}
|
||||
|
||||
@ -1,9 +1,13 @@
|
||||
import { QuartzComponent, QuartzComponentConstructor, QuartzComponentProps } from "./types"
|
||||
import {
|
||||
QuartzComponent,
|
||||
QuartzComponentConstructor,
|
||||
QuartzComponentProps,
|
||||
} from "./types"
|
||||
import style from "./styles/search.scss"
|
||||
// @ts-ignore
|
||||
import script from "./scripts/search.inline"
|
||||
import { classNames } from "../util/lang"
|
||||
import { i18n } from "../i18n"
|
||||
import {classNames} from "../util/lang"
|
||||
import {i18n} from "../i18n"
|
||||
|
||||
export interface SearchOptions {
|
||||
enablePreview: boolean
|
||||
@ -14,14 +18,21 @@ const defaultOptions: SearchOptions = {
|
||||
}
|
||||
|
||||
export default ((userOpts?: Partial<SearchOptions>) => {
|
||||
const Search: QuartzComponent = ({ displayClass, cfg }: QuartzComponentProps) => {
|
||||
const opts = { ...defaultOptions, ...userOpts }
|
||||
const searchPlaceholder = i18n(cfg.locale).components.search.searchBarPlaceholder
|
||||
const Search: QuartzComponent = ({
|
||||
displayClass,
|
||||
cfg,
|
||||
}: QuartzComponentProps) => {
|
||||
const opts = {...defaultOptions, ...userOpts}
|
||||
const searchPlaceholder = i18n(cfg.locale).components.search
|
||||
.searchBarPlaceholder
|
||||
return (
|
||||
<div class={classNames(displayClass, "search")}>
|
||||
<button class="search-button" id="search-button">
|
||||
<p>{i18n(cfg.locale).components.search.title}</p>
|
||||
<svg role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 19.9 19.7">
|
||||
<svg
|
||||
role="img"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
viewBox="0 0 19.9 19.7">
|
||||
<title>Search</title>
|
||||
<g class="search-path" fill="none">
|
||||
<path stroke-linecap="square" d="M18.5 18.3l-5.4-5.4" />
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import { QuartzComponentConstructor, QuartzComponentProps } from "./types"
|
||||
import { classNames } from "../util/lang"
|
||||
import {QuartzComponentConstructor, QuartzComponentProps} from "./types"
|
||||
import {classNames} from "../util/lang"
|
||||
|
||||
function Spacer({ displayClass }: QuartzComponentProps) {
|
||||
function Spacer({displayClass}: QuartzComponentProps) {
|
||||
return <div class={classNames(displayClass, "spacer")}></div>
|
||||
}
|
||||
|
||||
|
||||
@ -1,11 +1,15 @@
|
||||
import { QuartzComponent, QuartzComponentConstructor, QuartzComponentProps } from "./types"
|
||||
import {
|
||||
QuartzComponent,
|
||||
QuartzComponentConstructor,
|
||||
QuartzComponentProps,
|
||||
} from "./types"
|
||||
import legacyStyle from "./styles/legacyToc.scss"
|
||||
import modernStyle from "./styles/toc.scss"
|
||||
import { classNames } from "../util/lang"
|
||||
import {classNames} from "../util/lang"
|
||||
|
||||
// @ts-ignore
|
||||
import script from "./scripts/toc.inline"
|
||||
import { i18n } from "../i18n"
|
||||
import {i18n} from "../i18n"
|
||||
|
||||
interface Options {
|
||||
layout: "modern" | "legacy"
|
||||
@ -31,8 +35,7 @@ const TableOfContents: QuartzComponent = ({
|
||||
id="toc"
|
||||
class={fileData.collapseToc ? "collapsed" : ""}
|
||||
aria-controls="toc-content"
|
||||
aria-expanded={!fileData.collapseToc}
|
||||
>
|
||||
aria-expanded={!fileData.collapseToc}>
|
||||
<h3>{i18n(cfg.locale).components.tableOfContents.title}</h3>
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
@ -44,8 +47,7 @@ const TableOfContents: QuartzComponent = ({
|
||||
stroke-width="2"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
class="fold"
|
||||
>
|
||||
class="fold">
|
||||
<polyline points="6 9 12 15 18 9"></polyline>
|
||||
</svg>
|
||||
</button>
|
||||
@ -66,7 +68,10 @@ const TableOfContents: QuartzComponent = ({
|
||||
TableOfContents.css = modernStyle
|
||||
TableOfContents.afterDOMLoaded = script
|
||||
|
||||
const LegacyTableOfContents: QuartzComponent = ({ fileData, cfg }: QuartzComponentProps) => {
|
||||
const LegacyTableOfContents: QuartzComponent = ({
|
||||
fileData,
|
||||
cfg,
|
||||
}: QuartzComponentProps) => {
|
||||
if (!fileData.toc) {
|
||||
return null
|
||||
}
|
||||
|
||||
@ -1,8 +1,15 @@
|
||||
import { pathToRoot, slugTag } from "../util/path"
|
||||
import { QuartzComponent, QuartzComponentConstructor, QuartzComponentProps } from "./types"
|
||||
import { classNames } from "../util/lang"
|
||||
import {pathToRoot, slugTag} from "../util/path"
|
||||
import {
|
||||
QuartzComponent,
|
||||
QuartzComponentConstructor,
|
||||
QuartzComponentProps,
|
||||
} from "./types"
|
||||
import {classNames} from "../util/lang"
|
||||
|
||||
const TagList: QuartzComponent = ({ fileData, displayClass }: QuartzComponentProps) => {
|
||||
const TagList: QuartzComponent = ({
|
||||
fileData,
|
||||
displayClass,
|
||||
}: QuartzComponentProps) => {
|
||||
const tags = fileData.frontmatter?.tags
|
||||
const baseDir = pathToRoot(fileData.slug!)
|
||||
if (tags && tags.length > 0) {
|
||||
|
||||
@ -1,7 +1,11 @@
|
||||
import { i18n } from "../../i18n"
|
||||
import { QuartzComponent, QuartzComponentConstructor, QuartzComponentProps } from "../types"
|
||||
import {i18n} from "../../i18n"
|
||||
import {
|
||||
QuartzComponent,
|
||||
QuartzComponentConstructor,
|
||||
QuartzComponentProps,
|
||||
} from "../types"
|
||||
|
||||
const NotFound: QuartzComponent = ({ cfg }: QuartzComponentProps) => {
|
||||
const NotFound: QuartzComponent = ({cfg}: QuartzComponentProps) => {
|
||||
// If baseUrl contains a pathname after the domain, use this as the home link
|
||||
const url = new URL(`https://${cfg.baseUrl ?? "example.com"}`)
|
||||
const baseDir = url.pathname
|
||||
|
||||
@ -1,7 +1,11 @@
|
||||
import { htmlToJsx } from "../../util/jsx"
|
||||
import { QuartzComponent, QuartzComponentConstructor, QuartzComponentProps } from "../types"
|
||||
import {htmlToJsx} from "../../util/jsx"
|
||||
import {
|
||||
QuartzComponent,
|
||||
QuartzComponentConstructor,
|
||||
QuartzComponentProps,
|
||||
} from "../types"
|
||||
|
||||
const Content: QuartzComponent = ({ fileData, tree }: QuartzComponentProps) => {
|
||||
const Content: QuartzComponent = ({fileData, tree}: QuartzComponentProps) => {
|
||||
const content = htmlToJsx(fileData.filePath!, tree)
|
||||
const classes: string[] = fileData.frontmatter?.cssclasses ?? []
|
||||
const classString = ["popover-hint", ...classes].join(" ")
|
||||
|
||||
@ -1,12 +1,16 @@
|
||||
import { QuartzComponent, QuartzComponentConstructor, QuartzComponentProps } from "../types"
|
||||
import {
|
||||
QuartzComponent,
|
||||
QuartzComponentConstructor,
|
||||
QuartzComponentProps,
|
||||
} from "../types"
|
||||
import path from "path"
|
||||
|
||||
import style from "../styles/listPage.scss"
|
||||
import { PageList, SortFn } from "../PageList"
|
||||
import { stripSlashes, simplifySlug } from "../../util/path"
|
||||
import { Root } from "hast"
|
||||
import { htmlToJsx } from "../../util/jsx"
|
||||
import { i18n } from "../../i18n"
|
||||
import {PageList, SortFn} from "../PageList"
|
||||
import {stripSlashes, simplifySlug} from "../../util/path"
|
||||
import {Root} from "hast"
|
||||
import {htmlToJsx} from "../../util/jsx"
|
||||
import {i18n} from "../../i18n"
|
||||
|
||||
interface FolderContentOptions {
|
||||
/**
|
||||
@ -21,14 +25,15 @@ const defaultOptions: FolderContentOptions = {
|
||||
}
|
||||
|
||||
export default ((opts?: Partial<FolderContentOptions>) => {
|
||||
const options: FolderContentOptions = { ...defaultOptions, ...opts }
|
||||
const options: FolderContentOptions = {...defaultOptions, ...opts}
|
||||
|
||||
const FolderContent: QuartzComponent = (props: QuartzComponentProps) => {
|
||||
const { tree, fileData, allFiles, cfg } = props
|
||||
const {tree, fileData, allFiles, cfg} = props
|
||||
const folderSlug = stripSlashes(simplifySlug(fileData.slug!))
|
||||
const allPagesInFolder = allFiles.filter((file) => {
|
||||
const fileSlug = stripSlashes(simplifySlug(file.slug!))
|
||||
const prefixed = fileSlug.startsWith(folderSlug) && fileSlug !== folderSlug
|
||||
const prefixed =
|
||||
fileSlug.startsWith(folderSlug) && fileSlug !== folderSlug
|
||||
const folderParts = folderSlug.split(path.posix.sep)
|
||||
const fileParts = fileSlug.split(path.posix.sep)
|
||||
const isDirectChild = fileParts.length === folderParts.length + 1
|
||||
|
||||
@ -1,11 +1,15 @@
|
||||
import { QuartzComponent, QuartzComponentConstructor, QuartzComponentProps } from "../types"
|
||||
import {
|
||||
QuartzComponent,
|
||||
QuartzComponentConstructor,
|
||||
QuartzComponentProps,
|
||||
} from "../types"
|
||||
import style from "../styles/listPage.scss"
|
||||
import { PageList, SortFn } from "../PageList"
|
||||
import { FullSlug, getAllSegmentPrefixes, simplifySlug } from "../../util/path"
|
||||
import { QuartzPluginData } from "../../plugins/vfile"
|
||||
import { Root } from "hast"
|
||||
import { htmlToJsx } from "../../util/jsx"
|
||||
import { i18n } from "../../i18n"
|
||||
import {PageList, SortFn} from "../PageList"
|
||||
import {FullSlug, getAllSegmentPrefixes, simplifySlug} from "../../util/path"
|
||||
import {QuartzPluginData} from "../../plugins/vfile"
|
||||
import {Root} from "hast"
|
||||
import {htmlToJsx} from "../../util/jsx"
|
||||
import {i18n} from "../../i18n"
|
||||
|
||||
interface TagContentOptions {
|
||||
sort?: SortFn
|
||||
@ -17,20 +21,24 @@ const defaultOptions: TagContentOptions = {
|
||||
}
|
||||
|
||||
export default ((opts?: Partial<TagContentOptions>) => {
|
||||
const options: TagContentOptions = { ...defaultOptions, ...opts }
|
||||
const options: TagContentOptions = {...defaultOptions, ...opts}
|
||||
|
||||
const TagContent: QuartzComponent = (props: QuartzComponentProps) => {
|
||||
const { tree, fileData, allFiles, cfg } = props
|
||||
const {tree, fileData, allFiles, cfg} = props
|
||||
const slug = fileData.slug
|
||||
|
||||
if (!(slug?.startsWith("tags/") || slug === "tags")) {
|
||||
throw new Error(`Component "TagContent" tried to render a non-tag page: ${slug}`)
|
||||
throw new Error(
|
||||
`Component "TagContent" tried to render a non-tag page: ${slug}`,
|
||||
)
|
||||
}
|
||||
|
||||
const tag = simplifySlug(slug.slice("tags/".length) as FullSlug)
|
||||
const allPagesWithTag = (tag: string) =>
|
||||
allFiles.filter((file) =>
|
||||
(file.frontmatter?.tags ?? []).flatMap(getAllSegmentPrefixes).includes(tag),
|
||||
(file.frontmatter?.tags ?? [])
|
||||
.flatMap(getAllSegmentPrefixes)
|
||||
.includes(tag),
|
||||
)
|
||||
|
||||
const content =
|
||||
@ -42,7 +50,9 @@ export default ((opts?: Partial<TagContentOptions>) => {
|
||||
if (tag === "/") {
|
||||
const tags = [
|
||||
...new Set(
|
||||
allFiles.flatMap((data) => data.frontmatter?.tags ?? []).flatMap(getAllSegmentPrefixes),
|
||||
allFiles
|
||||
.flatMap((data) => data.frontmatter?.tags ?? [])
|
||||
.flatMap(getAllSegmentPrefixes),
|
||||
),
|
||||
].sort((a, b) => a.localeCompare(b))
|
||||
const tagItemMap: Map<string, QuartzPluginData[]> = new Map()
|
||||
@ -54,7 +64,9 @@ export default ((opts?: Partial<TagContentOptions>) => {
|
||||
<article>
|
||||
<p>{content}</p>
|
||||
</article>
|
||||
<p>{i18n(cfg.locale).pages.tagContent.totalTags({ count: tags.length })}</p>
|
||||
<p>
|
||||
{i18n(cfg.locale).pages.tagContent.totalTags({count: tags.length})}
|
||||
</p>
|
||||
<div>
|
||||
{tags.map((tag) => {
|
||||
const pages = tagItemMap.get(tag)!
|
||||
@ -63,7 +75,9 @@ export default ((opts?: Partial<TagContentOptions>) => {
|
||||
allFiles: pages,
|
||||
}
|
||||
|
||||
const contentPage = allFiles.filter((file) => file.slug === `tags/${tag}`).at(0)
|
||||
const contentPage = allFiles
|
||||
.filter((file) => file.slug === `tags/${tag}`)
|
||||
.at(0)
|
||||
|
||||
const root = contentPage?.htmlAst
|
||||
const content =
|
||||
@ -81,7 +95,9 @@ export default ((opts?: Partial<TagContentOptions>) => {
|
||||
{content && <p>{content}</p>}
|
||||
<div class="page-listing">
|
||||
<p>
|
||||
{i18n(cfg.locale).pages.tagContent.itemsUnderTag({ count: pages.length })}
|
||||
{i18n(cfg.locale).pages.tagContent.itemsUnderTag({
|
||||
count: pages.length,
|
||||
})}
|
||||
{pages.length > options.numPages && (
|
||||
<>
|
||||
{" "}
|
||||
@ -93,7 +109,11 @@ export default ((opts?: Partial<TagContentOptions>) => {
|
||||
</>
|
||||
)}
|
||||
</p>
|
||||
<PageList limit={options.numPages} {...listProps} sort={opts?.sort} />
|
||||
<PageList
|
||||
limit={options.numPages}
|
||||
{...listProps}
|
||||
sort={opts?.sort}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
@ -112,7 +132,11 @@ export default ((opts?: Partial<TagContentOptions>) => {
|
||||
<div class={classes}>
|
||||
<article>{content}</article>
|
||||
<div class="page-listing">
|
||||
<p>{i18n(cfg.locale).pages.tagContent.itemsUnderTag({ count: pages.length })}</p>
|
||||
<p>
|
||||
{i18n(cfg.locale).pages.tagContent.itemsUnderTag({
|
||||
count: pages.length,
|
||||
})}
|
||||
</p>
|
||||
<div>
|
||||
<PageList {...listProps} />
|
||||
</div>
|
||||
|
||||
@ -1,13 +1,19 @@
|
||||
import { render } from "preact-render-to-string"
|
||||
import { QuartzComponent, QuartzComponentProps } from "./types"
|
||||
import {render} from "preact-render-to-string"
|
||||
import {QuartzComponent, QuartzComponentProps} from "./types"
|
||||
import HeaderConstructor from "./Header"
|
||||
import BodyConstructor from "./Body"
|
||||
import { JSResourceToScriptElement, StaticResources } from "../util/resources"
|
||||
import { clone, FullSlug, RelativeURL, joinSegments, normalizeHastElement } from "../util/path"
|
||||
import { visit } from "unist-util-visit"
|
||||
import { Root, Element, ElementContent } from "hast"
|
||||
import { GlobalConfiguration } from "../cfg"
|
||||
import { i18n } from "../i18n"
|
||||
import {JSResourceToScriptElement, StaticResources} from "../util/resources"
|
||||
import {
|
||||
clone,
|
||||
FullSlug,
|
||||
RelativeURL,
|
||||
joinSegments,
|
||||
normalizeHastElement,
|
||||
} from "../util/path"
|
||||
import {visit} from "unist-util-visit"
|
||||
import {Root, Element, ElementContent} from "hast"
|
||||
import {GlobalConfiguration} from "../cfg"
|
||||
import {i18n} from "../i18n"
|
||||
|
||||
interface RenderComponents {
|
||||
head: QuartzComponent
|
||||
@ -71,7 +77,9 @@ export function renderPage(
|
||||
if (classNames.includes("transclude")) {
|
||||
const inner = node.children[0] as Element
|
||||
const transcludeTarget = inner.properties["data-slug"] as FullSlug
|
||||
const page = componentData.allFiles.find((f) => f.slug === transcludeTarget)
|
||||
const page = componentData.allFiles.find(
|
||||
(f) => f.slug === transcludeTarget,
|
||||
)
|
||||
if (!page) {
|
||||
return
|
||||
}
|
||||
@ -96,9 +104,16 @@ export function renderPage(
|
||||
{
|
||||
type: "element",
|
||||
tagName: "a",
|
||||
properties: { href: inner.properties?.href, class: ["internal", "transclude-src"] },
|
||||
properties: {
|
||||
href: inner.properties?.href,
|
||||
class: ["internal", "transclude-src"],
|
||||
},
|
||||
children: [
|
||||
{ type: "text", value: i18n(cfg.locale).components.transcludes.linkToOriginal },
|
||||
{
|
||||
type: "text",
|
||||
value: i18n(cfg.locale).components.transcludes
|
||||
.linkToOriginal,
|
||||
},
|
||||
],
|
||||
},
|
||||
]
|
||||
@ -111,7 +126,8 @@ export function renderPage(
|
||||
let endIdx = undefined
|
||||
for (const [i, el] of page.htmlAst.children.entries()) {
|
||||
// skip non-headers
|
||||
if (!(el.type === "element" && el.tagName.match(headerRegex))) continue
|
||||
if (!(el.type === "element" && el.tagName.match(headerRegex)))
|
||||
continue
|
||||
const depth = Number(el.tagName.substring(1))
|
||||
|
||||
// lookin for our blockref
|
||||
@ -133,15 +149,23 @@ export function renderPage(
|
||||
}
|
||||
|
||||
node.children = [
|
||||
...(page.htmlAst.children.slice(startIdx, endIdx) as ElementContent[]).map((child) =>
|
||||
...(
|
||||
page.htmlAst.children.slice(startIdx, endIdx) as ElementContent[]
|
||||
).map((child) =>
|
||||
normalizeHastElement(child as Element, slug, transcludeTarget),
|
||||
),
|
||||
{
|
||||
type: "element",
|
||||
tagName: "a",
|
||||
properties: { href: inner.properties?.href, class: ["internal", "transclude-src"] },
|
||||
properties: {
|
||||
href: inner.properties?.href,
|
||||
class: ["internal", "transclude-src"],
|
||||
},
|
||||
children: [
|
||||
{ type: "text", value: i18n(cfg.locale).components.transcludes.linkToOriginal },
|
||||
{
|
||||
type: "text",
|
||||
value: i18n(cfg.locale).components.transcludes.linkToOriginal,
|
||||
},
|
||||
],
|
||||
},
|
||||
]
|
||||
@ -169,9 +193,15 @@ export function renderPage(
|
||||
{
|
||||
type: "element",
|
||||
tagName: "a",
|
||||
properties: { href: inner.properties?.href, class: ["internal", "transclude-src"] },
|
||||
properties: {
|
||||
href: inner.properties?.href,
|
||||
class: ["internal", "transclude-src"],
|
||||
},
|
||||
children: [
|
||||
{ type: "text", value: i18n(cfg.locale).components.transcludes.linkToOriginal },
|
||||
{
|
||||
type: "text",
|
||||
value: i18n(cfg.locale).components.transcludes.linkToOriginal,
|
||||
},
|
||||
],
|
||||
},
|
||||
]
|
||||
@ -212,7 +242,10 @@ export function renderPage(
|
||||
</div>
|
||||
)
|
||||
|
||||
const lang = componentData.fileData.frontmatter?.lang ?? cfg.locale?.split("-")[0] ?? "en"
|
||||
const lang =
|
||||
componentData.fileData.frontmatter?.lang ??
|
||||
cfg.locale?.split("-")[0] ??
|
||||
"en"
|
||||
const doc = (
|
||||
<html lang={lang}>
|
||||
<Head {...componentData} />
|
||||
|
||||
@ -14,7 +14,9 @@ function toggleCallout(this: HTMLElement) {
|
||||
}
|
||||
|
||||
const collapsed = parent.classList.contains("is-collapsed")
|
||||
const height = collapsed ? parent.scrollHeight : parent.scrollHeight + current.scrollHeight
|
||||
const height = collapsed
|
||||
? parent.scrollHeight
|
||||
: parent.scrollHeight + current.scrollHeight
|
||||
parent.style.maxHeight = height + "px"
|
||||
|
||||
current = parent
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { getFullSlug } from "../../util/path"
|
||||
import {getFullSlug} from "../../util/path"
|
||||
|
||||
const checkboxId = (index: number) => `${getFullSlug(window)}-checkbox-${index}`
|
||||
|
||||
@ -10,7 +10,9 @@ document.addEventListener("nav", () => {
|
||||
const elId = checkboxId(index)
|
||||
|
||||
const switchState = (e: Event) => {
|
||||
const newCheckboxState = (e.target as HTMLInputElement)?.checked ? "true" : "false"
|
||||
const newCheckboxState = (e.target as HTMLInputElement)?.checked
|
||||
? "true"
|
||||
: "false"
|
||||
localStorage.setItem(elId, newCheckboxState)
|
||||
}
|
||||
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
const changeTheme = (e: CustomEventMap["themechange"]) => {
|
||||
const theme = e.detail.theme
|
||||
const iframe = document.querySelector("iframe.giscus-frame") as HTMLIFrameElement
|
||||
const iframe = document.querySelector(
|
||||
"iframe.giscus-frame",
|
||||
) as HTMLIFrameElement
|
||||
if (!iframe) {
|
||||
return
|
||||
}
|
||||
@ -49,11 +51,20 @@ document.addEventListener("nav", () => {
|
||||
giscusScript.setAttribute("data-repo", giscusContainer.dataset.repo)
|
||||
giscusScript.setAttribute("data-repo-id", giscusContainer.dataset.repoId)
|
||||
giscusScript.setAttribute("data-category", giscusContainer.dataset.category)
|
||||
giscusScript.setAttribute("data-category-id", giscusContainer.dataset.categoryId)
|
||||
giscusScript.setAttribute(
|
||||
"data-category-id",
|
||||
giscusContainer.dataset.categoryId,
|
||||
)
|
||||
giscusScript.setAttribute("data-mapping", giscusContainer.dataset.mapping)
|
||||
giscusScript.setAttribute("data-strict", giscusContainer.dataset.strict)
|
||||
giscusScript.setAttribute("data-reactions-enabled", giscusContainer.dataset.reactionsEnabled)
|
||||
giscusScript.setAttribute("data-input-position", giscusContainer.dataset.inputPosition)
|
||||
giscusScript.setAttribute(
|
||||
"data-reactions-enabled",
|
||||
giscusContainer.dataset.reactionsEnabled,
|
||||
)
|
||||
giscusScript.setAttribute(
|
||||
"data-input-position",
|
||||
giscusContainer.dataset.inputPosition,
|
||||
)
|
||||
|
||||
const theme = document.documentElement.getAttribute("saved-theme")
|
||||
if (theme) {
|
||||
@ -64,7 +75,7 @@ document.addEventListener("nav", () => {
|
||||
|
||||
document.addEventListener("themechange", changeTheme)
|
||||
// window.addCleanup(() => document.removeEventListener("themechange", changeTheme))
|
||||
window.addCleanup(() =>
|
||||
document.removeEventListener("themechange", changeTheme as EventListener)
|
||||
);
|
||||
window.addCleanup(() =>
|
||||
document.removeEventListener("themechange", changeTheme as EventListener),
|
||||
)
|
||||
})
|
||||
|
||||
@ -1,10 +1,12 @@
|
||||
const userPref = window.matchMedia("(prefers-color-scheme: light)").matches ? "light" : "dark"
|
||||
const userPref = window.matchMedia("(prefers-color-scheme: light)").matches
|
||||
? "light"
|
||||
: "dark"
|
||||
const currentTheme = localStorage.getItem("theme") ?? userPref
|
||||
document.documentElement.setAttribute("saved-theme", currentTheme)
|
||||
|
||||
const emitThemeChangeEvent = (theme: "light" | "dark") => {
|
||||
const event: CustomEventMap["themechange"] = new CustomEvent("themechange", {
|
||||
detail: { theme },
|
||||
detail: {theme},
|
||||
})
|
||||
document.dispatchEvent(event)
|
||||
}
|
||||
@ -26,15 +28,23 @@ document.addEventListener("nav", () => {
|
||||
}
|
||||
|
||||
// Darkmode toggle
|
||||
const toggleSwitch = document.querySelector("#darkmode-toggle") as HTMLInputElement
|
||||
const toggleSwitch = document.querySelector(
|
||||
"#darkmode-toggle",
|
||||
) as HTMLInputElement
|
||||
toggleSwitch.addEventListener("change", switchTheme)
|
||||
window.addCleanup(() => toggleSwitch.removeEventListener("change", switchTheme))
|
||||
window.addCleanup(() =>
|
||||
toggleSwitch.removeEventListener("change", switchTheme),
|
||||
)
|
||||
if (currentTheme === "dark") {
|
||||
toggleSwitch.checked = true
|
||||
}
|
||||
|
||||
// Listen for changes in prefers-color-scheme
|
||||
const colorSchemeMediaQuery = window.matchMedia("(prefers-color-scheme: dark)")
|
||||
const colorSchemeMediaQuery = window.matchMedia(
|
||||
"(prefers-color-scheme: dark)",
|
||||
)
|
||||
colorSchemeMediaQuery.addEventListener("change", themeChange)
|
||||
window.addCleanup(() => colorSchemeMediaQuery.removeEventListener("change", themeChange))
|
||||
window.addCleanup(() =>
|
||||
colorSchemeMediaQuery.removeEventListener("change", themeChange),
|
||||
)
|
||||
})
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { FolderState } from "../ExplorerNode"
|
||||
import {FolderState} from "../ExplorerNode"
|
||||
|
||||
type MaybeHTMLElement = HTMLElement | undefined
|
||||
let currentExplorerState: FolderState[]
|
||||
@ -25,7 +25,8 @@ function toggleExplorer(this: HTMLElement) {
|
||||
if (!content) return
|
||||
|
||||
content.classList.toggle("collapsed")
|
||||
content.style.maxHeight = content.style.maxHeight === "0px" ? content.scrollHeight + "px" : "0px"
|
||||
content.style.maxHeight =
|
||||
content.style.maxHeight === "0px" ? content.scrollHeight + "px" : "0px"
|
||||
}
|
||||
|
||||
function toggleFolder(evt: MouseEvent) {
|
||||
@ -82,20 +83,26 @@ function setupExplorer() {
|
||||
const useSavedFolderState = explorer?.dataset.savestate === "true"
|
||||
const oldExplorerState: FolderState[] =
|
||||
storageTree && useSavedFolderState ? JSON.parse(storageTree) : []
|
||||
const oldIndex = new Map(oldExplorerState.map((entry) => [entry.path, entry.collapsed]))
|
||||
const oldIndex = new Map(
|
||||
oldExplorerState.map((entry) => [entry.path, entry.collapsed]),
|
||||
)
|
||||
const newExplorerState: FolderState[] = explorer.dataset.tree
|
||||
? JSON.parse(explorer.dataset.tree)
|
||||
: []
|
||||
currentExplorerState = []
|
||||
for (const { path, collapsed } of newExplorerState) {
|
||||
currentExplorerState.push({ path, collapsed: oldIndex.get(path) ?? collapsed })
|
||||
for (const {path, collapsed} of newExplorerState) {
|
||||
currentExplorerState.push({
|
||||
path,
|
||||
collapsed: oldIndex.get(path) ?? collapsed,
|
||||
})
|
||||
}
|
||||
|
||||
currentExplorerState.map((folderState) => {
|
||||
const folderLi = document.querySelector(
|
||||
`[data-folderpath='${folderState.path}']`,
|
||||
) as MaybeHTMLElement
|
||||
const folderUl = folderLi?.parentElement?.nextElementSibling as MaybeHTMLElement
|
||||
const folderUl = folderLi?.parentElement
|
||||
?.nextElementSibling as MaybeHTMLElement
|
||||
if (folderUl) {
|
||||
setFolderState(folderUl, folderState.collapsed)
|
||||
}
|
||||
@ -120,7 +127,9 @@ document.addEventListener("nav", () => {
|
||||
* @param collapsed if folder should be set to collapsed or not
|
||||
*/
|
||||
function setFolderState(folderElement: HTMLElement, collapsed: boolean) {
|
||||
return collapsed ? folderElement.classList.remove("open") : folderElement.classList.add("open")
|
||||
return collapsed
|
||||
? folderElement.classList.remove("open")
|
||||
: folderElement.classList.add("open")
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -1,7 +1,13 @@
|
||||
import type { ContentDetails } from "../../plugins/emitters/contentIndex"
|
||||
import type {ContentDetails} from "../../plugins/emitters/contentIndex"
|
||||
import * as d3 from "d3"
|
||||
import { registerEscapeHandler, removeAllChildren } from "./util"
|
||||
import { FullSlug, SimpleSlug, getFullSlug, resolveRelative, simplifySlug } from "../../util/path"
|
||||
import {registerEscapeHandler, removeAllChildren} from "./util"
|
||||
import {
|
||||
FullSlug,
|
||||
SimpleSlug,
|
||||
getFullSlug,
|
||||
resolveRelative,
|
||||
simplifySlug,
|
||||
} from "../../util/path"
|
||||
|
||||
type NodeData = {
|
||||
id: SimpleSlug
|
||||
@ -62,7 +68,7 @@ async function renderGraph(container: string, fullSlug: FullSlug) {
|
||||
|
||||
for (const dest of outgoing) {
|
||||
if (validLinks.has(dest)) {
|
||||
links.push({ source: source, target: dest })
|
||||
links.push({source: source, target: dest})
|
||||
}
|
||||
}
|
||||
|
||||
@ -74,7 +80,7 @@ async function renderGraph(container: string, fullSlug: FullSlug) {
|
||||
tags.push(...localTags.filter((tag) => !tags.includes(tag)))
|
||||
|
||||
for (const tag of localTags) {
|
||||
links.push({ source: source, target: tag })
|
||||
links.push({source: source, target: tag})
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -92,7 +98,10 @@ async function renderGraph(container: string, fullSlug: FullSlug) {
|
||||
neighbourhood.add(cur)
|
||||
const outgoing = links.filter((l) => l.source === cur)
|
||||
const incoming = links.filter((l) => l.target === cur)
|
||||
wl.push(...outgoing.map((l) => l.target), ...incoming.map((l) => l.source))
|
||||
wl.push(
|
||||
...outgoing.map((l) => l.target),
|
||||
...incoming.map((l) => l.source),
|
||||
)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@ -100,16 +109,20 @@ async function renderGraph(container: string, fullSlug: FullSlug) {
|
||||
if (showTags) tags.forEach((tag) => neighbourhood.add(tag))
|
||||
}
|
||||
|
||||
const graphData: { nodes: NodeData[]; links: LinkData[] } = {
|
||||
const graphData: {nodes: NodeData[]; links: LinkData[]} = {
|
||||
nodes: [...neighbourhood].map((url) => {
|
||||
const text = url.startsWith("tags/") ? "#" + url.substring(5) : (data.get(url)?.title ?? url)
|
||||
const text = url.startsWith("tags/")
|
||||
? "#" + url.substring(5)
|
||||
: data.get(url)?.title ?? url
|
||||
return {
|
||||
id: url,
|
||||
text: text,
|
||||
tags: data.get(url)?.tags ?? [],
|
||||
}
|
||||
}),
|
||||
links: links.filter((l) => neighbourhood.has(l.source) && neighbourhood.has(l.target)),
|
||||
links: links.filter(
|
||||
(l) => neighbourhood.has(l.source) && neighbourhood.has(l.target),
|
||||
),
|
||||
}
|
||||
|
||||
const simulation: d3.Simulation<NodeData, LinkData> = d3
|
||||
@ -132,7 +145,12 @@ async function renderGraph(container: string, fullSlug: FullSlug) {
|
||||
.append("svg")
|
||||
.attr("width", width)
|
||||
.attr("height", height)
|
||||
.attr("viewBox", [-width / 2 / scale, -height / 2 / scale, width / scale, height / scale])
|
||||
.attr("viewBox", [
|
||||
-width / 2 / scale,
|
||||
-height / 2 / scale,
|
||||
width / scale,
|
||||
height / scale,
|
||||
])
|
||||
|
||||
// draw links between nodes
|
||||
const link = svg
|
||||
@ -145,7 +163,12 @@ async function renderGraph(container: string, fullSlug: FullSlug) {
|
||||
.attr("stroke-width", 1)
|
||||
|
||||
// svg groups
|
||||
const graphNode = svg.append("g").selectAll("g").data(graphData.nodes).enter().append("g")
|
||||
const graphNode = svg
|
||||
.append("g")
|
||||
.selectAll("g")
|
||||
.data(graphData.nodes)
|
||||
.enter()
|
||||
.append("g")
|
||||
|
||||
// calculate color
|
||||
const color = (d: NodeData) => {
|
||||
@ -186,7 +209,9 @@ async function renderGraph(container: string, fullSlug: FullSlug) {
|
||||
}
|
||||
|
||||
function nodeRadius(d: NodeData) {
|
||||
const numLinks = links.filter((l: any) => l.source.id === d.id || l.target.id === d.id).length
|
||||
const numLinks = links.filter(
|
||||
(l: any) => l.source.id === d.id || l.target.id === d.id,
|
||||
).length
|
||||
return 2 + Math.sqrt(numLinks)
|
||||
}
|
||||
|
||||
@ -208,11 +233,15 @@ async function renderGraph(container: string, fullSlug: FullSlug) {
|
||||
const currentId = d.id
|
||||
const linkNodes = d3
|
||||
.selectAll(".link")
|
||||
.filter((d: any) => d.source.id === currentId || d.target.id === currentId)
|
||||
.filter(
|
||||
(d: any) => d.source.id === currentId || d.target.id === currentId,
|
||||
)
|
||||
|
||||
if (focusOnHover) {
|
||||
// fade out non-neighbour nodes
|
||||
connectedNodes = linkNodes.data().flatMap((d: any) => [d.source.id, d.target.id])
|
||||
connectedNodes = linkNodes
|
||||
.data()
|
||||
.flatMap((d: any) => [d.source.id, d.target.id])
|
||||
|
||||
d3.selectAll<HTMLElement, NodeData>(".link")
|
||||
.transition()
|
||||
@ -238,7 +267,11 @@ async function renderGraph(container: string, fullSlug: FullSlug) {
|
||||
}
|
||||
|
||||
// highlight links
|
||||
linkNodes.transition().duration(200).attr("stroke", "var(--gray)").attr("stroke-width", 1)
|
||||
linkNodes
|
||||
.transition()
|
||||
.duration(200)
|
||||
.attr("stroke", "var(--gray)")
|
||||
.attr("stroke-width", 1)
|
||||
|
||||
const bigFont = fontSize * 1.5
|
||||
|
||||
@ -255,19 +288,32 @@ async function renderGraph(container: string, fullSlug: FullSlug) {
|
||||
})
|
||||
.on("mouseleave", function (_, d) {
|
||||
if (focusOnHover) {
|
||||
d3.selectAll<HTMLElement, NodeData>(".link").transition().duration(200).style("opacity", 1)
|
||||
d3.selectAll<HTMLElement, NodeData>(".node").transition().duration(200).style("opacity", 1)
|
||||
d3.selectAll<HTMLElement, NodeData>(".link")
|
||||
.transition()
|
||||
.duration(200)
|
||||
.style("opacity", 1)
|
||||
d3.selectAll<HTMLElement, NodeData>(".node")
|
||||
.transition()
|
||||
.duration(200)
|
||||
.style("opacity", 1)
|
||||
|
||||
d3.selectAll<HTMLElement, NodeData>(".node")
|
||||
.filter((d) => !connectedNodes.includes(d.id))
|
||||
.nodes()
|
||||
.map((it) => d3.select(it.parentNode as HTMLElement).select("text"))
|
||||
.forEach((it) => it.transition().duration(200).style("opacity", it.attr("opacityOld")))
|
||||
.forEach((it) =>
|
||||
it
|
||||
.transition()
|
||||
.duration(200)
|
||||
.style("opacity", it.attr("opacityOld")),
|
||||
)
|
||||
}
|
||||
const currentId = d.id
|
||||
const linkNodes = d3
|
||||
.selectAll(".link")
|
||||
.filter((d: any) => d.source.id === currentId || d.target.id === currentId)
|
||||
.filter(
|
||||
(d: any) => d.source.id === currentId || d.target.id === currentId,
|
||||
)
|
||||
|
||||
linkNodes.transition().duration(200).attr("stroke", "var(--lightgray)")
|
||||
|
||||
@ -313,7 +359,7 @@ async function renderGraph(container: string, fullSlug: FullSlug) {
|
||||
[width, height],
|
||||
])
|
||||
.scaleExtent([0.25, 4])
|
||||
.on("zoom", ({ transform }) => {
|
||||
.on("zoom", ({transform}) => {
|
||||
link.attr("transform", transform)
|
||||
node.attr("transform", transform)
|
||||
const scale = transform.k * opacityScale
|
||||
@ -366,5 +412,7 @@ document.addEventListener("nav", async (e: CustomEventMap["nav"]) => {
|
||||
|
||||
const containerIcon = document.getElementById("global-graph-icon")
|
||||
containerIcon?.addEventListener("click", renderGlobalGraph)
|
||||
window.addCleanup(() => containerIcon?.removeEventListener("click", renderGlobalGraph))
|
||||
window.addCleanup(() =>
|
||||
containerIcon?.removeEventListener("click", renderGlobalGraph),
|
||||
)
|
||||
})
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
import { computePosition, flip, inline, shift } from "@floating-ui/dom"
|
||||
import { normalizeRelativeURLs } from "../../util/path"
|
||||
import {computePosition, flip, inline, shift} from "@floating-ui/dom"
|
||||
import {normalizeRelativeURLs} from "../../util/path"
|
||||
|
||||
const p = new DOMParser()
|
||||
async function mouseEnterHandler(
|
||||
this: HTMLAnchorElement,
|
||||
{ clientX, clientY }: { clientX: number; clientY: number },
|
||||
{clientX, clientY}: {clientX: number; clientY: number},
|
||||
) {
|
||||
const link = this
|
||||
if (link.dataset.noPopover === "true") {
|
||||
@ -12,8 +12,8 @@ async function mouseEnterHandler(
|
||||
}
|
||||
|
||||
async function setPosition(popoverElement: HTMLElement) {
|
||||
const { x, y } = await computePosition(link, popoverElement, {
|
||||
middleware: [inline({ x: clientX, y: clientY }), shift(), flip()],
|
||||
const {x, y} = await computePosition(link, popoverElement, {
|
||||
middleware: [inline({x: clientX, y: clientY}), shift(), flip()],
|
||||
})
|
||||
Object.assign(popoverElement.style, {
|
||||
left: `${x}px`,
|
||||
@ -94,15 +94,19 @@ async function mouseEnterHandler(
|
||||
const heading = popoverInner.querySelector(hash) as HTMLElement | null
|
||||
if (heading) {
|
||||
// leave ~12px of buffer when scrolling to a heading
|
||||
popoverInner.scroll({ top: heading.offsetTop - 12, behavior: "instant" })
|
||||
popoverInner.scroll({top: heading.offsetTop - 12, behavior: "instant"})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
document.addEventListener("nav", () => {
|
||||
const links = [...document.getElementsByClassName("internal")] as HTMLAnchorElement[]
|
||||
const links = [
|
||||
...document.getElementsByClassName("internal"),
|
||||
] as HTMLAnchorElement[]
|
||||
for (const link of links) {
|
||||
link.addEventListener("mouseenter", mouseEnterHandler)
|
||||
window.addCleanup(() => link.removeEventListener("mouseenter", mouseEnterHandler))
|
||||
window.addCleanup(() =>
|
||||
link.removeEventListener("mouseenter", mouseEnterHandler),
|
||||
)
|
||||
}
|
||||
})
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import FlexSearch from "flexsearch"
|
||||
import { ContentDetails } from "../../plugins/emitters/contentIndex"
|
||||
import { registerEscapeHandler, removeAllChildren } from "./util"
|
||||
import { FullSlug, normalizeRelativeURLs, resolveRelative } from "../../util/path"
|
||||
import {ContentDetails} from "../../plugins/emitters/contentIndex"
|
||||
import {registerEscapeHandler, removeAllChildren} from "./util"
|
||||
import {FullSlug, normalizeRelativeURLs, resolveRelative} from "../../util/path"
|
||||
|
||||
interface Item {
|
||||
id: number
|
||||
@ -15,7 +15,8 @@ interface Item {
|
||||
type SearchType = "basic" | "tags"
|
||||
let searchType: SearchType = "basic"
|
||||
let currentSearchTerm: string = ""
|
||||
const encoder = (str: string) => str.toLowerCase().split(/([^a-z]|[^\x00-\x7F])/)
|
||||
const encoder = (str: string) =>
|
||||
str.toLowerCase().split(/([^a-z]|[^\x00-\x7F])/)
|
||||
let index = new FlexSearch.Document<Item>({
|
||||
charset: "latin:extra",
|
||||
encode: encoder,
|
||||
@ -65,12 +66,18 @@ function highlight(searchTerm: string, text: string, trim?: boolean) {
|
||||
let endIndex = tokenizedText.length - 1
|
||||
if (trim) {
|
||||
const includesCheck = (tok: string) =>
|
||||
tokenizedTerms.some((term) => tok.toLowerCase().startsWith(term.toLowerCase()))
|
||||
tokenizedTerms.some((term) =>
|
||||
tok.toLowerCase().startsWith(term.toLowerCase()),
|
||||
)
|
||||
const occurrencesIndices = tokenizedText.map(includesCheck)
|
||||
|
||||
let bestSum = 0
|
||||
let bestIndex = 0
|
||||
for (let i = 0; i < Math.max(tokenizedText.length - contextWindowWords, 0); i++) {
|
||||
for (
|
||||
let i = 0;
|
||||
i < Math.max(tokenizedText.length - contextWindowWords, 0);
|
||||
i++
|
||||
) {
|
||||
const window = occurrencesIndices.slice(i, i + contextWindowWords)
|
||||
const windowSum = window.reduce((total, cur) => total + (cur ? 1 : 0), 0)
|
||||
if (windowSum >= bestSum) {
|
||||
@ -80,7 +87,10 @@ function highlight(searchTerm: string, text: string, trim?: boolean) {
|
||||
}
|
||||
|
||||
startIndex = Math.max(bestIndex - contextWindowWords, 0)
|
||||
endIndex = Math.min(startIndex + 2 * contextWindowWords, tokenizedText.length - 1)
|
||||
endIndex = Math.min(
|
||||
startIndex + 2 * contextWindowWords,
|
||||
tokenizedText.length - 1,
|
||||
)
|
||||
tokenizedText = tokenizedText.slice(startIndex, endIndex)
|
||||
}
|
||||
|
||||
@ -124,15 +134,21 @@ function highlightHTML(searchTerm: string, el: HTMLElement) {
|
||||
let lastIndex = 0
|
||||
for (const match of matches) {
|
||||
const matchIndex = nodeText.indexOf(match, lastIndex)
|
||||
spanContainer.appendChild(document.createTextNode(nodeText.slice(lastIndex, matchIndex)))
|
||||
spanContainer.appendChild(
|
||||
document.createTextNode(nodeText.slice(lastIndex, matchIndex)),
|
||||
)
|
||||
spanContainer.appendChild(createHighlightSpan(match))
|
||||
lastIndex = matchIndex + match.length
|
||||
}
|
||||
spanContainer.appendChild(document.createTextNode(nodeText.slice(lastIndex)))
|
||||
spanContainer.appendChild(
|
||||
document.createTextNode(nodeText.slice(lastIndex)),
|
||||
)
|
||||
node.parentNode?.replaceChild(spanContainer, node)
|
||||
} else if (node.nodeType === Node.ELEMENT_NODE) {
|
||||
if ((node as HTMLElement).classList.contains("highlight")) return
|
||||
Array.from(node.childNodes).forEach((child) => highlightTextNodes(child, term))
|
||||
Array.from(node.childNodes).forEach((child) =>
|
||||
highlightTextNodes(child, term),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@ -149,7 +165,9 @@ document.addEventListener("nav", async (e: CustomEventMap["nav"]) => {
|
||||
const container = document.getElementById("search-container")
|
||||
const sidebar = container?.closest(".sidebar") as HTMLElement
|
||||
const searchButton = document.getElementById("search-button")
|
||||
const searchBar = document.getElementById("search-bar") as HTMLInputElement | null
|
||||
const searchBar = document.getElementById(
|
||||
"search-bar",
|
||||
) as HTMLInputElement | null
|
||||
const searchLayout = document.getElementById("search-layout")
|
||||
const idDataMap = Object.keys(data) as FullSlug[]
|
||||
|
||||
@ -212,7 +230,11 @@ document.addEventListener("nav", async (e: CustomEventMap["nav"]) => {
|
||||
const searchBarOpen = container?.classList.contains("active")
|
||||
searchBarOpen ? hideSearch() : showSearch("basic")
|
||||
return
|
||||
} else if (e.shiftKey && (e.ctrlKey || e.metaKey) && e.key.toLowerCase() === "k") {
|
||||
} else if (
|
||||
e.shiftKey &&
|
||||
(e.ctrlKey || e.metaKey) &&
|
||||
e.key.toLowerCase() === "k"
|
||||
) {
|
||||
// Hotkey to open tag search
|
||||
e.preventDefault()
|
||||
const searchBarOpen = container?.classList.contains("active")
|
||||
@ -237,7 +259,9 @@ document.addEventListener("nav", async (e: CustomEventMap["nav"]) => {
|
||||
await displayPreview(active)
|
||||
active.click()
|
||||
} else {
|
||||
const anchor = document.getElementsByClassName("result-card")[0] as HTMLInputElement | null
|
||||
const anchor = document.getElementsByClassName(
|
||||
"result-card",
|
||||
)[0] as HTMLInputElement | null
|
||||
if (!anchor || anchor?.classList.contains("no-match")) return
|
||||
await displayPreview(anchor)
|
||||
anchor.click()
|
||||
@ -249,7 +273,8 @@ document.addEventListener("nav", async (e: CustomEventMap["nav"]) => {
|
||||
const currentResult = currentHover
|
||||
? currentHover
|
||||
: (document.activeElement as HTMLInputElement | null)
|
||||
const prevResult = currentResult?.previousElementSibling as HTMLInputElement | null
|
||||
const prevResult =
|
||||
currentResult?.previousElementSibling as HTMLInputElement | null
|
||||
currentResult?.classList.remove("focus")
|
||||
prevResult?.focus()
|
||||
if (prevResult) currentHover = prevResult
|
||||
@ -262,8 +287,11 @@ document.addEventListener("nav", async (e: CustomEventMap["nav"]) => {
|
||||
if (document.activeElement === searchBar || currentHover !== null) {
|
||||
const firstResult = currentHover
|
||||
? currentHover
|
||||
: (document.getElementsByClassName("result-card")[0] as HTMLInputElement | null)
|
||||
const secondResult = firstResult?.nextElementSibling as HTMLInputElement | null
|
||||
: (document.getElementsByClassName(
|
||||
"result-card",
|
||||
)[0] as HTMLInputElement | null)
|
||||
const secondResult =
|
||||
firstResult?.nextElementSibling as HTMLInputElement | null
|
||||
firstResult?.classList.remove("focus")
|
||||
secondResult?.focus()
|
||||
if (secondResult) currentHover = secondResult
|
||||
@ -277,7 +305,10 @@ document.addEventListener("nav", async (e: CustomEventMap["nav"]) => {
|
||||
return {
|
||||
id,
|
||||
slug,
|
||||
title: searchType === "tags" ? data[slug].title : highlight(term, data[slug].title ?? ""),
|
||||
title:
|
||||
searchType === "tags"
|
||||
? data[slug].title
|
||||
: highlight(term, data[slug].title ?? ""),
|
||||
content: highlight(term, data[slug].content ?? "", true),
|
||||
tags: highlightTags(term.substring(1), data[slug].tags),
|
||||
}
|
||||
@ -303,8 +334,9 @@ document.addEventListener("nav", async (e: CustomEventMap["nav"]) => {
|
||||
return new URL(resolveRelative(currentSlug, slug), location.toString())
|
||||
}
|
||||
|
||||
const resultToHTML = ({ slug, title, content, tags }: Item) => {
|
||||
const htmlTags = tags.length > 0 ? `<ul class="tags">${tags.join("")}</ul>` : ``
|
||||
const resultToHTML = ({slug, title, content, tags}: Item) => {
|
||||
const htmlTags =
|
||||
tags.length > 0 ? `<ul class="tags">${tags.join("")}</ul>` : ``
|
||||
const itemTile = document.createElement("a")
|
||||
itemTile.classList.add("result-card")
|
||||
itemTile.id = slug
|
||||
@ -313,12 +345,14 @@ document.addEventListener("nav", async (e: CustomEventMap["nav"]) => {
|
||||
enablePreview && window.innerWidth > 600 ? "" : `<p>${content}</p>`
|
||||
}`
|
||||
itemTile.addEventListener("click", (event) => {
|
||||
if (event.altKey || event.ctrlKey || event.metaKey || event.shiftKey) return
|
||||
if (event.altKey || event.ctrlKey || event.metaKey || event.shiftKey)
|
||||
return
|
||||
hideSearch()
|
||||
})
|
||||
|
||||
const handler = (event: MouseEvent) => {
|
||||
if (event.altKey || event.ctrlKey || event.metaKey || event.shiftKey) return
|
||||
if (event.altKey || event.ctrlKey || event.metaKey || event.shiftKey)
|
||||
return
|
||||
hideSearch()
|
||||
}
|
||||
|
||||
@ -329,7 +363,9 @@ document.addEventListener("nav", async (e: CustomEventMap["nav"]) => {
|
||||
}
|
||||
|
||||
itemTile.addEventListener("mouseenter", onMouseEnter)
|
||||
window.addCleanup(() => itemTile.removeEventListener("mouseenter", onMouseEnter))
|
||||
window.addCleanup(() =>
|
||||
itemTile.removeEventListener("mouseenter", onMouseEnter),
|
||||
)
|
||||
itemTile.addEventListener("click", handler)
|
||||
window.addCleanup(() => itemTile.removeEventListener("click", handler))
|
||||
|
||||
@ -386,7 +422,9 @@ document.addEventListener("nav", async (e: CustomEventMap["nav"]) => {
|
||||
if (!searchLayout || !enablePreview || !el || !preview) return
|
||||
const slug = el.id as FullSlug
|
||||
const innerDiv = await fetchContent(slug).then((contents) =>
|
||||
contents.flatMap((el) => [...highlightHTML(currentSearchTerm, el as HTMLElement).children]),
|
||||
contents.flatMap((el) => [
|
||||
...highlightHTML(currentSearchTerm, el as HTMLElement).children,
|
||||
]),
|
||||
)
|
||||
previewInner = document.createElement("div")
|
||||
previewInner.classList.add("preview-inner")
|
||||
@ -397,7 +435,7 @@ document.addEventListener("nav", async (e: CustomEventMap["nav"]) => {
|
||||
const highlights = [...preview.querySelectorAll(".highlight")].sort(
|
||||
(a, b) => b.innerHTML.length - a.innerHTML.length,
|
||||
)
|
||||
highlights[0]?.scrollIntoView({ block: "start" })
|
||||
highlights[0]?.scrollIntoView({block: "start"})
|
||||
}
|
||||
|
||||
async function onType(e: HTMLElementEventMap["input"]) {
|
||||
@ -454,14 +492,20 @@ document.addEventListener("nav", async (e: CustomEventMap["nav"]) => {
|
||||
...getByField("content"),
|
||||
...getByField("tags"),
|
||||
])
|
||||
const finalResults = [...allIds].map((id) => formatForDisplay(currentSearchTerm, id))
|
||||
const finalResults = [...allIds].map((id) =>
|
||||
formatForDisplay(currentSearchTerm, id),
|
||||
)
|
||||
await displayResults(finalResults)
|
||||
}
|
||||
|
||||
document.addEventListener("keydown", shortcutHandler)
|
||||
window.addCleanup(() => document.removeEventListener("keydown", shortcutHandler))
|
||||
window.addCleanup(() =>
|
||||
document.removeEventListener("keydown", shortcutHandler),
|
||||
)
|
||||
searchButton?.addEventListener("click", () => showSearch("basic"))
|
||||
window.addCleanup(() => searchButton?.removeEventListener("click", () => showSearch("basic")))
|
||||
window.addCleanup(() =>
|
||||
searchButton?.removeEventListener("click", () => showSearch("basic")),
|
||||
)
|
||||
searchBar?.addEventListener("input", onType)
|
||||
window.addCleanup(() => searchBar?.removeEventListener("input", onType))
|
||||
|
||||
@ -474,7 +518,7 @@ document.addEventListener("nav", async (e: CustomEventMap["nav"]) => {
|
||||
* @param index index to fill
|
||||
* @param data data to fill index with
|
||||
*/
|
||||
async function fillDocument(data: { [key: FullSlug]: ContentDetails }) {
|
||||
async function fillDocument(data: {[key: FullSlug]: ContentDetails}) {
|
||||
let id = 0
|
||||
const promises: Array<Promise<unknown>> = []
|
||||
for (const [slug, fileData] of Object.entries<ContentDetails>(data)) {
|
||||
|
||||
@ -1,5 +1,10 @@
|
||||
import micromorph from "micromorph"
|
||||
import { FullSlug, RelativeURL, getFullSlug, normalizeRelativeURLs } from "../../util/path"
|
||||
import {
|
||||
FullSlug,
|
||||
RelativeURL,
|
||||
getFullSlug,
|
||||
normalizeRelativeURLs,
|
||||
} from "../../util/path"
|
||||
|
||||
// adapted from `micromorph`
|
||||
// https://github.com/natemoo-re/micromorph
|
||||
@ -23,19 +28,22 @@ const isSamePage = (url: URL): boolean => {
|
||||
return sameOrigin && samePath
|
||||
}
|
||||
|
||||
const getOpts = ({ target }: Event): { url: URL; scroll?: boolean } | undefined => {
|
||||
const getOpts = ({target}: Event): {url: URL; scroll?: boolean} | undefined => {
|
||||
if (!isElement(target)) return
|
||||
if (target.attributes.getNamedItem("target")?.value === "_blank") return
|
||||
const a = target.closest("a")
|
||||
if (!a) return
|
||||
if ("routerIgnore" in a.dataset) return
|
||||
const { href } = a
|
||||
const {href} = a
|
||||
if (!isLocalUrl(href)) return
|
||||
return { url: new URL(href), scroll: "routerNoscroll" in a.dataset ? false : undefined }
|
||||
return {
|
||||
url: new URL(href),
|
||||
scroll: "routerNoscroll" in a.dataset ? false : undefined,
|
||||
}
|
||||
}
|
||||
|
||||
function notifyNav(url: FullSlug) {
|
||||
const event: CustomEventMap["nav"] = new CustomEvent("nav", { detail: { url } })
|
||||
const event: CustomEventMap["nav"] = new CustomEvent("nav", {detail: {url}})
|
||||
document.dispatchEvent(event)
|
||||
}
|
||||
|
||||
@ -86,15 +94,19 @@ async function navigate(url: URL, isBack: boolean = false) {
|
||||
// scroll into place and add history
|
||||
if (!isBack) {
|
||||
if (url.hash) {
|
||||
const el = document.getElementById(decodeURIComponent(url.hash.substring(1)))
|
||||
const el = document.getElementById(
|
||||
decodeURIComponent(url.hash.substring(1)),
|
||||
)
|
||||
el?.scrollIntoView()
|
||||
} else {
|
||||
window.scrollTo({ top: 0 })
|
||||
window.scrollTo({top: 0})
|
||||
}
|
||||
}
|
||||
|
||||
// now, patch head
|
||||
const elementsToRemove = document.head.querySelectorAll(":not([spa-preserve])")
|
||||
const elementsToRemove = document.head.querySelectorAll(
|
||||
":not([spa-preserve])",
|
||||
)
|
||||
elementsToRemove.forEach((el) => el.remove())
|
||||
const elementsToAdd = html.head.querySelectorAll(":not([spa-preserve])")
|
||||
elementsToAdd.forEach((el) => document.head.appendChild(el))
|
||||
@ -113,13 +125,15 @@ window.spaNavigate = navigate
|
||||
function createRouter() {
|
||||
if (typeof window !== "undefined") {
|
||||
window.addEventListener("click", async (event) => {
|
||||
const { url } = getOpts(event) ?? {}
|
||||
const {url} = getOpts(event) ?? {}
|
||||
// dont hijack behaviour, just let browser act normally
|
||||
if (!url || event.ctrlKey || event.metaKey) return
|
||||
event.preventDefault()
|
||||
|
||||
if (isSamePage(url) && url.hash) {
|
||||
const el = document.getElementById(decodeURIComponent(url.hash.substring(1)))
|
||||
const el = document.getElementById(
|
||||
decodeURIComponent(url.hash.substring(1)),
|
||||
)
|
||||
el?.scrollIntoView()
|
||||
history.pushState({}, "", url)
|
||||
return
|
||||
@ -133,8 +147,9 @@ function createRouter() {
|
||||
})
|
||||
|
||||
window.addEventListener("popstate", (event) => {
|
||||
const { url } = getOpts(event) ?? {}
|
||||
if (window.location.hash && window.location.pathname === url?.pathname) return
|
||||
const {url} = getOpts(event) ?? {}
|
||||
if (window.location.hash && window.location.pathname === url?.pathname)
|
||||
return
|
||||
try {
|
||||
navigate(new URL(window.location.toString()), true)
|
||||
} catch (e) {
|
||||
@ -167,7 +182,7 @@ if (!customElements.get("route-announcer")) {
|
||||
const attrs = {
|
||||
"aria-live": "assertive",
|
||||
"aria-atomic": "true",
|
||||
style:
|
||||
"style":
|
||||
"position: absolute; left: 0; top: 0; clip: rect(0 0 0 0); clip-path: inset(50%); overflow: hidden; white-space: nowrap; width: 1px; height: 1px",
|
||||
}
|
||||
|
||||
|
||||
@ -23,7 +23,8 @@ function toggleToc(this: HTMLElement) {
|
||||
const content = this.nextElementSibling as HTMLElement | undefined
|
||||
if (!content) return
|
||||
content.classList.toggle("collapsed")
|
||||
content.style.maxHeight = content.style.maxHeight === "0px" ? content.scrollHeight + "px" : "0px"
|
||||
content.style.maxHeight =
|
||||
content.style.maxHeight === "0px" ? content.scrollHeight + "px" : "0px"
|
||||
}
|
||||
|
||||
function setupToc() {
|
||||
@ -44,6 +45,8 @@ document.addEventListener("nav", () => {
|
||||
|
||||
// update toc entry highlighting
|
||||
observer.disconnect()
|
||||
const headers = document.querySelectorAll("h1[id], h2[id], h3[id], h4[id], h5[id], h6[id]")
|
||||
const headers = document.querySelectorAll(
|
||||
"h1[id], h2[id], h3[id], h4[id], h5[id], h6[id]",
|
||||
)
|
||||
headers.forEach((header) => observer.observe(header))
|
||||
})
|
||||
|
||||
@ -1,4 +1,7 @@
|
||||
export function registerEscapeHandler(outsideContainer: HTMLElement | null, cb: () => void) {
|
||||
export function registerEscapeHandler(
|
||||
outsideContainer: HTMLElement | null,
|
||||
cb: () => void,
|
||||
) {
|
||||
if (!outsideContainer) return
|
||||
function click(this: HTMLElement, e: HTMLElementEventMap["click"]) {
|
||||
if (e.target !== this) return
|
||||
|
||||
@ -143,7 +143,11 @@
|
||||
}
|
||||
|
||||
& .highlight {
|
||||
background: color-mix(in srgb, var(--tertiary) 60%, rgba(255, 255, 255, 0));
|
||||
background: color-mix(
|
||||
in srgb,
|
||||
var(--tertiary) 60%,
|
||||
rgba(255, 255, 255, 0)
|
||||
);
|
||||
border-radius: 5px;
|
||||
scroll-margin-top: 2rem;
|
||||
}
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
import { ComponentType, JSX } from "preact"
|
||||
import { StaticResources } from "../util/resources"
|
||||
import { QuartzPluginData } from "../plugins/vfile"
|
||||
import { GlobalConfiguration } from "../cfg"
|
||||
import { Node } from "hast"
|
||||
import { BuildCtx } from "../util/ctx"
|
||||
import {ComponentType, JSX} from "preact"
|
||||
import {StaticResources} from "../util/resources"
|
||||
import {QuartzPluginData} from "../plugins/vfile"
|
||||
import {GlobalConfiguration} from "../cfg"
|
||||
import {Node} from "hast"
|
||||
import {BuildCtx} from "../util/ctx"
|
||||
|
||||
export type QuartzComponentProps = {
|
||||
ctx: BuildCtx
|
||||
@ -24,6 +24,6 @@ export type QuartzComponent = ComponentType<QuartzComponentProps> & {
|
||||
afterDOMLoaded?: string
|
||||
}
|
||||
|
||||
export type QuartzComponentConstructor<Options extends object | undefined = undefined> = (
|
||||
opts: Options,
|
||||
) => QuartzComponent
|
||||
export type QuartzComponentConstructor<
|
||||
Options extends object | undefined = undefined,
|
||||
> = (opts: Options) => QuartzComponent
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { Translation, CalloutTranslation } from "./locales/definition"
|
||||
import {Translation, CalloutTranslation} from "./locales/definition"
|
||||
import enUs from "./locales/en-US"
|
||||
import enGb from "./locales/en-GB"
|
||||
import fr from "./locales/fr-FR"
|
||||
@ -65,6 +65,7 @@ export const TRANSLATIONS = {
|
||||
} as const
|
||||
|
||||
export const defaultTranslation = "en-US"
|
||||
export const i18n = (locale: ValidLocale): Translation => TRANSLATIONS[locale ?? defaultTranslation]
|
||||
export const i18n = (locale: ValidLocale): Translation =>
|
||||
TRANSLATIONS[locale ?? defaultTranslation]
|
||||
export type ValidLocale = keyof typeof TRANSLATIONS
|
||||
export type ValidCallout = keyof CalloutTranslation
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { Translation } from "./definition"
|
||||
import {Translation} from "./definition"
|
||||
|
||||
export default {
|
||||
propertyDefaults: {
|
||||
@ -40,10 +40,10 @@ export default {
|
||||
},
|
||||
recentNotes: {
|
||||
title: "آخر الملاحظات",
|
||||
seeRemainingMore: ({ remaining }) => `تصفح ${remaining} أكثر →`,
|
||||
seeRemainingMore: ({remaining}) => `تصفح ${remaining} أكثر →`,
|
||||
},
|
||||
transcludes: {
|
||||
transcludeOf: ({ targetSlug }) => `مقتبس من ${targetSlug}`,
|
||||
transcludeOf: ({targetSlug}) => `مقتبس من ${targetSlug}`,
|
||||
linkToOriginal: "وصلة للملاحظة الرئيسة",
|
||||
},
|
||||
search: {
|
||||
@ -54,7 +54,7 @@ export default {
|
||||
title: "فهرس المحتويات",
|
||||
},
|
||||
contentMeta: {
|
||||
readingTime: ({ minutes }) =>
|
||||
readingTime: ({minutes}) =>
|
||||
minutes == 1
|
||||
? `دقيقة أو أقل للقراءة`
|
||||
: minutes == 2
|
||||
@ -65,7 +65,7 @@ export default {
|
||||
pages: {
|
||||
rss: {
|
||||
recentNotes: "آخر الملاحظات",
|
||||
lastFewNotes: ({ count }) => `آخر ${count} ملاحظة`,
|
||||
lastFewNotes: ({count}) => `آخر ${count} ملاحظة`,
|
||||
},
|
||||
error: {
|
||||
title: "غير موجود",
|
||||
@ -74,16 +74,20 @@ export default {
|
||||
},
|
||||
folderContent: {
|
||||
folder: "مجلد",
|
||||
itemsUnderFolder: ({ count }) =>
|
||||
count === 1 ? "يوجد عنصر واحد فقط تحت هذا المجلد" : `يوجد ${count} عناصر تحت هذا المجلد.`,
|
||||
itemsUnderFolder: ({count}) =>
|
||||
count === 1
|
||||
? "يوجد عنصر واحد فقط تحت هذا المجلد"
|
||||
: `يوجد ${count} عناصر تحت هذا المجلد.`,
|
||||
},
|
||||
tagContent: {
|
||||
tag: "الوسم",
|
||||
tagIndex: "مؤشر الوسم",
|
||||
itemsUnderTag: ({ count }) =>
|
||||
count === 1 ? "يوجد عنصر واحد فقط تحت هذا الوسم" : `يوجد ${count} عناصر تحت هذا الوسم.`,
|
||||
showingFirst: ({ count }) => `إظهار أول ${count} أوسمة.`,
|
||||
totalTags: ({ count }) => `يوجد ${count} أوسمة.`,
|
||||
itemsUnderTag: ({count}) =>
|
||||
count === 1
|
||||
? "يوجد عنصر واحد فقط تحت هذا الوسم"
|
||||
: `يوجد ${count} عناصر تحت هذا الوسم.`,
|
||||
showingFirst: ({count}) => `إظهار أول ${count} أوسمة.`,
|
||||
totalTags: ({count}) => `يوجد ${count} أوسمة.`,
|
||||
},
|
||||
},
|
||||
} as const satisfies Translation
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { Translation } from "./definition"
|
||||
import {Translation} from "./definition"
|
||||
|
||||
export default {
|
||||
propertyDefaults: {
|
||||
@ -40,10 +40,10 @@ export default {
|
||||
},
|
||||
recentNotes: {
|
||||
title: "Notes Recents",
|
||||
seeRemainingMore: ({ remaining }) => `Vegi ${remaining} més →`,
|
||||
seeRemainingMore: ({remaining}) => `Vegi ${remaining} més →`,
|
||||
},
|
||||
transcludes: {
|
||||
transcludeOf: ({ targetSlug }) => `Transcluit de ${targetSlug}`,
|
||||
transcludeOf: ({targetSlug}) => `Transcluit de ${targetSlug}`,
|
||||
linkToOriginal: "Enllaç a l'original",
|
||||
},
|
||||
search: {
|
||||
@ -54,13 +54,13 @@ export default {
|
||||
title: "Taula de Continguts",
|
||||
},
|
||||
contentMeta: {
|
||||
readingTime: ({ minutes }) => `Es llegeix en ${minutes} min`,
|
||||
readingTime: ({minutes}) => `Es llegeix en ${minutes} min`,
|
||||
},
|
||||
},
|
||||
pages: {
|
||||
rss: {
|
||||
recentNotes: "Notes recents",
|
||||
lastFewNotes: ({ count }) => `Últimes ${count} notes`,
|
||||
lastFewNotes: ({count}) => `Últimes ${count} notes`,
|
||||
},
|
||||
error: {
|
||||
title: "No s'ha trobat.",
|
||||
@ -69,16 +69,20 @@ export default {
|
||||
},
|
||||
folderContent: {
|
||||
folder: "Carpeta",
|
||||
itemsUnderFolder: ({ count }) =>
|
||||
count === 1 ? "1 article en aquesta carpeta." : `${count} articles en esta carpeta.`,
|
||||
itemsUnderFolder: ({count}) =>
|
||||
count === 1
|
||||
? "1 article en aquesta carpeta."
|
||||
: `${count} articles en esta carpeta.`,
|
||||
},
|
||||
tagContent: {
|
||||
tag: "Etiqueta",
|
||||
tagIndex: "índex d'Etiquetes",
|
||||
itemsUnderTag: ({ count }) =>
|
||||
count === 1 ? "1 article amb aquesta etiqueta." : `${count} article amb aquesta etiqueta.`,
|
||||
showingFirst: ({ count }) => `Mostrant les primeres ${count} etiquetes.`,
|
||||
totalTags: ({ count }) => `S'han trobat ${count} etiquetes en total.`,
|
||||
itemsUnderTag: ({count}) =>
|
||||
count === 1
|
||||
? "1 article amb aquesta etiqueta."
|
||||
: `${count} article amb aquesta etiqueta.`,
|
||||
showingFirst: ({count}) => `Mostrant les primeres ${count} etiquetes.`,
|
||||
totalTags: ({count}) => `S'han trobat ${count} etiquetes en total.`,
|
||||
},
|
||||
},
|
||||
} as const satisfies Translation
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { Translation } from "./definition"
|
||||
import {Translation} from "./definition"
|
||||
|
||||
export default {
|
||||
propertyDefaults: {
|
||||
@ -40,10 +40,10 @@ export default {
|
||||
},
|
||||
recentNotes: {
|
||||
title: "Zuletzt bearbeitete Seiten",
|
||||
seeRemainingMore: ({ remaining }) => `${remaining} weitere ansehen →`,
|
||||
seeRemainingMore: ({remaining}) => `${remaining} weitere ansehen →`,
|
||||
},
|
||||
transcludes: {
|
||||
transcludeOf: ({ targetSlug }) => `Transklusion von ${targetSlug}`,
|
||||
transcludeOf: ({targetSlug}) => `Transklusion von ${targetSlug}`,
|
||||
linkToOriginal: "Link zum Original",
|
||||
},
|
||||
search: {
|
||||
@ -54,31 +54,36 @@ export default {
|
||||
title: "Inhaltsverzeichnis",
|
||||
},
|
||||
contentMeta: {
|
||||
readingTime: ({ minutes }) => `${minutes} min read`,
|
||||
readingTime: ({minutes}) => `${minutes} min read`,
|
||||
},
|
||||
},
|
||||
pages: {
|
||||
rss: {
|
||||
recentNotes: "Zuletzt bearbeitete Seiten",
|
||||
lastFewNotes: ({ count }) => `Letzte ${count} Seiten`,
|
||||
lastFewNotes: ({count}) => `Letzte ${count} Seiten`,
|
||||
},
|
||||
error: {
|
||||
title: "Nicht gefunden",
|
||||
notFound: "Diese Seite ist entweder nicht öffentlich oder existiert nicht.",
|
||||
notFound:
|
||||
"Diese Seite ist entweder nicht öffentlich oder existiert nicht.",
|
||||
home: "Return to Homepage",
|
||||
},
|
||||
folderContent: {
|
||||
folder: "Ordner",
|
||||
itemsUnderFolder: ({ count }) =>
|
||||
count === 1 ? "1 Datei in diesem Ordner." : `${count} Dateien in diesem Ordner.`,
|
||||
itemsUnderFolder: ({count}) =>
|
||||
count === 1
|
||||
? "1 Datei in diesem Ordner."
|
||||
: `${count} Dateien in diesem Ordner.`,
|
||||
},
|
||||
tagContent: {
|
||||
tag: "Tag",
|
||||
tagIndex: "Tag-Übersicht",
|
||||
itemsUnderTag: ({ count }) =>
|
||||
count === 1 ? "1 Datei mit diesem Tag." : `${count} Dateien mit diesem Tag.`,
|
||||
showingFirst: ({ count }) => `Die ersten ${count} Tags werden angezeigt.`,
|
||||
totalTags: ({ count }) => `${count} Tags insgesamt.`,
|
||||
itemsUnderTag: ({count}) =>
|
||||
count === 1
|
||||
? "1 Datei mit diesem Tag."
|
||||
: `${count} Dateien mit diesem Tag.`,
|
||||
showingFirst: ({count}) => `Die ersten ${count} Tags werden angezeigt.`,
|
||||
totalTags: ({count}) => `${count} Tags insgesamt.`,
|
||||
},
|
||||
},
|
||||
} as const satisfies Translation
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { FullSlug } from "../../util/path"
|
||||
import {FullSlug} from "../../util/path"
|
||||
|
||||
export interface CalloutTranslation {
|
||||
note: string
|
||||
@ -42,10 +42,10 @@ export interface Translation {
|
||||
}
|
||||
recentNotes: {
|
||||
title: string
|
||||
seeRemainingMore: (variables: { remaining: number }) => string
|
||||
seeRemainingMore: (variables: {remaining: number}) => string
|
||||
}
|
||||
transcludes: {
|
||||
transcludeOf: (variables: { targetSlug: FullSlug }) => string
|
||||
transcludeOf: (variables: {targetSlug: FullSlug}) => string
|
||||
linkToOriginal: string
|
||||
}
|
||||
search: {
|
||||
@ -56,13 +56,13 @@ export interface Translation {
|
||||
title: string
|
||||
}
|
||||
contentMeta: {
|
||||
readingTime: (variables: { minutes: number }) => string
|
||||
readingTime: (variables: {minutes: number}) => string
|
||||
}
|
||||
}
|
||||
pages: {
|
||||
rss: {
|
||||
recentNotes: string
|
||||
lastFewNotes: (variables: { count: number }) => string
|
||||
lastFewNotes: (variables: {count: number}) => string
|
||||
}
|
||||
error: {
|
||||
title: string
|
||||
@ -71,14 +71,14 @@ export interface Translation {
|
||||
}
|
||||
folderContent: {
|
||||
folder: string
|
||||
itemsUnderFolder: (variables: { count: number }) => string
|
||||
itemsUnderFolder: (variables: {count: number}) => string
|
||||
}
|
||||
tagContent: {
|
||||
tag: string
|
||||
tagIndex: string
|
||||
itemsUnderTag: (variables: { count: number }) => string
|
||||
showingFirst: (variables: { count: number }) => string
|
||||
totalTags: (variables: { count: number }) => string
|
||||
itemsUnderTag: (variables: {count: number}) => string
|
||||
showingFirst: (variables: {count: number}) => string
|
||||
totalTags: (variables: {count: number}) => string
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { Translation } from "./definition"
|
||||
import {Translation} from "./definition"
|
||||
|
||||
export default {
|
||||
propertyDefaults: {
|
||||
@ -40,10 +40,10 @@ export default {
|
||||
},
|
||||
recentNotes: {
|
||||
title: "Recent Notes",
|
||||
seeRemainingMore: ({ remaining }) => `See ${remaining} more →`,
|
||||
seeRemainingMore: ({remaining}) => `See ${remaining} more →`,
|
||||
},
|
||||
transcludes: {
|
||||
transcludeOf: ({ targetSlug }) => `Transclude of ${targetSlug}`,
|
||||
transcludeOf: ({targetSlug}) => `Transclude of ${targetSlug}`,
|
||||
linkToOriginal: "Link to original",
|
||||
},
|
||||
search: {
|
||||
@ -54,13 +54,13 @@ export default {
|
||||
title: "Table of Contents",
|
||||
},
|
||||
contentMeta: {
|
||||
readingTime: ({ minutes }) => `${minutes} min read`,
|
||||
readingTime: ({minutes}) => `${minutes} min read`,
|
||||
},
|
||||
},
|
||||
pages: {
|
||||
rss: {
|
||||
recentNotes: "Recent notes",
|
||||
lastFewNotes: ({ count }) => `Last ${count} notes`,
|
||||
lastFewNotes: ({count}) => `Last ${count} notes`,
|
||||
},
|
||||
error: {
|
||||
title: "Not Found",
|
||||
@ -69,16 +69,18 @@ export default {
|
||||
},
|
||||
folderContent: {
|
||||
folder: "Folder",
|
||||
itemsUnderFolder: ({ count }) =>
|
||||
count === 1 ? "1 item under this folder." : `${count} items under this folder.`,
|
||||
itemsUnderFolder: ({count}) =>
|
||||
count === 1
|
||||
? "1 item under this folder."
|
||||
: `${count} items under this folder.`,
|
||||
},
|
||||
tagContent: {
|
||||
tag: "Tag",
|
||||
tagIndex: "Tag Index",
|
||||
itemsUnderTag: ({ count }) =>
|
||||
itemsUnderTag: ({count}) =>
|
||||
count === 1 ? "1 item with this tag." : `${count} items with this tag.`,
|
||||
showingFirst: ({ count }) => `Showing first ${count} tags.`,
|
||||
totalTags: ({ count }) => `Found ${count} total tags.`,
|
||||
showingFirst: ({count}) => `Showing first ${count} tags.`,
|
||||
totalTags: ({count}) => `Found ${count} total tags.`,
|
||||
},
|
||||
},
|
||||
} as const satisfies Translation
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { Translation } from "./definition"
|
||||
import {Translation} from "./definition"
|
||||
|
||||
export default {
|
||||
propertyDefaults: {
|
||||
@ -40,10 +40,10 @@ export default {
|
||||
},
|
||||
recentNotes: {
|
||||
title: "Recent Notes",
|
||||
seeRemainingMore: ({ remaining }) => `See ${remaining} more →`,
|
||||
seeRemainingMore: ({remaining}) => `See ${remaining} more →`,
|
||||
},
|
||||
transcludes: {
|
||||
transcludeOf: ({ targetSlug }) => `Transclude of ${targetSlug}`,
|
||||
transcludeOf: ({targetSlug}) => `Transclude of ${targetSlug}`,
|
||||
linkToOriginal: "Link to original",
|
||||
},
|
||||
search: {
|
||||
@ -54,13 +54,13 @@ export default {
|
||||
title: "Table of Contents",
|
||||
},
|
||||
contentMeta: {
|
||||
readingTime: ({ minutes }) => `${minutes} min read`,
|
||||
readingTime: ({minutes}) => `${minutes} min read`,
|
||||
},
|
||||
},
|
||||
pages: {
|
||||
rss: {
|
||||
recentNotes: "Recent notes",
|
||||
lastFewNotes: ({ count }) => `Last ${count} notes`,
|
||||
lastFewNotes: ({count}) => `Last ${count} notes`,
|
||||
},
|
||||
error: {
|
||||
title: "Not Found",
|
||||
@ -69,16 +69,18 @@ export default {
|
||||
},
|
||||
folderContent: {
|
||||
folder: "Folder",
|
||||
itemsUnderFolder: ({ count }) =>
|
||||
count === 1 ? "1 item under this folder." : `${count} items under this folder.`,
|
||||
itemsUnderFolder: ({count}) =>
|
||||
count === 1
|
||||
? "1 item under this folder."
|
||||
: `${count} items under this folder.`,
|
||||
},
|
||||
tagContent: {
|
||||
tag: "Tag",
|
||||
tagIndex: "Tag Index",
|
||||
itemsUnderTag: ({ count }) =>
|
||||
itemsUnderTag: ({count}) =>
|
||||
count === 1 ? "1 item with this tag." : `${count} items with this tag.`,
|
||||
showingFirst: ({ count }) => `Showing first ${count} tags.`,
|
||||
totalTags: ({ count }) => `Found ${count} total tags.`,
|
||||
showingFirst: ({count}) => `Showing first ${count} tags.`,
|
||||
totalTags: ({count}) => `Found ${count} total tags.`,
|
||||
},
|
||||
},
|
||||
} as const satisfies Translation
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { Translation } from "./definition"
|
||||
import {Translation} from "./definition"
|
||||
|
||||
export default {
|
||||
propertyDefaults: {
|
||||
@ -40,10 +40,10 @@ export default {
|
||||
},
|
||||
recentNotes: {
|
||||
title: "Notas Recientes",
|
||||
seeRemainingMore: ({ remaining }) => `Vea ${remaining} más →`,
|
||||
seeRemainingMore: ({remaining}) => `Vea ${remaining} más →`,
|
||||
},
|
||||
transcludes: {
|
||||
transcludeOf: ({ targetSlug }) => `Transcluido de ${targetSlug}`,
|
||||
transcludeOf: ({targetSlug}) => `Transcluido de ${targetSlug}`,
|
||||
linkToOriginal: "Enlace al original",
|
||||
},
|
||||
search: {
|
||||
@ -54,13 +54,13 @@ export default {
|
||||
title: "Tabla de Contenidos",
|
||||
},
|
||||
contentMeta: {
|
||||
readingTime: ({ minutes }) => `Se lee en ${minutes} min`,
|
||||
readingTime: ({minutes}) => `Se lee en ${minutes} min`,
|
||||
},
|
||||
},
|
||||
pages: {
|
||||
rss: {
|
||||
recentNotes: "Notas recientes",
|
||||
lastFewNotes: ({ count }) => `Últimas ${count} notas`,
|
||||
lastFewNotes: ({count}) => `Últimas ${count} notas`,
|
||||
},
|
||||
error: {
|
||||
title: "No se ha encontrado.",
|
||||
@ -69,16 +69,20 @@ export default {
|
||||
},
|
||||
folderContent: {
|
||||
folder: "Carpeta",
|
||||
itemsUnderFolder: ({ count }) =>
|
||||
count === 1 ? "1 artículo en esta carpeta." : `${count} artículos en esta carpeta.`,
|
||||
itemsUnderFolder: ({count}) =>
|
||||
count === 1
|
||||
? "1 artículo en esta carpeta."
|
||||
: `${count} artículos en esta carpeta.`,
|
||||
},
|
||||
tagContent: {
|
||||
tag: "Etiqueta",
|
||||
tagIndex: "Índice de Etiquetas",
|
||||
itemsUnderTag: ({ count }) =>
|
||||
count === 1 ? "1 artículo con esta etiqueta." : `${count} artículos con esta etiqueta.`,
|
||||
showingFirst: ({ count }) => `Mostrando las primeras ${count} etiquetas.`,
|
||||
totalTags: ({ count }) => `Se han encontrado ${count} etiquetas en total.`,
|
||||
itemsUnderTag: ({count}) =>
|
||||
count === 1
|
||||
? "1 artículo con esta etiqueta."
|
||||
: `${count} artículos con esta etiqueta.`,
|
||||
showingFirst: ({count}) => `Mostrando las primeras ${count} etiquetas.`,
|
||||
totalTags: ({count}) => `Se han encontrado ${count} etiquetas en total.`,
|
||||
},
|
||||
},
|
||||
} as const satisfies Translation
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { Translation } from "./definition"
|
||||
import {Translation} from "./definition"
|
||||
|
||||
export default {
|
||||
propertyDefaults: {
|
||||
@ -40,10 +40,10 @@ export default {
|
||||
},
|
||||
recentNotes: {
|
||||
title: "یادداشتهای اخیر",
|
||||
seeRemainingMore: ({ remaining }) => `${remaining} یادداشت دیگر →`,
|
||||
seeRemainingMore: ({remaining}) => `${remaining} یادداشت دیگر →`,
|
||||
},
|
||||
transcludes: {
|
||||
transcludeOf: ({ targetSlug }) => `از ${targetSlug}`,
|
||||
transcludeOf: ({targetSlug}) => `از ${targetSlug}`,
|
||||
linkToOriginal: "پیوند به اصلی",
|
||||
},
|
||||
search: {
|
||||
@ -54,13 +54,13 @@ export default {
|
||||
title: "فهرست",
|
||||
},
|
||||
contentMeta: {
|
||||
readingTime: ({ minutes }) => `زمان تقریبی مطالعه: ${minutes} دقیقه`,
|
||||
readingTime: ({minutes}) => `زمان تقریبی مطالعه: ${minutes} دقیقه`,
|
||||
},
|
||||
},
|
||||
pages: {
|
||||
rss: {
|
||||
recentNotes: "یادداشتهای اخیر",
|
||||
lastFewNotes: ({ count }) => `${count} یادداشت اخیر`,
|
||||
lastFewNotes: ({count}) => `${count} یادداشت اخیر`,
|
||||
},
|
||||
error: {
|
||||
title: "یافت نشد",
|
||||
@ -69,16 +69,18 @@ export default {
|
||||
},
|
||||
folderContent: {
|
||||
folder: "پوشه",
|
||||
itemsUnderFolder: ({ count }) =>
|
||||
count === 1 ? ".یک مطلب در این پوشه است" : `${count} مطلب در این پوشه است.`,
|
||||
itemsUnderFolder: ({count}) =>
|
||||
count === 1
|
||||
? ".یک مطلب در این پوشه است"
|
||||
: `${count} مطلب در این پوشه است.`,
|
||||
},
|
||||
tagContent: {
|
||||
tag: "برچسب",
|
||||
tagIndex: "فهرست برچسبها",
|
||||
itemsUnderTag: ({ count }) =>
|
||||
itemsUnderTag: ({count}) =>
|
||||
count === 1 ? "یک مطلب با این برچسب" : `${count} مطلب با این برچسب.`,
|
||||
showingFirst: ({ count }) => `در حال نمایش ${count} برچسب.`,
|
||||
totalTags: ({ count }) => `${count} برچسب یافت شد.`,
|
||||
showingFirst: ({count}) => `در حال نمایش ${count} برچسب.`,
|
||||
totalTags: ({count}) => `${count} برچسب یافت شد.`,
|
||||
},
|
||||
},
|
||||
} as const satisfies Translation
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { Translation } from "./definition"
|
||||
import {Translation} from "./definition"
|
||||
|
||||
export default {
|
||||
propertyDefaults: {
|
||||
@ -40,10 +40,10 @@ export default {
|
||||
},
|
||||
recentNotes: {
|
||||
title: "Notes Récentes",
|
||||
seeRemainingMore: ({ remaining }) => `Voir ${remaining} de plus →`,
|
||||
seeRemainingMore: ({remaining}) => `Voir ${remaining} de plus →`,
|
||||
},
|
||||
transcludes: {
|
||||
transcludeOf: ({ targetSlug }) => `Transclusion de ${targetSlug}`,
|
||||
transcludeOf: ({targetSlug}) => `Transclusion de ${targetSlug}`,
|
||||
linkToOriginal: "Lien vers l'original",
|
||||
},
|
||||
search: {
|
||||
@ -54,13 +54,13 @@ export default {
|
||||
title: "Table des Matières",
|
||||
},
|
||||
contentMeta: {
|
||||
readingTime: ({ minutes }) => `${minutes} min de lecture`,
|
||||
readingTime: ({minutes}) => `${minutes} min de lecture`,
|
||||
},
|
||||
},
|
||||
pages: {
|
||||
rss: {
|
||||
recentNotes: "Notes récentes",
|
||||
lastFewNotes: ({ count }) => `Les dernières ${count} notes`,
|
||||
lastFewNotes: ({count}) => `Les dernières ${count} notes`,
|
||||
},
|
||||
error: {
|
||||
title: "Introuvable",
|
||||
@ -69,16 +69,20 @@ export default {
|
||||
},
|
||||
folderContent: {
|
||||
folder: "Dossier",
|
||||
itemsUnderFolder: ({ count }) =>
|
||||
count === 1 ? "1 élément sous ce dossier." : `${count} éléments sous ce dossier.`,
|
||||
itemsUnderFolder: ({count}) =>
|
||||
count === 1
|
||||
? "1 élément sous ce dossier."
|
||||
: `${count} éléments sous ce dossier.`,
|
||||
},
|
||||
tagContent: {
|
||||
tag: "Étiquette",
|
||||
tagIndex: "Index des étiquettes",
|
||||
itemsUnderTag: ({ count }) =>
|
||||
count === 1 ? "1 élément avec cette étiquette." : `${count} éléments avec cette étiquette.`,
|
||||
showingFirst: ({ count }) => `Affichage des premières ${count} étiquettes.`,
|
||||
totalTags: ({ count }) => `Trouvé ${count} étiquettes au total.`,
|
||||
itemsUnderTag: ({count}) =>
|
||||
count === 1
|
||||
? "1 élément avec cette étiquette."
|
||||
: `${count} éléments avec cette étiquette.`,
|
||||
showingFirst: ({count}) => `Affichage des premières ${count} étiquettes.`,
|
||||
totalTags: ({count}) => `Trouvé ${count} étiquettes au total.`,
|
||||
},
|
||||
},
|
||||
} as const satisfies Translation
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { Translation } from "./definition"
|
||||
import {Translation} from "./definition"
|
||||
|
||||
export default {
|
||||
propertyDefaults: {
|
||||
@ -40,10 +40,10 @@ export default {
|
||||
},
|
||||
recentNotes: {
|
||||
title: "Legutóbbi jegyzetek",
|
||||
seeRemainingMore: ({ remaining }) => `${remaining} további megtekintése →`,
|
||||
seeRemainingMore: ({remaining}) => `${remaining} további megtekintése →`,
|
||||
},
|
||||
transcludes: {
|
||||
transcludeOf: ({ targetSlug }) => `${targetSlug} áthivatkozása`,
|
||||
transcludeOf: ({targetSlug}) => `${targetSlug} áthivatkozása`,
|
||||
linkToOriginal: "Hivatkozás az eredetire",
|
||||
},
|
||||
search: {
|
||||
@ -54,13 +54,13 @@ export default {
|
||||
title: "Tartalomjegyzék",
|
||||
},
|
||||
contentMeta: {
|
||||
readingTime: ({ minutes }) => `${minutes} perces olvasás`,
|
||||
readingTime: ({minutes}) => `${minutes} perces olvasás`,
|
||||
},
|
||||
},
|
||||
pages: {
|
||||
rss: {
|
||||
recentNotes: "Legutóbbi jegyzetek",
|
||||
lastFewNotes: ({ count }) => `Legutóbbi ${count} jegyzet`,
|
||||
lastFewNotes: ({count}) => `Legutóbbi ${count} jegyzet`,
|
||||
},
|
||||
error: {
|
||||
title: "Nem található",
|
||||
@ -69,14 +69,15 @@ export default {
|
||||
},
|
||||
folderContent: {
|
||||
folder: "Mappa",
|
||||
itemsUnderFolder: ({ count }) => `Ebben a mappában ${count} elem található.`,
|
||||
itemsUnderFolder: ({count}) =>
|
||||
`Ebben a mappában ${count} elem található.`,
|
||||
},
|
||||
tagContent: {
|
||||
tag: "Címke",
|
||||
tagIndex: "Címke index",
|
||||
itemsUnderTag: ({ count }) => `${count} elem található ezzel a címkével.`,
|
||||
showingFirst: ({ count }) => `Első ${count} címke megjelenítve.`,
|
||||
totalTags: ({ count }) => `Összesen ${count} címke található.`,
|
||||
itemsUnderTag: ({count}) => `${count} elem található ezzel a címkével.`,
|
||||
showingFirst: ({count}) => `Első ${count} címke megjelenítve.`,
|
||||
totalTags: ({count}) => `Összesen ${count} címke található.`,
|
||||
},
|
||||
},
|
||||
} as const satisfies Translation
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { Translation } from "./definition"
|
||||
import {Translation} from "./definition"
|
||||
|
||||
export default {
|
||||
propertyDefaults: {
|
||||
@ -40,10 +40,10 @@ export default {
|
||||
},
|
||||
recentNotes: {
|
||||
title: "Note recenti",
|
||||
seeRemainingMore: ({ remaining }) => `Vedi ${remaining} altro →`,
|
||||
seeRemainingMore: ({remaining}) => `Vedi ${remaining} altro →`,
|
||||
},
|
||||
transcludes: {
|
||||
transcludeOf: ({ targetSlug }) => `Transclusione di ${targetSlug}`,
|
||||
transcludeOf: ({targetSlug}) => `Transclusione di ${targetSlug}`,
|
||||
linkToOriginal: "Link all'originale",
|
||||
},
|
||||
search: {
|
||||
@ -54,13 +54,13 @@ export default {
|
||||
title: "Tabella dei contenuti",
|
||||
},
|
||||
contentMeta: {
|
||||
readingTime: ({ minutes }) => `${minutes} minuti`,
|
||||
readingTime: ({minutes}) => `${minutes} minuti`,
|
||||
},
|
||||
},
|
||||
pages: {
|
||||
rss: {
|
||||
recentNotes: "Note recenti",
|
||||
lastFewNotes: ({ count }) => `Ultime ${count} note`,
|
||||
lastFewNotes: ({count}) => `Ultime ${count} note`,
|
||||
},
|
||||
error: {
|
||||
title: "Non trovato",
|
||||
@ -69,16 +69,20 @@ export default {
|
||||
},
|
||||
folderContent: {
|
||||
folder: "Cartella",
|
||||
itemsUnderFolder: ({ count }) =>
|
||||
count === 1 ? "1 oggetto in questa cartella." : `${count} oggetti in questa cartella.`,
|
||||
itemsUnderFolder: ({count}) =>
|
||||
count === 1
|
||||
? "1 oggetto in questa cartella."
|
||||
: `${count} oggetti in questa cartella.`,
|
||||
},
|
||||
tagContent: {
|
||||
tag: "Etichetta",
|
||||
tagIndex: "Indice etichette",
|
||||
itemsUnderTag: ({ count }) =>
|
||||
count === 1 ? "1 oggetto con questa etichetta." : `${count} oggetti con questa etichetta.`,
|
||||
showingFirst: ({ count }) => `Prime ${count} etichette.`,
|
||||
totalTags: ({ count }) => `Trovate ${count} etichette totali.`,
|
||||
itemsUnderTag: ({count}) =>
|
||||
count === 1
|
||||
? "1 oggetto con questa etichetta."
|
||||
: `${count} oggetti con questa etichetta.`,
|
||||
showingFirst: ({count}) => `Prime ${count} etichette.`,
|
||||
totalTags: ({count}) => `Trovate ${count} etichette totali.`,
|
||||
},
|
||||
},
|
||||
} as const satisfies Translation
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { Translation } from "./definition"
|
||||
import {Translation} from "./definition"
|
||||
|
||||
export default {
|
||||
propertyDefaults: {
|
||||
@ -40,10 +40,10 @@ export default {
|
||||
},
|
||||
recentNotes: {
|
||||
title: "最近の記事",
|
||||
seeRemainingMore: ({ remaining }) => `さらに${remaining}件 →`,
|
||||
seeRemainingMore: ({remaining}) => `さらに${remaining}件 →`,
|
||||
},
|
||||
transcludes: {
|
||||
transcludeOf: ({ targetSlug }) => `${targetSlug}のまとめ`,
|
||||
transcludeOf: ({targetSlug}) => `${targetSlug}のまとめ`,
|
||||
linkToOriginal: "元記事へのリンク",
|
||||
},
|
||||
search: {
|
||||
@ -54,13 +54,13 @@ export default {
|
||||
title: "目次",
|
||||
},
|
||||
contentMeta: {
|
||||
readingTime: ({ minutes }) => `${minutes} min read`,
|
||||
readingTime: ({minutes}) => `${minutes} min read`,
|
||||
},
|
||||
},
|
||||
pages: {
|
||||
rss: {
|
||||
recentNotes: "最近の記事",
|
||||
lastFewNotes: ({ count }) => `最新の${count}件`,
|
||||
lastFewNotes: ({count}) => `最新の${count}件`,
|
||||
},
|
||||
error: {
|
||||
title: "Not Found",
|
||||
@ -69,14 +69,14 @@ export default {
|
||||
},
|
||||
folderContent: {
|
||||
folder: "フォルダ",
|
||||
itemsUnderFolder: ({ count }) => `${count}件のページ`,
|
||||
itemsUnderFolder: ({count}) => `${count}件のページ`,
|
||||
},
|
||||
tagContent: {
|
||||
tag: "タグ",
|
||||
tagIndex: "タグ一覧",
|
||||
itemsUnderTag: ({ count }) => `${count}件のページ`,
|
||||
showingFirst: ({ count }) => `のうち最初の${count}件を表示しています`,
|
||||
totalTags: ({ count }) => `全${count}個のタグを表示中`,
|
||||
itemsUnderTag: ({count}) => `${count}件のページ`,
|
||||
showingFirst: ({count}) => `のうち最初の${count}件を表示しています`,
|
||||
totalTags: ({count}) => `全${count}個のタグを表示中`,
|
||||
},
|
||||
},
|
||||
} as const satisfies Translation
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { Translation } from "./definition"
|
||||
import {Translation} from "./definition"
|
||||
|
||||
export default {
|
||||
propertyDefaults: {
|
||||
@ -40,10 +40,10 @@ export default {
|
||||
},
|
||||
recentNotes: {
|
||||
title: "최근 게시글",
|
||||
seeRemainingMore: ({ remaining }) => `${remaining}건 더보기 →`,
|
||||
seeRemainingMore: ({remaining}) => `${remaining}건 더보기 →`,
|
||||
},
|
||||
transcludes: {
|
||||
transcludeOf: ({ targetSlug }) => `${targetSlug}의 포함`,
|
||||
transcludeOf: ({targetSlug}) => `${targetSlug}의 포함`,
|
||||
linkToOriginal: "원본 링크",
|
||||
},
|
||||
search: {
|
||||
@ -54,13 +54,13 @@ export default {
|
||||
title: "목차",
|
||||
},
|
||||
contentMeta: {
|
||||
readingTime: ({ minutes }) => `${minutes} min read`,
|
||||
readingTime: ({minutes}) => `${minutes} min read`,
|
||||
},
|
||||
},
|
||||
pages: {
|
||||
rss: {
|
||||
recentNotes: "최근 게시글",
|
||||
lastFewNotes: ({ count }) => `최근 ${count} 건`,
|
||||
lastFewNotes: ({count}) => `최근 ${count} 건`,
|
||||
},
|
||||
error: {
|
||||
title: "Not Found",
|
||||
@ -69,14 +69,14 @@ export default {
|
||||
},
|
||||
folderContent: {
|
||||
folder: "폴더",
|
||||
itemsUnderFolder: ({ count }) => `${count}건의 항목`,
|
||||
itemsUnderFolder: ({count}) => `${count}건의 항목`,
|
||||
},
|
||||
tagContent: {
|
||||
tag: "태그",
|
||||
tagIndex: "태그 목록",
|
||||
itemsUnderTag: ({ count }) => `${count}건의 항목`,
|
||||
showingFirst: ({ count }) => `처음 ${count}개의 태그`,
|
||||
totalTags: ({ count }) => `총 ${count}개의 태그를 찾았습니다.`,
|
||||
itemsUnderTag: ({count}) => `${count}건의 항목`,
|
||||
showingFirst: ({count}) => `처음 ${count}개의 태그`,
|
||||
totalTags: ({count}) => `총 ${count}개의 태그를 찾았습니다.`,
|
||||
},
|
||||
},
|
||||
} as const satisfies Translation
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { Translation } from "./definition"
|
||||
import {Translation} from "./definition"
|
||||
|
||||
export default {
|
||||
propertyDefaults: {
|
||||
@ -40,10 +40,10 @@ export default {
|
||||
},
|
||||
recentNotes: {
|
||||
title: "Recente notities",
|
||||
seeRemainingMore: ({ remaining }) => `Zie ${remaining} meer →`,
|
||||
seeRemainingMore: ({remaining}) => `Zie ${remaining} meer →`,
|
||||
},
|
||||
transcludes: {
|
||||
transcludeOf: ({ targetSlug }) => `Invoeging van ${targetSlug}`,
|
||||
transcludeOf: ({targetSlug}) => `Invoeging van ${targetSlug}`,
|
||||
linkToOriginal: "Link naar origineel",
|
||||
},
|
||||
search: {
|
||||
@ -54,14 +54,14 @@ export default {
|
||||
title: "Inhoudsopgave",
|
||||
},
|
||||
contentMeta: {
|
||||
readingTime: ({ minutes }) =>
|
||||
readingTime: ({minutes}) =>
|
||||
minutes === 1 ? "1 minuut leestijd" : `${minutes} minuten leestijd`,
|
||||
},
|
||||
},
|
||||
pages: {
|
||||
rss: {
|
||||
recentNotes: "Recente notities",
|
||||
lastFewNotes: ({ count }) => `Laatste ${count} notities`,
|
||||
lastFewNotes: ({count}) => `Laatste ${count} notities`,
|
||||
},
|
||||
error: {
|
||||
title: "Niet gevonden",
|
||||
@ -70,17 +70,17 @@ export default {
|
||||
},
|
||||
folderContent: {
|
||||
folder: "Map",
|
||||
itemsUnderFolder: ({ count }) =>
|
||||
itemsUnderFolder: ({count}) =>
|
||||
count === 1 ? "1 item in deze map." : `${count} items in deze map.`,
|
||||
},
|
||||
tagContent: {
|
||||
tag: "Label",
|
||||
tagIndex: "Label-index",
|
||||
itemsUnderTag: ({ count }) =>
|
||||
itemsUnderTag: ({count}) =>
|
||||
count === 1 ? "1 item met dit label." : `${count} items met dit label.`,
|
||||
showingFirst: ({ count }) =>
|
||||
showingFirst: ({count}) =>
|
||||
count === 1 ? "Eerste label tonen." : `Eerste ${count} labels tonen.`,
|
||||
totalTags: ({ count }) => `${count} labels gevonden.`,
|
||||
totalTags: ({count}) => `${count} labels gevonden.`,
|
||||
},
|
||||
},
|
||||
} as const satisfies Translation
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { Translation } from "./definition"
|
||||
import {Translation} from "./definition"
|
||||
|
||||
export default {
|
||||
propertyDefaults: {
|
||||
@ -40,10 +40,10 @@ export default {
|
||||
},
|
||||
recentNotes: {
|
||||
title: "Najnowsze notatki",
|
||||
seeRemainingMore: ({ remaining }) => `Zobacz ${remaining} nastepnych →`,
|
||||
seeRemainingMore: ({remaining}) => `Zobacz ${remaining} nastepnych →`,
|
||||
},
|
||||
transcludes: {
|
||||
transcludeOf: ({ targetSlug }) => `Osadzone ${targetSlug}`,
|
||||
transcludeOf: ({targetSlug}) => `Osadzone ${targetSlug}`,
|
||||
linkToOriginal: "Łącze do oryginału",
|
||||
},
|
||||
search: {
|
||||
@ -54,13 +54,13 @@ export default {
|
||||
title: "Spis treści",
|
||||
},
|
||||
contentMeta: {
|
||||
readingTime: ({ minutes }) => `${minutes} min. czytania `,
|
||||
readingTime: ({minutes}) => `${minutes} min. czytania `,
|
||||
},
|
||||
},
|
||||
pages: {
|
||||
rss: {
|
||||
recentNotes: "Najnowsze notatki",
|
||||
lastFewNotes: ({ count }) => `Ostatnie ${count} notatek`,
|
||||
lastFewNotes: ({count}) => `Ostatnie ${count} notatek`,
|
||||
},
|
||||
error: {
|
||||
title: "Nie znaleziono",
|
||||
@ -69,16 +69,20 @@ export default {
|
||||
},
|
||||
folderContent: {
|
||||
folder: "Folder",
|
||||
itemsUnderFolder: ({ count }) =>
|
||||
count === 1 ? "W tym folderze jest 1 element." : `Elementów w folderze: ${count}.`,
|
||||
itemsUnderFolder: ({count}) =>
|
||||
count === 1
|
||||
? "W tym folderze jest 1 element."
|
||||
: `Elementów w folderze: ${count}.`,
|
||||
},
|
||||
tagContent: {
|
||||
tag: "Znacznik",
|
||||
tagIndex: "Spis znaczników",
|
||||
itemsUnderTag: ({ count }) =>
|
||||
count === 1 ? "Oznaczony 1 element." : `Elementów z tym znacznikiem: ${count}.`,
|
||||
showingFirst: ({ count }) => `Pokazuje ${count} pierwszych znaczników.`,
|
||||
totalTags: ({ count }) => `Znalezionych wszystkich znaczników: ${count}.`,
|
||||
itemsUnderTag: ({count}) =>
|
||||
count === 1
|
||||
? "Oznaczony 1 element."
|
||||
: `Elementów z tym znacznikiem: ${count}.`,
|
||||
showingFirst: ({count}) => `Pokazuje ${count} pierwszych znaczników.`,
|
||||
totalTags: ({count}) => `Znalezionych wszystkich znaczników: ${count}.`,
|
||||
},
|
||||
},
|
||||
} as const satisfies Translation
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { Translation } from "./definition"
|
||||
import {Translation} from "./definition"
|
||||
|
||||
export default {
|
||||
propertyDefaults: {
|
||||
@ -40,10 +40,10 @@ export default {
|
||||
},
|
||||
recentNotes: {
|
||||
title: "Notas recentes",
|
||||
seeRemainingMore: ({ remaining }) => `Veja mais ${remaining} →`,
|
||||
seeRemainingMore: ({remaining}) => `Veja mais ${remaining} →`,
|
||||
},
|
||||
transcludes: {
|
||||
transcludeOf: ({ targetSlug }) => `Transcrever de ${targetSlug}`,
|
||||
transcludeOf: ({targetSlug}) => `Transcrever de ${targetSlug}`,
|
||||
linkToOriginal: "Link ao original",
|
||||
},
|
||||
search: {
|
||||
@ -54,13 +54,13 @@ export default {
|
||||
title: "Sumário",
|
||||
},
|
||||
contentMeta: {
|
||||
readingTime: ({ minutes }) => `Leitura de ${minutes} min`,
|
||||
readingTime: ({minutes}) => `Leitura de ${minutes} min`,
|
||||
},
|
||||
},
|
||||
pages: {
|
||||
rss: {
|
||||
recentNotes: "Notas recentes",
|
||||
lastFewNotes: ({ count }) => `Últimas ${count} notas`,
|
||||
lastFewNotes: ({count}) => `Últimas ${count} notas`,
|
||||
},
|
||||
error: {
|
||||
title: "Não encontrado",
|
||||
@ -69,16 +69,16 @@ export default {
|
||||
},
|
||||
folderContent: {
|
||||
folder: "Arquivo",
|
||||
itemsUnderFolder: ({ count }) =>
|
||||
itemsUnderFolder: ({count}) =>
|
||||
count === 1 ? "1 item neste arquivo." : `${count} items neste arquivo.`,
|
||||
},
|
||||
tagContent: {
|
||||
tag: "Tag",
|
||||
tagIndex: "Sumário de Tags",
|
||||
itemsUnderTag: ({ count }) =>
|
||||
itemsUnderTag: ({count}) =>
|
||||
count === 1 ? "1 item com esta tag." : `${count} items com esta tag.`,
|
||||
showingFirst: ({ count }) => `Mostrando as ${count} primeiras tags.`,
|
||||
totalTags: ({ count }) => `Encontradas ${count} tags.`,
|
||||
showingFirst: ({count}) => `Mostrando as ${count} primeiras tags.`,
|
||||
totalTags: ({count}) => `Encontradas ${count} tags.`,
|
||||
},
|
||||
},
|
||||
} as const satisfies Translation
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { Translation } from "./definition"
|
||||
import {Translation} from "./definition"
|
||||
|
||||
export default {
|
||||
propertyDefaults: {
|
||||
@ -40,10 +40,10 @@ export default {
|
||||
},
|
||||
recentNotes: {
|
||||
title: "Notițe recente",
|
||||
seeRemainingMore: ({ remaining }) => `Vezi încă ${remaining} →`,
|
||||
seeRemainingMore: ({remaining}) => `Vezi încă ${remaining} →`,
|
||||
},
|
||||
transcludes: {
|
||||
transcludeOf: ({ targetSlug }) => `Extras din ${targetSlug}`,
|
||||
transcludeOf: ({targetSlug}) => `Extras din ${targetSlug}`,
|
||||
linkToOriginal: "Legătură către original",
|
||||
},
|
||||
search: {
|
||||
@ -54,14 +54,14 @@ export default {
|
||||
title: "Cuprins",
|
||||
},
|
||||
contentMeta: {
|
||||
readingTime: ({ minutes }) =>
|
||||
readingTime: ({minutes}) =>
|
||||
minutes == 1 ? `lectură de 1 minut` : `lectură de ${minutes} minute`,
|
||||
},
|
||||
},
|
||||
pages: {
|
||||
rss: {
|
||||
recentNotes: "Notițe recente",
|
||||
lastFewNotes: ({ count }) => `Ultimele ${count} notițe`,
|
||||
lastFewNotes: ({count}) => `Ultimele ${count} notițe`,
|
||||
},
|
||||
error: {
|
||||
title: "Pagina nu a fost găsită",
|
||||
@ -70,16 +70,20 @@ export default {
|
||||
},
|
||||
folderContent: {
|
||||
folder: "Dosar",
|
||||
itemsUnderFolder: ({ count }) =>
|
||||
count === 1 ? "1 articol în acest dosar." : `${count} elemente în acest dosar.`,
|
||||
itemsUnderFolder: ({count}) =>
|
||||
count === 1
|
||||
? "1 articol în acest dosar."
|
||||
: `${count} elemente în acest dosar.`,
|
||||
},
|
||||
tagContent: {
|
||||
tag: "Etichetă",
|
||||
tagIndex: "Indexul etichetelor",
|
||||
itemsUnderTag: ({ count }) =>
|
||||
count === 1 ? "1 articol cu această etichetă." : `${count} articole cu această etichetă.`,
|
||||
showingFirst: ({ count }) => `Se afișează primele ${count} etichete.`,
|
||||
totalTags: ({ count }) => `Au fost găsite ${count} etichete în total.`,
|
||||
itemsUnderTag: ({count}) =>
|
||||
count === 1
|
||||
? "1 articol cu această etichetă."
|
||||
: `${count} articole cu această etichetă.`,
|
||||
showingFirst: ({count}) => `Se afișează primele ${count} etichete.`,
|
||||
totalTags: ({count}) => `Au fost găsite ${count} etichete în total.`,
|
||||
},
|
||||
},
|
||||
} as const satisfies Translation
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { Translation } from "./definition"
|
||||
import {Translation} from "./definition"
|
||||
|
||||
export default {
|
||||
propertyDefaults: {
|
||||
@ -40,11 +40,11 @@ export default {
|
||||
},
|
||||
recentNotes: {
|
||||
title: "Недавние заметки",
|
||||
seeRemainingMore: ({ remaining }) =>
|
||||
seeRemainingMore: ({remaining}) =>
|
||||
`Посмотреть оставш${getForm(remaining, "уюся", "иеся", "иеся")} ${remaining} →`,
|
||||
},
|
||||
transcludes: {
|
||||
transcludeOf: ({ targetSlug }) => `Переход из ${targetSlug}`,
|
||||
transcludeOf: ({targetSlug}) => `Переход из ${targetSlug}`,
|
||||
linkToOriginal: "Ссылка на оригинал",
|
||||
},
|
||||
search: {
|
||||
@ -55,13 +55,13 @@ export default {
|
||||
title: "Оглавление",
|
||||
},
|
||||
contentMeta: {
|
||||
readingTime: ({ minutes }) => `время чтения ~${minutes} мин.`,
|
||||
readingTime: ({minutes}) => `время чтения ~${minutes} мин.`,
|
||||
},
|
||||
},
|
||||
pages: {
|
||||
rss: {
|
||||
recentNotes: "Недавние заметки",
|
||||
lastFewNotes: ({ count }) =>
|
||||
lastFewNotes: ({count}) =>
|
||||
`Последн${getForm(count, "яя", "ие", "ие")} ${count} замет${getForm(count, "ка", "ки", "ок")}`,
|
||||
},
|
||||
error: {
|
||||
@ -71,21 +71,28 @@ export default {
|
||||
},
|
||||
folderContent: {
|
||||
folder: "Папка",
|
||||
itemsUnderFolder: ({ count }) =>
|
||||
itemsUnderFolder: ({count}) =>
|
||||
`в этой папке ${count} элемент${getForm(count, "", "а", "ов")}`,
|
||||
},
|
||||
tagContent: {
|
||||
tag: "Тег",
|
||||
tagIndex: "Индекс тегов",
|
||||
itemsUnderTag: ({ count }) => `с этим тегом ${count} элемент${getForm(count, "", "а", "ов")}`,
|
||||
showingFirst: ({ count }) =>
|
||||
itemsUnderTag: ({count}) =>
|
||||
`с этим тегом ${count} элемент${getForm(count, "", "а", "ов")}`,
|
||||
showingFirst: ({count}) =>
|
||||
`Показыва${getForm(count, "ется", "ются", "ются")} ${count} тег${getForm(count, "", "а", "ов")}`,
|
||||
totalTags: ({ count }) => `Всего ${count} тег${getForm(count, "", "а", "ов")}`,
|
||||
totalTags: ({count}) =>
|
||||
`Всего ${count} тег${getForm(count, "", "а", "ов")}`,
|
||||
},
|
||||
},
|
||||
} as const satisfies Translation
|
||||
|
||||
function getForm(number: number, form1: string, form2: string, form5: string): string {
|
||||
function getForm(
|
||||
number: number,
|
||||
form1: string,
|
||||
form2: string,
|
||||
form5: string,
|
||||
): string {
|
||||
const remainder100 = number % 100
|
||||
const remainder10 = remainder100 % 10
|
||||
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { Translation } from "./definition"
|
||||
import {Translation} from "./definition"
|
||||
|
||||
export default {
|
||||
propertyDefaults: {
|
||||
@ -40,10 +40,10 @@ export default {
|
||||
},
|
||||
recentNotes: {
|
||||
title: "Останні нотатки",
|
||||
seeRemainingMore: ({ remaining }) => `Переглянути ще ${remaining} →`,
|
||||
seeRemainingMore: ({remaining}) => `Переглянути ще ${remaining} →`,
|
||||
},
|
||||
transcludes: {
|
||||
transcludeOf: ({ targetSlug }) => `Видобуто з ${targetSlug}`,
|
||||
transcludeOf: ({targetSlug}) => `Видобуто з ${targetSlug}`,
|
||||
linkToOriginal: "Посилання на оригінал",
|
||||
},
|
||||
search: {
|
||||
@ -54,13 +54,13 @@ export default {
|
||||
title: "Зміст",
|
||||
},
|
||||
contentMeta: {
|
||||
readingTime: ({ minutes }) => `${minutes} хв читання`,
|
||||
readingTime: ({minutes}) => `${minutes} хв читання`,
|
||||
},
|
||||
},
|
||||
pages: {
|
||||
rss: {
|
||||
recentNotes: "Останні нотатки",
|
||||
lastFewNotes: ({ count }) => `Останні нотатки: ${count}`,
|
||||
lastFewNotes: ({count}) => `Останні нотатки: ${count}`,
|
||||
},
|
||||
error: {
|
||||
title: "Не знайдено",
|
||||
@ -69,16 +69,20 @@ export default {
|
||||
},
|
||||
folderContent: {
|
||||
folder: "Тека",
|
||||
itemsUnderFolder: ({ count }) =>
|
||||
count === 1 ? "У цій теці 1 елемент." : `Елементів у цій теці: ${count}.`,
|
||||
itemsUnderFolder: ({count}) =>
|
||||
count === 1
|
||||
? "У цій теці 1 елемент."
|
||||
: `Елементів у цій теці: ${count}.`,
|
||||
},
|
||||
tagContent: {
|
||||
tag: "Мітка",
|
||||
tagIndex: "Індекс мітки",
|
||||
itemsUnderTag: ({ count }) =>
|
||||
count === 1 ? "1 елемент з цією міткою." : `Елементів з цією міткою: ${count}.`,
|
||||
showingFirst: ({ count }) => `Показ перших ${count} міток.`,
|
||||
totalTags: ({ count }) => `Всього знайдено міток: ${count}.`,
|
||||
itemsUnderTag: ({count}) =>
|
||||
count === 1
|
||||
? "1 елемент з цією міткою."
|
||||
: `Елементів з цією міткою: ${count}.`,
|
||||
showingFirst: ({count}) => `Показ перших ${count} міток.`,
|
||||
totalTags: ({count}) => `Всього знайдено міток: ${count}.`,
|
||||
},
|
||||
},
|
||||
} as const satisfies Translation
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { Translation } from "./definition"
|
||||
import {Translation} from "./definition"
|
||||
|
||||
export default {
|
||||
propertyDefaults: {
|
||||
@ -40,10 +40,10 @@ export default {
|
||||
},
|
||||
recentNotes: {
|
||||
title: "Bài viết gần đây",
|
||||
seeRemainingMore: ({ remaining }) => `Xem ${remaining} thêm →`,
|
||||
seeRemainingMore: ({remaining}) => `Xem ${remaining} thêm →`,
|
||||
},
|
||||
transcludes: {
|
||||
transcludeOf: ({ targetSlug }) => `Bao gồm ${targetSlug}`,
|
||||
transcludeOf: ({targetSlug}) => `Bao gồm ${targetSlug}`,
|
||||
linkToOriginal: "Liên Kết Gốc",
|
||||
},
|
||||
search: {
|
||||
@ -54,13 +54,13 @@ export default {
|
||||
title: "Bảng Nội Dung",
|
||||
},
|
||||
contentMeta: {
|
||||
readingTime: ({ minutes }) => `đọc ${minutes} phút`,
|
||||
readingTime: ({minutes}) => `đọc ${minutes} phút`,
|
||||
},
|
||||
},
|
||||
pages: {
|
||||
rss: {
|
||||
recentNotes: "Những bài gần đây",
|
||||
lastFewNotes: ({ count }) => `${count} Bài gần đây`,
|
||||
lastFewNotes: ({count}) => `${count} Bài gần đây`,
|
||||
},
|
||||
error: {
|
||||
title: "Không Tìm Thấy",
|
||||
@ -69,16 +69,18 @@ export default {
|
||||
},
|
||||
folderContent: {
|
||||
folder: "Thư Mục",
|
||||
itemsUnderFolder: ({ count }) =>
|
||||
count === 1 ? "1 mục trong thư mục này." : `${count} mục trong thư mục này.`,
|
||||
itemsUnderFolder: ({count}) =>
|
||||
count === 1
|
||||
? "1 mục trong thư mục này."
|
||||
: `${count} mục trong thư mục này.`,
|
||||
},
|
||||
tagContent: {
|
||||
tag: "Thẻ",
|
||||
tagIndex: "Thẻ Mục Lục",
|
||||
itemsUnderTag: ({ count }) =>
|
||||
itemsUnderTag: ({count}) =>
|
||||
count === 1 ? "1 mục gắn thẻ này." : `${count} mục gắn thẻ này.`,
|
||||
showingFirst: ({ count }) => `Hiển thị trước ${count} thẻ.`,
|
||||
totalTags: ({ count }) => `Tìm thấy ${count} thẻ tổng cộng.`,
|
||||
showingFirst: ({count}) => `Hiển thị trước ${count} thẻ.`,
|
||||
totalTags: ({count}) => `Tìm thấy ${count} thẻ tổng cộng.`,
|
||||
},
|
||||
},
|
||||
} as const satisfies Translation
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { Translation } from "./definition"
|
||||
import {Translation} from "./definition"
|
||||
|
||||
export default {
|
||||
propertyDefaults: {
|
||||
@ -40,10 +40,10 @@ export default {
|
||||
},
|
||||
recentNotes: {
|
||||
title: "最近的笔记",
|
||||
seeRemainingMore: ({ remaining }) => `查看更多${remaining}篇笔记 →`,
|
||||
seeRemainingMore: ({remaining}) => `查看更多${remaining}篇笔记 →`,
|
||||
},
|
||||
transcludes: {
|
||||
transcludeOf: ({ targetSlug }) => `包含${targetSlug}`,
|
||||
transcludeOf: ({targetSlug}) => `包含${targetSlug}`,
|
||||
linkToOriginal: "指向原始笔记的链接",
|
||||
},
|
||||
search: {
|
||||
@ -54,13 +54,13 @@ export default {
|
||||
title: "目录",
|
||||
},
|
||||
contentMeta: {
|
||||
readingTime: ({ minutes }) => `${minutes}分钟阅读`,
|
||||
readingTime: ({minutes}) => `${minutes}分钟阅读`,
|
||||
},
|
||||
},
|
||||
pages: {
|
||||
rss: {
|
||||
recentNotes: "最近的笔记",
|
||||
lastFewNotes: ({ count }) => `最近的${count}条笔记`,
|
||||
lastFewNotes: ({count}) => `最近的${count}条笔记`,
|
||||
},
|
||||
error: {
|
||||
title: "无法找到",
|
||||
@ -69,14 +69,14 @@ export default {
|
||||
},
|
||||
folderContent: {
|
||||
folder: "文件夹",
|
||||
itemsUnderFolder: ({ count }) => `此文件夹下有${count}条笔记。`,
|
||||
itemsUnderFolder: ({count}) => `此文件夹下有${count}条笔记。`,
|
||||
},
|
||||
tagContent: {
|
||||
tag: "标签",
|
||||
tagIndex: "标签索引",
|
||||
itemsUnderTag: ({ count }) => `此标签下有${count}条笔记。`,
|
||||
showingFirst: ({ count }) => `显示前${count}个标签。`,
|
||||
totalTags: ({ count }) => `总共有${count}个标签。`,
|
||||
itemsUnderTag: ({count}) => `此标签下有${count}条笔记。`,
|
||||
showingFirst: ({count}) => `显示前${count}个标签。`,
|
||||
totalTags: ({count}) => `总共有${count}个标签。`,
|
||||
},
|
||||
},
|
||||
} as const satisfies Translation
|
||||
|
||||
@ -1,14 +1,14 @@
|
||||
import { QuartzEmitterPlugin } from "../types"
|
||||
import { QuartzComponentProps } from "../../components/types"
|
||||
import {QuartzEmitterPlugin} from "../types"
|
||||
import {QuartzComponentProps} from "../../components/types"
|
||||
import BodyConstructor from "../../components/Body"
|
||||
import { pageResources, renderPage } from "../../components/renderPage"
|
||||
import { FullPageLayout } from "../../cfg"
|
||||
import { FilePath, FullSlug } from "../../util/path"
|
||||
import { sharedPageComponents } from "../../../quartz.layout"
|
||||
import { NotFound } from "../../components"
|
||||
import { defaultProcessedContent } from "../vfile"
|
||||
import { write } from "./helpers"
|
||||
import { i18n } from "../../i18n"
|
||||
import {pageResources, renderPage} from "../../components/renderPage"
|
||||
import {FullPageLayout} from "../../cfg"
|
||||
import {FilePath, FullSlug} from "../../util/path"
|
||||
import {sharedPageComponents} from "../../../quartz.layout"
|
||||
import {NotFound} from "../../components"
|
||||
import {defaultProcessedContent} from "../vfile"
|
||||
import {write} from "./helpers"
|
||||
import {i18n} from "../../i18n"
|
||||
import DepGraph from "../../depgraph"
|
||||
|
||||
export const NotFoundPage: QuartzEmitterPlugin = () => {
|
||||
@ -20,7 +20,7 @@ export const NotFoundPage: QuartzEmitterPlugin = () => {
|
||||
right: [],
|
||||
}
|
||||
|
||||
const { head: Head, pageBody, footer: Footer } = opts
|
||||
const {head: Head, pageBody, footer: Footer} = opts
|
||||
const Body = BodyConstructor()
|
||||
|
||||
return {
|
||||
@ -43,7 +43,7 @@ export const NotFoundPage: QuartzEmitterPlugin = () => {
|
||||
slug,
|
||||
text: notFound,
|
||||
description: notFound,
|
||||
frontmatter: { title: notFound, tags: [] },
|
||||
frontmatter: {title: notFound, tags: []},
|
||||
})
|
||||
const componentData: QuartzComponentProps = {
|
||||
ctx,
|
||||
@ -58,7 +58,13 @@ export const NotFoundPage: QuartzEmitterPlugin = () => {
|
||||
return [
|
||||
await write({
|
||||
ctx,
|
||||
content: renderPage(cfg, slug, componentData, opts, externalResources),
|
||||
content: renderPage(
|
||||
cfg,
|
||||
slug,
|
||||
componentData,
|
||||
opts,
|
||||
externalResources,
|
||||
),
|
||||
slug,
|
||||
ext: ".html",
|
||||
}),
|
||||
|
||||
@ -1,7 +1,13 @@
|
||||
import { FilePath, FullSlug, joinSegments, resolveRelative, simplifySlug } from "../../util/path"
|
||||
import { QuartzEmitterPlugin } from "../types"
|
||||
import {
|
||||
FilePath,
|
||||
FullSlug,
|
||||
joinSegments,
|
||||
resolveRelative,
|
||||
simplifySlug,
|
||||
} from "../../util/path"
|
||||
import {QuartzEmitterPlugin} from "../types"
|
||||
import path from "path"
|
||||
import { write } from "./helpers"
|
||||
import {write} from "./helpers"
|
||||
import DepGraph from "../../depgraph"
|
||||
|
||||
export const AliasRedirects: QuartzEmitterPlugin = () => ({
|
||||
@ -12,11 +18,16 @@ export const AliasRedirects: QuartzEmitterPlugin = () => ({
|
||||
async getDependencyGraph(ctx, content, _resources) {
|
||||
const graph = new DepGraph<FilePath>()
|
||||
|
||||
const { argv } = ctx
|
||||
const {argv} = ctx
|
||||
for (const [_tree, file] of content) {
|
||||
const dir = path.posix.relative(argv.directory, path.dirname(file.data.filePath!))
|
||||
const dir = path.posix.relative(
|
||||
argv.directory,
|
||||
path.dirname(file.data.filePath!),
|
||||
)
|
||||
const aliases = file.data.frontmatter?.aliases ?? []
|
||||
const slugs = aliases.map((alias) => path.posix.join(dir, alias) as FullSlug)
|
||||
const slugs = aliases.map(
|
||||
(alias) => path.posix.join(dir, alias) as FullSlug,
|
||||
)
|
||||
const permalink = file.data.frontmatter?.permalink
|
||||
if (typeof permalink === "string") {
|
||||
slugs.push(permalink as FullSlug)
|
||||
@ -28,21 +39,29 @@ export const AliasRedirects: QuartzEmitterPlugin = () => ({
|
||||
slug = joinSegments(slug, "index") as FullSlug
|
||||
}
|
||||
|
||||
graph.addEdge(file.data.filePath!, joinSegments(argv.output, slug + ".html") as FilePath)
|
||||
graph.addEdge(
|
||||
file.data.filePath!,
|
||||
joinSegments(argv.output, slug + ".html") as FilePath,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
return graph
|
||||
},
|
||||
async emit(ctx, content, _resources): Promise<FilePath[]> {
|
||||
const { argv } = ctx
|
||||
const {argv} = ctx
|
||||
const fps: FilePath[] = []
|
||||
|
||||
for (const [_tree, file] of content) {
|
||||
const ogSlug = simplifySlug(file.data.slug!)
|
||||
const dir = path.posix.relative(argv.directory, path.dirname(file.data.filePath!))
|
||||
const dir = path.posix.relative(
|
||||
argv.directory,
|
||||
path.dirname(file.data.filePath!),
|
||||
)
|
||||
const aliases = file.data.frontmatter?.aliases ?? []
|
||||
const slugs: FullSlug[] = aliases.map((alias) => path.posix.join(dir, alias) as FullSlug)
|
||||
const slugs: FullSlug[] = aliases.map(
|
||||
(alias) => path.posix.join(dir, alias) as FullSlug,
|
||||
)
|
||||
const permalink = file.data.frontmatter?.permalink
|
||||
if (typeof permalink === "string") {
|
||||
slugs.push(permalink as FullSlug)
|
||||
|
||||
@ -1,15 +1,18 @@
|
||||
import { FilePath, joinSegments, slugifyFilePath } from "../../util/path"
|
||||
import { QuartzEmitterPlugin } from "../types"
|
||||
import {FilePath, joinSegments, slugifyFilePath} from "../../util/path"
|
||||
import {QuartzEmitterPlugin} from "../types"
|
||||
import path from "path"
|
||||
import fs from "fs"
|
||||
import { glob } from "../../util/glob"
|
||||
import {glob} from "../../util/glob"
|
||||
import DepGraph from "../../depgraph"
|
||||
import { Argv } from "../../util/ctx"
|
||||
import { QuartzConfig } from "../../cfg"
|
||||
import {Argv} from "../../util/ctx"
|
||||
import {QuartzConfig} from "../../cfg"
|
||||
|
||||
const filesToCopy = async (argv: Argv, cfg: QuartzConfig) => {
|
||||
// glob all non MD files in content folder and copy it over
|
||||
return await glob("**", argv.directory, ["**/*.md", ...cfg.configuration.ignorePatterns])
|
||||
return await glob("**", argv.directory, [
|
||||
"**/*.md",
|
||||
...cfg.configuration.ignorePatterns,
|
||||
])
|
||||
}
|
||||
|
||||
export const Assets: QuartzEmitterPlugin = () => {
|
||||
@ -19,7 +22,7 @@ export const Assets: QuartzEmitterPlugin = () => {
|
||||
return []
|
||||
},
|
||||
async getDependencyGraph(ctx, _content, _resources) {
|
||||
const { argv, cfg } = ctx
|
||||
const {argv, cfg} = ctx
|
||||
const graph = new DepGraph<FilePath>()
|
||||
|
||||
const fps = await filesToCopy(argv, cfg)
|
||||
@ -36,7 +39,7 @@ export const Assets: QuartzEmitterPlugin = () => {
|
||||
|
||||
return graph
|
||||
},
|
||||
async emit({ argv, cfg }, _content, _resources): Promise<FilePath[]> {
|
||||
async emit({argv, cfg}, _content, _resources): Promise<FilePath[]> {
|
||||
const assetsPath = argv.output
|
||||
const fps = await filesToCopy(argv, cfg)
|
||||
const res: FilePath[] = []
|
||||
@ -47,7 +50,7 @@ export const Assets: QuartzEmitterPlugin = () => {
|
||||
|
||||
const dest = joinSegments(assetsPath, name) as FilePath
|
||||
const dir = path.dirname(dest) as FilePath
|
||||
await fs.promises.mkdir(dir, { recursive: true }) // ensure dir exists
|
||||
await fs.promises.mkdir(dir, {recursive: true}) // ensure dir exists
|
||||
await fs.promises.copyFile(src, dest)
|
||||
res.push(dest)
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import { FilePath, joinSegments } from "../../util/path"
|
||||
import { QuartzEmitterPlugin } from "../types"
|
||||
import {FilePath, joinSegments} from "../../util/path"
|
||||
import {QuartzEmitterPlugin} from "../types"
|
||||
import fs from "fs"
|
||||
import chalk from "chalk"
|
||||
import DepGraph from "../../depgraph"
|
||||
@ -17,9 +17,13 @@ export const CNAME: QuartzEmitterPlugin = () => ({
|
||||
async getDependencyGraph(_ctx, _content, _resources) {
|
||||
return new DepGraph<FilePath>()
|
||||
},
|
||||
async emit({ argv, cfg }, _content, _resources): Promise<FilePath[]> {
|
||||
async emit({argv, cfg}, _content, _resources): Promise<FilePath[]> {
|
||||
if (!cfg.configuration.baseUrl) {
|
||||
console.warn(chalk.yellow("CNAME emitter requires `baseUrl` to be set in your configuration"))
|
||||
console.warn(
|
||||
chalk.yellow(
|
||||
"CNAME emitter requires `baseUrl` to be set in your configuration",
|
||||
),
|
||||
)
|
||||
return []
|
||||
}
|
||||
const path = joinSegments(argv.output, "CNAME")
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import { FilePath, FullSlug, joinSegments } from "../../util/path"
|
||||
import { QuartzEmitterPlugin } from "../types"
|
||||
import {FilePath, FullSlug, joinSegments} from "../../util/path"
|
||||
import {QuartzEmitterPlugin} from "../types"
|
||||
|
||||
// @ts-ignore
|
||||
import spaRouterScript from "../../components/scripts/spa.inline"
|
||||
@ -7,12 +7,12 @@ import spaRouterScript from "../../components/scripts/spa.inline"
|
||||
import popoverScript from "../../components/scripts/popover.inline"
|
||||
import styles from "../../styles/custom.scss"
|
||||
import popoverStyle from "../../components/styles/popover.scss"
|
||||
import { BuildCtx } from "../../util/ctx"
|
||||
import { QuartzComponent } from "../../components/types"
|
||||
import { googleFontHref, joinStyles } from "../../util/theme"
|
||||
import { Features, transform } from "lightningcss"
|
||||
import { transform as transpile } from "esbuild"
|
||||
import { write } from "./helpers"
|
||||
import {BuildCtx} from "../../util/ctx"
|
||||
import {QuartzComponent} from "../../components/types"
|
||||
import {googleFontHref, joinStyles} from "../../util/theme"
|
||||
import {Features, transform} from "lightningcss"
|
||||
import {transform as transpile} from "esbuild"
|
||||
import {write} from "./helpers"
|
||||
import DepGraph from "../../depgraph"
|
||||
|
||||
type ComponentResources = {
|
||||
@ -37,7 +37,7 @@ function getComponentResources(ctx: BuildCtx): ComponentResources {
|
||||
}
|
||||
|
||||
for (const component of allComponents) {
|
||||
const { css, beforeDOMLoaded, afterDOMLoaded } = component
|
||||
const {css, beforeDOMLoaded, afterDOMLoaded} = component
|
||||
if (css) {
|
||||
componentResources.css.add(css)
|
||||
}
|
||||
@ -58,7 +58,9 @@ function getComponentResources(ctx: BuildCtx): ComponentResources {
|
||||
|
||||
async function joinScripts(scripts: string[]): Promise<string> {
|
||||
// wrap with iife to prevent scope collision
|
||||
const script = scripts.map((script) => `(function () {${script}})();`).join("\n")
|
||||
const script = scripts
|
||||
.map((script) => `(function () {${script}})();`)
|
||||
.join("\n")
|
||||
|
||||
// minify with esbuild
|
||||
const res = await transpile(script, {
|
||||
@ -68,7 +70,10 @@ async function joinScripts(scripts: string[]): Promise<string> {
|
||||
return res.code
|
||||
}
|
||||
|
||||
function addGlobalPageResources(ctx: BuildCtx, componentResources: ComponentResources) {
|
||||
function addGlobalPageResources(
|
||||
ctx: BuildCtx,
|
||||
componentResources: ComponentResources,
|
||||
) {
|
||||
const cfg = ctx.cfg.configuration
|
||||
|
||||
// popovers
|
||||
@ -185,11 +190,15 @@ export const ComponentResources: QuartzEmitterPlugin = () => {
|
||||
let googleFontsStyleSheet = ""
|
||||
if (cfg.theme.fontOrigin === "local") {
|
||||
// let the user do it themselves in css
|
||||
} else if (cfg.theme.fontOrigin === "googleFonts" && !cfg.theme.cdnCaching) {
|
||||
} else if (
|
||||
cfg.theme.fontOrigin === "googleFonts" &&
|
||||
!cfg.theme.cdnCaching
|
||||
) {
|
||||
// when cdnCaching is true, we link to google fonts in Head.tsx
|
||||
let match
|
||||
|
||||
const fontSourceRegex = /url\((https:\/\/fonts.gstatic.com\/s\/[^)]+\.(woff2|ttf))\)/g
|
||||
const fontSourceRegex =
|
||||
/url\((https:\/\/fonts.gstatic.com\/s\/[^)]+\.(woff2|ttf))\)/g
|
||||
|
||||
googleFontsStyleSheet = await (
|
||||
await fetch(googleFontHref(ctx.cfg.configuration.theme))
|
||||
|
||||
@ -1,12 +1,18 @@
|
||||
import { Root } from "hast"
|
||||
import { GlobalConfiguration } from "../../cfg"
|
||||
import { getDate } from "../../components/Date"
|
||||
import { escapeHTML } from "../../util/escape"
|
||||
import { FilePath, FullSlug, SimpleSlug, joinSegments, simplifySlug } from "../../util/path"
|
||||
import { QuartzEmitterPlugin } from "../types"
|
||||
import { toHtml } from "hast-util-to-html"
|
||||
import { write } from "./helpers"
|
||||
import { i18n } from "../../i18n"
|
||||
import {Root} from "hast"
|
||||
import {GlobalConfiguration} from "../../cfg"
|
||||
import {getDate} from "../../components/Date"
|
||||
import {escapeHTML} from "../../util/escape"
|
||||
import {
|
||||
FilePath,
|
||||
FullSlug,
|
||||
SimpleSlug,
|
||||
joinSegments,
|
||||
simplifySlug,
|
||||
} from "../../util/path"
|
||||
import {QuartzEmitterPlugin} from "../types"
|
||||
import {toHtml} from "hast-util-to-html"
|
||||
import {write} from "./helpers"
|
||||
import {i18n} from "../../i18n"
|
||||
import DepGraph from "../../depgraph"
|
||||
|
||||
export type ContentIndex = Map<FullSlug, ContentDetails>
|
||||
@ -38,7 +44,10 @@ const defaultOptions: Options = {
|
||||
|
||||
function generateSiteMap(cfg: GlobalConfiguration, idx: ContentIndex): string {
|
||||
const base = cfg.baseUrl ?? ""
|
||||
const createURLEntry = (slug: SimpleSlug, content: ContentDetails): string => `<url>
|
||||
const createURLEntry = (
|
||||
slug: SimpleSlug,
|
||||
content: ContentDetails,
|
||||
): string => `<url>
|
||||
<loc>https://${joinSegments(base, encodeURI(slug))}</loc>
|
||||
${content.date && `<lastmod>${content.date.toISOString()}</lastmod>`}
|
||||
</url>`
|
||||
@ -48,10 +57,17 @@ function generateSiteMap(cfg: GlobalConfiguration, idx: ContentIndex): string {
|
||||
return `<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml">${urls}</urlset>`
|
||||
}
|
||||
|
||||
function generateRSSFeed(cfg: GlobalConfiguration, idx: ContentIndex, limit?: number): string {
|
||||
function generateRSSFeed(
|
||||
cfg: GlobalConfiguration,
|
||||
idx: ContentIndex,
|
||||
limit?: number,
|
||||
): string {
|
||||
const base = cfg.baseUrl ?? ""
|
||||
|
||||
const createURLEntry = (slug: SimpleSlug, content: ContentDetails): string => `<item>
|
||||
const createURLEntry = (
|
||||
slug: SimpleSlug,
|
||||
content: ContentDetails,
|
||||
): string => `<item>
|
||||
<title>${escapeHTML(content.title)}</title>
|
||||
<link>https://${joinSegments(base, encodeURI(slug))}</link>
|
||||
<guid>https://${joinSegments(base, encodeURI(slug))}</guid>
|
||||
@ -80,7 +96,7 @@ function generateRSSFeed(cfg: GlobalConfiguration, idx: ContentIndex, limit?: nu
|
||||
<channel>
|
||||
<title>${escapeHTML(cfg.pageTitle)}</title>
|
||||
<link>https://${base}</link>
|
||||
<description>${!!limit ? i18n(cfg.locale).pages.rss.lastFewNotes({ count: limit }) : i18n(cfg.locale).pages.rss.recentNotes} on ${escapeHTML(
|
||||
<description>${!!limit ? i18n(cfg.locale).pages.rss.lastFewNotes({count: limit}) : i18n(cfg.locale).pages.rss.recentNotes} on ${escapeHTML(
|
||||
cfg.pageTitle,
|
||||
)}</description>
|
||||
<generator>Quartz -- quartz.jzhao.xyz</generator>
|
||||
@ -90,7 +106,7 @@ function generateRSSFeed(cfg: GlobalConfiguration, idx: ContentIndex, limit?: nu
|
||||
}
|
||||
|
||||
export const ContentIndex: QuartzEmitterPlugin<Partial<Options>> = (opts) => {
|
||||
opts = { ...defaultOptions, ...opts }
|
||||
opts = {...defaultOptions, ...opts}
|
||||
return {
|
||||
name: "ContentIndex",
|
||||
async getDependencyGraph(ctx, content, _resources) {
|
||||
@ -104,10 +120,16 @@ export const ContentIndex: QuartzEmitterPlugin<Partial<Options>> = (opts) => {
|
||||
joinSegments(ctx.argv.output, "static/contentIndex.json") as FilePath,
|
||||
)
|
||||
if (opts?.enableSiteMap) {
|
||||
graph.addEdge(sourcePath, joinSegments(ctx.argv.output, "sitemap.xml") as FilePath)
|
||||
graph.addEdge(
|
||||
sourcePath,
|
||||
joinSegments(ctx.argv.output, "sitemap.xml") as FilePath,
|
||||
)
|
||||
}
|
||||
if (opts?.enableRSS) {
|
||||
graph.addEdge(sourcePath, joinSegments(ctx.argv.output, "index.xml") as FilePath)
|
||||
graph.addEdge(
|
||||
sourcePath,
|
||||
joinSegments(ctx.argv.output, "index.xml") as FilePath,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@ -120,14 +142,17 @@ export const ContentIndex: QuartzEmitterPlugin<Partial<Options>> = (opts) => {
|
||||
for (const [tree, file] of content) {
|
||||
const slug = file.data.slug!
|
||||
const date = getDate(ctx.cfg.configuration, file.data) ?? new Date()
|
||||
if (opts?.includeEmptyFiles || (file.data.text && file.data.text !== "")) {
|
||||
if (
|
||||
opts?.includeEmptyFiles ||
|
||||
(file.data.text && file.data.text !== "")
|
||||
) {
|
||||
linkIndex.set(slug, {
|
||||
title: file.data.frontmatter?.title!,
|
||||
links: file.data.links ?? [],
|
||||
tags: file.data.frontmatter?.tags ?? [],
|
||||
content: file.data.text ?? "",
|
||||
richContent: opts?.rssFullHtml
|
||||
? escapeHTML(toHtml(tree as Root, { allowDangerousHtml: true }))
|
||||
? escapeHTML(toHtml(tree as Root, {allowDangerousHtml: true}))
|
||||
: undefined,
|
||||
date: date,
|
||||
description: file.data.description ?? "",
|
||||
|
||||
@ -1,19 +1,27 @@
|
||||
import path from "path"
|
||||
import { visit } from "unist-util-visit"
|
||||
import { Root } from "hast"
|
||||
import { VFile } from "vfile"
|
||||
import { QuartzEmitterPlugin } from "../types"
|
||||
import { QuartzComponentProps } from "../../components/types"
|
||||
import {visit} from "unist-util-visit"
|
||||
import {Root} from "hast"
|
||||
import {VFile} from "vfile"
|
||||
import {QuartzEmitterPlugin} from "../types"
|
||||
import {QuartzComponentProps} from "../../components/types"
|
||||
import HeaderConstructor from "../../components/Header"
|
||||
import BodyConstructor from "../../components/Body"
|
||||
import { pageResources, renderPage } from "../../components/renderPage"
|
||||
import { FullPageLayout } from "../../cfg"
|
||||
import { Argv } from "../../util/ctx"
|
||||
import { FilePath, isRelativeURL, joinSegments, pathToRoot } from "../../util/path"
|
||||
import { defaultContentPageLayout, sharedPageComponents } from "../../../quartz.layout"
|
||||
import { Content } from "../../components"
|
||||
import {pageResources, renderPage} from "../../components/renderPage"
|
||||
import {FullPageLayout} from "../../cfg"
|
||||
import {Argv} from "../../util/ctx"
|
||||
import {
|
||||
FilePath,
|
||||
isRelativeURL,
|
||||
joinSegments,
|
||||
pathToRoot,
|
||||
} from "../../util/path"
|
||||
import {
|
||||
defaultContentPageLayout,
|
||||
sharedPageComponents,
|
||||
} from "../../../quartz.layout"
|
||||
import {Content} from "../../components"
|
||||
import chalk from "chalk"
|
||||
import { write } from "./helpers"
|
||||
import {write} from "./helpers"
|
||||
import DepGraph from "../../depgraph"
|
||||
|
||||
// get all the dependencies for the markdown file
|
||||
@ -25,7 +33,9 @@ const parseDependencies = (argv: Argv, hast: Root, file: VFile): string[] => {
|
||||
let ref: string | null = null
|
||||
|
||||
if (
|
||||
["script", "img", "audio", "video", "source", "iframe"].includes(elem.tagName) &&
|
||||
["script", "img", "audio", "video", "source", "iframe"].includes(
|
||||
elem.tagName,
|
||||
) &&
|
||||
elem?.properties?.src
|
||||
) {
|
||||
ref = elem.properties.src.toString()
|
||||
@ -40,7 +50,9 @@ const parseDependencies = (argv: Argv, hast: Root, file: VFile): string[] => {
|
||||
return
|
||||
}
|
||||
|
||||
let fp = path.join(file.data.filePath!, path.relative(argv.directory, ref)).replace(/\\/g, "/")
|
||||
let fp = path
|
||||
.join(file.data.filePath!, path.relative(argv.directory, ref))
|
||||
.replace(/\\/g, "/")
|
||||
// markdown files have the .md extension stripped in hrefs, add it back here
|
||||
if (!fp.split("/").pop()?.includes(".")) {
|
||||
fp += ".md"
|
||||
@ -51,7 +63,9 @@ const parseDependencies = (argv: Argv, hast: Root, file: VFile): string[] => {
|
||||
return dependencies
|
||||
}
|
||||
|
||||
export const ContentPage: QuartzEmitterPlugin<Partial<FullPageLayout>> = (userOpts) => {
|
||||
export const ContentPage: QuartzEmitterPlugin<Partial<FullPageLayout>> = (
|
||||
userOpts,
|
||||
) => {
|
||||
const opts: FullPageLayout = {
|
||||
...sharedPageComponents,
|
||||
...defaultContentPageLayout,
|
||||
@ -59,7 +73,16 @@ export const ContentPage: QuartzEmitterPlugin<Partial<FullPageLayout>> = (userOp
|
||||
...userOpts,
|
||||
}
|
||||
|
||||
const { head: Head, header, beforeBody, pageBody, afterBody, left, right, footer: Footer } = opts
|
||||
const {
|
||||
head: Head,
|
||||
header,
|
||||
beforeBody,
|
||||
pageBody,
|
||||
afterBody,
|
||||
left,
|
||||
right,
|
||||
footer: Footer,
|
||||
} = opts
|
||||
const Header = HeaderConstructor()
|
||||
const Body = BodyConstructor()
|
||||
|
||||
@ -85,7 +108,10 @@ export const ContentPage: QuartzEmitterPlugin<Partial<FullPageLayout>> = (userOp
|
||||
for (const [tree, file] of content) {
|
||||
const sourcePath = file.data.filePath!
|
||||
const slug = file.data.slug!
|
||||
graph.addEdge(sourcePath, joinSegments(ctx.argv.output, slug + ".html") as FilePath)
|
||||
graph.addEdge(
|
||||
sourcePath,
|
||||
joinSegments(ctx.argv.output, slug + ".html") as FilePath,
|
||||
)
|
||||
|
||||
parseDependencies(ctx.argv, tree as Root, file).forEach((dep) => {
|
||||
graph.addEdge(dep as FilePath, sourcePath)
|
||||
@ -117,7 +143,13 @@ export const ContentPage: QuartzEmitterPlugin<Partial<FullPageLayout>> = (userOp
|
||||
allFiles,
|
||||
}
|
||||
|
||||
const content = renderPage(cfg, slug, componentData, opts, externalResources)
|
||||
const content = renderPage(
|
||||
cfg,
|
||||
slug,
|
||||
componentData,
|
||||
opts,
|
||||
externalResources,
|
||||
)
|
||||
const fp = await write({
|
||||
ctx,
|
||||
content,
|
||||
|
||||
@ -1,10 +1,14 @@
|
||||
import { QuartzEmitterPlugin } from "../types"
|
||||
import { QuartzComponentProps } from "../../components/types"
|
||||
import {QuartzEmitterPlugin} from "../types"
|
||||
import {QuartzComponentProps} from "../../components/types"
|
||||
import HeaderConstructor from "../../components/Header"
|
||||
import BodyConstructor from "../../components/Body"
|
||||
import { pageResources, renderPage } from "../../components/renderPage"
|
||||
import { ProcessedContent, QuartzPluginData, defaultProcessedContent } from "../vfile"
|
||||
import { FullPageLayout } from "../../cfg"
|
||||
import {pageResources, renderPage} from "../../components/renderPage"
|
||||
import {
|
||||
ProcessedContent,
|
||||
QuartzPluginData,
|
||||
defaultProcessedContent,
|
||||
} from "../vfile"
|
||||
import {FullPageLayout} from "../../cfg"
|
||||
import path from "path"
|
||||
import {
|
||||
FilePath,
|
||||
@ -15,25 +19,39 @@ import {
|
||||
pathToRoot,
|
||||
simplifySlug,
|
||||
} from "../../util/path"
|
||||
import { defaultListPageLayout, sharedPageComponents } from "../../../quartz.layout"
|
||||
import { FolderContent } from "../../components"
|
||||
import { write } from "./helpers"
|
||||
import { i18n } from "../../i18n"
|
||||
import {
|
||||
defaultListPageLayout,
|
||||
sharedPageComponents,
|
||||
} from "../../../quartz.layout"
|
||||
import {FolderContent} from "../../components"
|
||||
import {write} from "./helpers"
|
||||
import {i18n} from "../../i18n"
|
||||
import DepGraph from "../../depgraph"
|
||||
|
||||
interface FolderPageOptions extends FullPageLayout {
|
||||
sort?: (f1: QuartzPluginData, f2: QuartzPluginData) => number
|
||||
}
|
||||
|
||||
export const FolderPage: QuartzEmitterPlugin<Partial<FolderPageOptions>> = (userOpts) => {
|
||||
export const FolderPage: QuartzEmitterPlugin<Partial<FolderPageOptions>> = (
|
||||
userOpts,
|
||||
) => {
|
||||
const opts: FullPageLayout = {
|
||||
...sharedPageComponents,
|
||||
...defaultListPageLayout,
|
||||
pageBody: FolderContent({ sort: userOpts?.sort }),
|
||||
pageBody: FolderContent({sort: userOpts?.sort}),
|
||||
...userOpts,
|
||||
}
|
||||
|
||||
const { head: Head, header, beforeBody, pageBody, afterBody, left, right, footer: Footer } = opts
|
||||
const {
|
||||
head: Head,
|
||||
header,
|
||||
beforeBody,
|
||||
pageBody,
|
||||
afterBody,
|
||||
left,
|
||||
right,
|
||||
footer: Footer,
|
||||
} = opts
|
||||
const Header = HeaderConstructor()
|
||||
const Body = BodyConstructor()
|
||||
|
||||
@ -63,7 +81,10 @@ export const FolderPage: QuartzEmitterPlugin<Partial<FolderPageOptions>> = (user
|
||||
const slug = vfile.data.slug
|
||||
const folderName = path.dirname(slug ?? "") as SimpleSlug
|
||||
if (slug && folderName !== "." && folderName !== "tags") {
|
||||
graph.addEdge(vfile.data.filePath!, joinSegments(folderName, "index.html") as FilePath)
|
||||
graph.addEdge(
|
||||
vfile.data.filePath!,
|
||||
joinSegments(folderName, "index.html") as FilePath,
|
||||
)
|
||||
}
|
||||
})
|
||||
|
||||
@ -85,18 +106,19 @@ export const FolderPage: QuartzEmitterPlugin<Partial<FolderPageOptions>> = (user
|
||||
}),
|
||||
)
|
||||
|
||||
const folderDescriptions: Record<string, ProcessedContent> = Object.fromEntries(
|
||||
[...folders].map((folder) => [
|
||||
folder,
|
||||
defaultProcessedContent({
|
||||
slug: joinSegments(folder, "index") as FullSlug,
|
||||
frontmatter: {
|
||||
title: `${i18n(cfg.locale).pages.folderContent.folder}: ${folder}`,
|
||||
tags: [],
|
||||
},
|
||||
}),
|
||||
]),
|
||||
)
|
||||
const folderDescriptions: Record<string, ProcessedContent> =
|
||||
Object.fromEntries(
|
||||
[...folders].map((folder) => [
|
||||
folder,
|
||||
defaultProcessedContent({
|
||||
slug: joinSegments(folder, "index") as FullSlug,
|
||||
frontmatter: {
|
||||
title: `${i18n(cfg.locale).pages.folderContent.folder}: ${folder}`,
|
||||
tags: [],
|
||||
},
|
||||
}),
|
||||
]),
|
||||
)
|
||||
|
||||
for (const [tree, file] of content) {
|
||||
const slug = stripSlashes(simplifySlug(file.data.slug!)) as SimpleSlug
|
||||
@ -119,7 +141,13 @@ export const FolderPage: QuartzEmitterPlugin<Partial<FolderPageOptions>> = (user
|
||||
allFiles,
|
||||
}
|
||||
|
||||
const content = renderPage(cfg, slug, componentData, opts, externalResources)
|
||||
const content = renderPage(
|
||||
cfg,
|
||||
slug,
|
||||
componentData,
|
||||
opts,
|
||||
externalResources,
|
||||
)
|
||||
const fp = await write({
|
||||
ctx,
|
||||
content,
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import path from "path"
|
||||
import fs from "fs"
|
||||
import { BuildCtx } from "../../util/ctx"
|
||||
import { FilePath, FullSlug, joinSegments } from "../../util/path"
|
||||
import {BuildCtx} from "../../util/ctx"
|
||||
import {FilePath, FullSlug, joinSegments} from "../../util/path"
|
||||
|
||||
type WriteOptions = {
|
||||
ctx: BuildCtx
|
||||
@ -10,10 +10,15 @@ type WriteOptions = {
|
||||
content: string | Buffer
|
||||
}
|
||||
|
||||
export const write = async ({ ctx, slug, ext, content }: WriteOptions): Promise<FilePath> => {
|
||||
export const write = async ({
|
||||
ctx,
|
||||
slug,
|
||||
ext,
|
||||
content,
|
||||
}: WriteOptions): Promise<FilePath> => {
|
||||
const pathToPage = joinSegments(ctx.argv.output, slug + ext) as FilePath
|
||||
const dir = path.dirname(pathToPage)
|
||||
await fs.promises.mkdir(dir, { recursive: true })
|
||||
await fs.promises.mkdir(dir, {recursive: true})
|
||||
await fs.promises.writeFile(pathToPage, content)
|
||||
return pathToPage
|
||||
}
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
export { ContentPage } from "./contentPage"
|
||||
export { TagPage } from "./tagPage"
|
||||
export { FolderPage } from "./folderPage"
|
||||
export { ContentIndex } from "./contentIndex"
|
||||
export { AliasRedirects } from "./aliases"
|
||||
export { Assets } from "./assets"
|
||||
export { Static } from "./static"
|
||||
export { ComponentResources } from "./componentResources"
|
||||
export { NotFoundPage } from "./404"
|
||||
export { CNAME } from "./cname"
|
||||
export {ContentPage} from "./contentPage"
|
||||
export {TagPage} from "./tagPage"
|
||||
export {FolderPage} from "./folderPage"
|
||||
export {ContentIndex} from "./contentIndex"
|
||||
export {AliasRedirects} from "./aliases"
|
||||
export {Assets} from "./assets"
|
||||
export {Static} from "./static"
|
||||
export {ComponentResources} from "./componentResources"
|
||||
export {NotFoundPage} from "./404"
|
||||
export {CNAME} from "./cname"
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import { FilePath, QUARTZ, joinSegments } from "../../util/path"
|
||||
import { QuartzEmitterPlugin } from "../types"
|
||||
import {FilePath, QUARTZ, joinSegments} from "../../util/path"
|
||||
import {QuartzEmitterPlugin} from "../types"
|
||||
import fs from "fs"
|
||||
import { glob } from "../../util/glob"
|
||||
import {glob} from "../../util/glob"
|
||||
import DepGraph from "../../depgraph"
|
||||
|
||||
export const Static: QuartzEmitterPlugin = () => ({
|
||||
@ -9,7 +9,7 @@ export const Static: QuartzEmitterPlugin = () => ({
|
||||
getQuartzComponents() {
|
||||
return []
|
||||
},
|
||||
async getDependencyGraph({ argv, cfg }, _content, _resources) {
|
||||
async getDependencyGraph({argv, cfg}, _content, _resources) {
|
||||
const graph = new DepGraph<FilePath>()
|
||||
|
||||
const staticPath = joinSegments(QUARTZ, "static")
|
||||
@ -23,13 +23,15 @@ export const Static: QuartzEmitterPlugin = () => ({
|
||||
|
||||
return graph
|
||||
},
|
||||
async emit({ argv, cfg }, _content, _resources): Promise<FilePath[]> {
|
||||
async emit({argv, cfg}, _content, _resources): Promise<FilePath[]> {
|
||||
const staticPath = joinSegments(QUARTZ, "static")
|
||||
const fps = await glob("**", staticPath, cfg.configuration.ignorePatterns)
|
||||
await fs.promises.cp(staticPath, joinSegments(argv.output, "static"), {
|
||||
recursive: true,
|
||||
dereference: true,
|
||||
})
|
||||
return fps.map((fp) => joinSegments(argv.output, "static", fp)) as FilePath[]
|
||||
return fps.map((fp) =>
|
||||
joinSegments(argv.output, "static", fp),
|
||||
) as FilePath[]
|
||||
},
|
||||
})
|
||||
|
||||
@ -1,10 +1,14 @@
|
||||
import { QuartzEmitterPlugin } from "../types"
|
||||
import { QuartzComponentProps } from "../../components/types"
|
||||
import {QuartzEmitterPlugin} from "../types"
|
||||
import {QuartzComponentProps} from "../../components/types"
|
||||
import HeaderConstructor from "../../components/Header"
|
||||
import BodyConstructor from "../../components/Body"
|
||||
import { pageResources, renderPage } from "../../components/renderPage"
|
||||
import { ProcessedContent, QuartzPluginData, defaultProcessedContent } from "../vfile"
|
||||
import { FullPageLayout } from "../../cfg"
|
||||
import {pageResources, renderPage} from "../../components/renderPage"
|
||||
import {
|
||||
ProcessedContent,
|
||||
QuartzPluginData,
|
||||
defaultProcessedContent,
|
||||
} from "../vfile"
|
||||
import {FullPageLayout} from "../../cfg"
|
||||
import {
|
||||
FilePath,
|
||||
FullSlug,
|
||||
@ -12,25 +16,39 @@ import {
|
||||
joinSegments,
|
||||
pathToRoot,
|
||||
} from "../../util/path"
|
||||
import { defaultListPageLayout, sharedPageComponents } from "../../../quartz.layout"
|
||||
import { TagContent } from "../../components"
|
||||
import { write } from "./helpers"
|
||||
import { i18n } from "../../i18n"
|
||||
import {
|
||||
defaultListPageLayout,
|
||||
sharedPageComponents,
|
||||
} from "../../../quartz.layout"
|
||||
import {TagContent} from "../../components"
|
||||
import {write} from "./helpers"
|
||||
import {i18n} from "../../i18n"
|
||||
import DepGraph from "../../depgraph"
|
||||
|
||||
interface TagPageOptions extends FullPageLayout {
|
||||
sort?: (f1: QuartzPluginData, f2: QuartzPluginData) => number
|
||||
}
|
||||
|
||||
export const TagPage: QuartzEmitterPlugin<Partial<TagPageOptions>> = (userOpts) => {
|
||||
export const TagPage: QuartzEmitterPlugin<Partial<TagPageOptions>> = (
|
||||
userOpts,
|
||||
) => {
|
||||
const opts: FullPageLayout = {
|
||||
...sharedPageComponents,
|
||||
...defaultListPageLayout,
|
||||
pageBody: TagContent({ sort: userOpts?.sort }),
|
||||
pageBody: TagContent({sort: userOpts?.sort}),
|
||||
...userOpts,
|
||||
}
|
||||
|
||||
const { head: Head, header, beforeBody, pageBody, afterBody, left, right, footer: Footer } = opts
|
||||
const {
|
||||
head: Head,
|
||||
header,
|
||||
beforeBody,
|
||||
pageBody,
|
||||
afterBody,
|
||||
left,
|
||||
right,
|
||||
footer: Footer,
|
||||
} = opts
|
||||
const Header = HeaderConstructor()
|
||||
const Body = BodyConstructor()
|
||||
|
||||
@ -55,7 +73,9 @@ export const TagPage: QuartzEmitterPlugin<Partial<TagPageOptions>> = (userOpts)
|
||||
|
||||
for (const [_tree, file] of content) {
|
||||
const sourcePath = file.data.filePath!
|
||||
const tags = (file.data.frontmatter?.tags ?? []).flatMap(getAllSegmentPrefixes)
|
||||
const tags = (file.data.frontmatter?.tags ?? []).flatMap(
|
||||
getAllSegmentPrefixes,
|
||||
)
|
||||
// if the file has at least one tag, it is used in the tag index page
|
||||
if (tags.length > 0) {
|
||||
tags.push("index")
|
||||
@ -77,27 +97,30 @@ export const TagPage: QuartzEmitterPlugin<Partial<TagPageOptions>> = (userOpts)
|
||||
const cfg = ctx.cfg.configuration
|
||||
|
||||
const tags: Set<string> = new Set(
|
||||
allFiles.flatMap((data) => data.frontmatter?.tags ?? []).flatMap(getAllSegmentPrefixes),
|
||||
allFiles
|
||||
.flatMap((data) => data.frontmatter?.tags ?? [])
|
||||
.flatMap(getAllSegmentPrefixes),
|
||||
)
|
||||
|
||||
// add base tag
|
||||
tags.add("index")
|
||||
|
||||
const tagDescriptions: Record<string, ProcessedContent> = Object.fromEntries(
|
||||
[...tags].map((tag) => {
|
||||
const title =
|
||||
tag === "index"
|
||||
? i18n(cfg.locale).pages.tagContent.tagIndex
|
||||
: `${i18n(cfg.locale).pages.tagContent.tag}: ${tag}`
|
||||
return [
|
||||
tag,
|
||||
defaultProcessedContent({
|
||||
slug: joinSegments("tags", tag) as FullSlug,
|
||||
frontmatter: { title, tags: [] },
|
||||
}),
|
||||
]
|
||||
}),
|
||||
)
|
||||
const tagDescriptions: Record<string, ProcessedContent> =
|
||||
Object.fromEntries(
|
||||
[...tags].map((tag) => {
|
||||
const title =
|
||||
tag === "index"
|
||||
? i18n(cfg.locale).pages.tagContent.tagIndex
|
||||
: `${i18n(cfg.locale).pages.tagContent.tag}: ${tag}`
|
||||
return [
|
||||
tag,
|
||||
defaultProcessedContent({
|
||||
slug: joinSegments("tags", tag) as FullSlug,
|
||||
frontmatter: {title, tags: []},
|
||||
}),
|
||||
]
|
||||
}),
|
||||
)
|
||||
|
||||
for (const [tree, file] of content) {
|
||||
const slug = file.data.slug!
|
||||
@ -123,7 +146,13 @@ export const TagPage: QuartzEmitterPlugin<Partial<TagPageOptions>> = (userOpts)
|
||||
allFiles,
|
||||
}
|
||||
|
||||
const content = renderPage(cfg, slug, componentData, opts, externalResources)
|
||||
const content = renderPage(
|
||||
cfg,
|
||||
slug,
|
||||
componentData,
|
||||
opts,
|
||||
externalResources,
|
||||
)
|
||||
const fp = await write({
|
||||
ctx,
|
||||
content,
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { QuartzFilterPlugin } from "../types"
|
||||
import {QuartzFilterPlugin} from "../types"
|
||||
|
||||
export const RemoveDrafts: QuartzFilterPlugin<{}> = () => ({
|
||||
name: "RemoveDrafts",
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { QuartzFilterPlugin } from "../types"
|
||||
import {QuartzFilterPlugin} from "../types"
|
||||
|
||||
export const ExplicitPublish: QuartzFilterPlugin = () => ({
|
||||
name: "ExplicitPublish",
|
||||
|
||||
@ -1,2 +1,2 @@
|
||||
export { RemoveDrafts } from "./draft"
|
||||
export { ExplicitPublish } from "./explicit"
|
||||
export {RemoveDrafts} from "./draft"
|
||||
export {ExplicitPublish} from "./explicit"
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import { StaticResources } from "../util/resources"
|
||||
import { FilePath, FullSlug } from "../util/path"
|
||||
import { BuildCtx } from "../util/ctx"
|
||||
import {StaticResources} from "../util/resources"
|
||||
import {FilePath, FullSlug} from "../util/path"
|
||||
import {BuildCtx} from "../util/ctx"
|
||||
|
||||
export function getStaticResourcesFromPlugins(ctx: BuildCtx) {
|
||||
const staticResources: StaticResources = {
|
||||
@ -9,7 +9,9 @@ export function getStaticResourcesFromPlugins(ctx: BuildCtx) {
|
||||
}
|
||||
|
||||
for (const transformer of ctx.cfg.plugins.transformers) {
|
||||
const res = transformer.externalResources ? transformer.externalResources(ctx) : {}
|
||||
const res = transformer.externalResources
|
||||
? transformer.externalResources(ctx)
|
||||
: {}
|
||||
if (res?.js) {
|
||||
staticResources.js.push(...res.js)
|
||||
}
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import rehypeCitation from "rehype-citation"
|
||||
import { PluggableList } from "unified"
|
||||
import { visit } from "unist-util-visit"
|
||||
import { QuartzTransformerPlugin } from "../types"
|
||||
import {PluggableList} from "unified"
|
||||
import {visit} from "unist-util-visit"
|
||||
import {QuartzTransformerPlugin} from "../types"
|
||||
|
||||
export interface Options {
|
||||
bibliographyFile: string
|
||||
@ -17,8 +17,10 @@ const defaultOptions: Options = {
|
||||
csl: "apa",
|
||||
}
|
||||
|
||||
export const Citations: QuartzTransformerPlugin<Partial<Options>> = (userOpts) => {
|
||||
const opts = { ...defaultOptions, ...userOpts }
|
||||
export const Citations: QuartzTransformerPlugin<Partial<Options>> = (
|
||||
userOpts,
|
||||
) => {
|
||||
const opts = {...defaultOptions, ...userOpts}
|
||||
return {
|
||||
name: "Citations",
|
||||
htmlPlugins() {
|
||||
@ -39,7 +41,10 @@ export const Citations: QuartzTransformerPlugin<Partial<Options>> = (userOpts) =
|
||||
plugins.push(() => {
|
||||
return (tree, _file) => {
|
||||
visit(tree, "element", (node, _index, _parent) => {
|
||||
if (node.tagName === "a" && node.properties?.href?.startsWith("#bib")) {
|
||||
if (
|
||||
node.tagName === "a" &&
|
||||
node.properties?.href?.startsWith("#bib")
|
||||
) {
|
||||
node.properties["data-no-popover"] = true
|
||||
}
|
||||
})
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import { Root as HTMLRoot } from "hast"
|
||||
import { toString } from "hast-util-to-string"
|
||||
import { QuartzTransformerPlugin } from "../types"
|
||||
import { escapeHTML } from "../../util/escape"
|
||||
import {Root as HTMLRoot} from "hast"
|
||||
import {toString} from "hast-util-to-string"
|
||||
import {QuartzTransformerPlugin} from "../types"
|
||||
import {escapeHTML} from "../../util/escape"
|
||||
|
||||
export interface Options {
|
||||
descriptionLength: number
|
||||
@ -18,8 +18,10 @@ const urlRegex = new RegExp(
|
||||
"g",
|
||||
)
|
||||
|
||||
export const Description: QuartzTransformerPlugin<Partial<Options>> = (userOpts) => {
|
||||
const opts = { ...defaultOptions, ...userOpts }
|
||||
export const Description: QuartzTransformerPlugin<Partial<Options>> = (
|
||||
userOpts,
|
||||
) => {
|
||||
const opts = {...defaultOptions, ...userOpts}
|
||||
return {
|
||||
name: "Description",
|
||||
htmlPlugins() {
|
||||
@ -58,7 +60,9 @@ export const Description: QuartzTransformerPlugin<Partial<Options>> = (userOpts)
|
||||
while (currentDescriptionLength < len) {
|
||||
const sentence = sentences[sentenceIdx]
|
||||
if (!sentence) break
|
||||
const currentSentence = sentence.endsWith(".") ? sentence : sentence + "."
|
||||
const currentSentence = sentence.endsWith(".")
|
||||
? sentence
|
||||
: sentence + "."
|
||||
finalDesc.push(currentSentence)
|
||||
currentDescriptionLength += currentSentence.length
|
||||
sentenceIdx++
|
||||
|
||||
@ -1,11 +1,11 @@
|
||||
import matter from "gray-matter"
|
||||
import remarkFrontmatter from "remark-frontmatter"
|
||||
import { QuartzTransformerPlugin } from "../types"
|
||||
import {QuartzTransformerPlugin} from "../types"
|
||||
import yaml from "js-yaml"
|
||||
import toml from "toml"
|
||||
import { slugTag } from "../../util/path"
|
||||
import { QuartzPluginData } from "../vfile"
|
||||
import { i18n } from "../../i18n"
|
||||
import {slugTag} from "../../util/path"
|
||||
import {QuartzPluginData} from "../vfile"
|
||||
import {i18n} from "../../i18n"
|
||||
|
||||
export interface Options {
|
||||
delimiters: string | [string, string]
|
||||
@ -17,7 +17,7 @@ const defaultOptions: Options = {
|
||||
language: "yaml",
|
||||
}
|
||||
|
||||
function coalesceAliases(data: { [key: string]: any }, aliases: string[]) {
|
||||
function coalesceAliases(data: {[key: string]: any}, aliases: string[]) {
|
||||
for (const alias of aliases) {
|
||||
if (data[alias] !== undefined && data[alias] !== null) return data[alias]
|
||||
}
|
||||
@ -36,23 +36,27 @@ function coerceToArray(input: string | string[]): string[] | undefined {
|
||||
|
||||
// remove all non-strings
|
||||
return input
|
||||
.filter((tag: unknown) => typeof tag === "string" || typeof tag === "number")
|
||||
.filter(
|
||||
(tag: unknown) => typeof tag === "string" || typeof tag === "number",
|
||||
)
|
||||
.map((tag: string | number) => tag.toString())
|
||||
}
|
||||
|
||||
export const FrontMatter: QuartzTransformerPlugin<Partial<Options>> = (userOpts) => {
|
||||
const opts = { ...defaultOptions, ...userOpts }
|
||||
export const FrontMatter: QuartzTransformerPlugin<Partial<Options>> = (
|
||||
userOpts,
|
||||
) => {
|
||||
const opts = {...defaultOptions, ...userOpts}
|
||||
return {
|
||||
name: "FrontMatter",
|
||||
markdownPlugins({ cfg }) {
|
||||
markdownPlugins({cfg}) {
|
||||
return [
|
||||
[remarkFrontmatter, ["yaml", "toml"]],
|
||||
() => {
|
||||
return (_, file) => {
|
||||
const { data } = matter(Buffer.from(file.value), {
|
||||
const {data} = matter(Buffer.from(file.value), {
|
||||
...opts,
|
||||
engines: {
|
||||
yaml: (s) => yaml.load(s, { schema: yaml.JSON_SCHEMA }) as object,
|
||||
yaml: (s) => yaml.load(s, {schema: yaml.JSON_SCHEMA}) as object,
|
||||
toml: (s) => toml.parse(s) as object,
|
||||
},
|
||||
})
|
||||
@ -60,15 +64,22 @@ export const FrontMatter: QuartzTransformerPlugin<Partial<Options>> = (userOpts)
|
||||
if (data.title != null && data.title.toString() !== "") {
|
||||
data.title = data.title.toString()
|
||||
} else {
|
||||
data.title = file.stem ?? i18n(cfg.configuration.locale).propertyDefaults.title
|
||||
data.title =
|
||||
file.stem ??
|
||||
i18n(cfg.configuration.locale).propertyDefaults.title
|
||||
}
|
||||
|
||||
const tags = coerceToArray(coalesceAliases(data, ["tags", "tag"]))
|
||||
if (tags) data.tags = [...new Set(tags.map((tag: string) => slugTag(tag)))]
|
||||
if (tags)
|
||||
data.tags = [...new Set(tags.map((tag: string) => slugTag(tag)))]
|
||||
|
||||
const aliases = coerceToArray(coalesceAliases(data, ["aliases", "alias"]))
|
||||
const aliases = coerceToArray(
|
||||
coalesceAliases(data, ["aliases", "alias"]),
|
||||
)
|
||||
if (aliases) data.aliases = aliases
|
||||
const cssclasses = coerceToArray(coalesceAliases(data, ["cssclasses", "cssclass"]))
|
||||
const cssclasses = coerceToArray(
|
||||
coalesceAliases(data, ["cssclasses", "cssclass"]),
|
||||
)
|
||||
if (cssclasses) data.cssclasses = cssclasses
|
||||
|
||||
// fill in frontmatter
|
||||
@ -82,7 +93,7 @@ export const FrontMatter: QuartzTransformerPlugin<Partial<Options>> = (userOpts)
|
||||
|
||||
declare module "vfile" {
|
||||
interface DataMap {
|
||||
frontmatter: { [key: string]: unknown } & {
|
||||
frontmatter: {[key: string]: unknown} & {
|
||||
title: string
|
||||
} & Partial<{
|
||||
tags: string[]
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import remarkGfm from "remark-gfm"
|
||||
import smartypants from "remark-smartypants"
|
||||
import { QuartzTransformerPlugin } from "../types"
|
||||
import {QuartzTransformerPlugin} from "../types"
|
||||
import rehypeSlug from "rehype-slug"
|
||||
import rehypeAutolinkHeadings from "rehype-autolink-headings"
|
||||
|
||||
@ -14,8 +14,10 @@ const defaultOptions: Options = {
|
||||
linkHeadings: true,
|
||||
}
|
||||
|
||||
export const GitHubFlavoredMarkdown: QuartzTransformerPlugin<Partial<Options>> = (userOpts) => {
|
||||
const opts = { ...defaultOptions, ...userOpts }
|
||||
export const GitHubFlavoredMarkdown: QuartzTransformerPlugin<
|
||||
Partial<Options>
|
||||
> = (userOpts) => {
|
||||
const opts = {...defaultOptions, ...userOpts}
|
||||
return {
|
||||
name: "GitHubFlavoredMarkdown",
|
||||
markdownPlugins() {
|
||||
@ -30,20 +32,20 @@ export const GitHubFlavoredMarkdown: QuartzTransformerPlugin<Partial<Options>> =
|
||||
{
|
||||
behavior: "append",
|
||||
properties: {
|
||||
role: "anchor",
|
||||
ariaHidden: true,
|
||||
tabIndex: -1,
|
||||
"role": "anchor",
|
||||
"ariaHidden": true,
|
||||
"tabIndex": -1,
|
||||
"data-no-popover": true,
|
||||
},
|
||||
content: {
|
||||
type: "element",
|
||||
tagName: "svg",
|
||||
properties: {
|
||||
width: 18,
|
||||
height: 18,
|
||||
viewBox: "0 0 24 24",
|
||||
fill: "none",
|
||||
stroke: "currentColor",
|
||||
"width": 18,
|
||||
"height": 18,
|
||||
"viewBox": "0 0 24 24",
|
||||
"fill": "none",
|
||||
"stroke": "currentColor",
|
||||
"stroke-width": "2",
|
||||
"stroke-linecap": "round",
|
||||
"stroke-linejoin": "round",
|
||||
|
||||
@ -1,12 +1,12 @@
|
||||
export { FrontMatter } from "./frontmatter"
|
||||
export { GitHubFlavoredMarkdown } from "./gfm"
|
||||
export { Citations } from "./citations"
|
||||
export { CreatedModifiedDate } from "./lastmod"
|
||||
export { Latex } from "./latex"
|
||||
export { Description } from "./description"
|
||||
export { CrawlLinks } from "./links"
|
||||
export { ObsidianFlavoredMarkdown } from "./ofm"
|
||||
export { OxHugoFlavouredMarkdown } from "./oxhugofm"
|
||||
export { SyntaxHighlighting } from "./syntax"
|
||||
export { TableOfContents } from "./toc"
|
||||
export { HardLineBreaks } from "./linebreaks"
|
||||
export {FrontMatter} from "./frontmatter"
|
||||
export {GitHubFlavoredMarkdown} from "./gfm"
|
||||
export {Citations} from "./citations"
|
||||
export {CreatedModifiedDate} from "./lastmod"
|
||||
export {Latex} from "./latex"
|
||||
export {Description} from "./description"
|
||||
export {CrawlLinks} from "./links"
|
||||
export {ObsidianFlavoredMarkdown} from "./ofm"
|
||||
export {OxHugoFlavouredMarkdown} from "./oxhugofm"
|
||||
export {SyntaxHighlighting} from "./syntax"
|
||||
export {TableOfContents} from "./toc"
|
||||
export {HardLineBreaks} from "./linebreaks"
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import fs from "fs"
|
||||
import path from "path"
|
||||
import { Repository } from "@napi-rs/simple-git"
|
||||
import { QuartzTransformerPlugin } from "../types"
|
||||
import {Repository} from "@napi-rs/simple-git"
|
||||
import {QuartzTransformerPlugin} from "../types"
|
||||
import chalk from "chalk"
|
||||
|
||||
export interface Options {
|
||||
@ -27,8 +27,10 @@ function coerceDate(fp: string, d: any): Date {
|
||||
}
|
||||
|
||||
type MaybeDate = undefined | string | number
|
||||
export const CreatedModifiedDate: QuartzTransformerPlugin<Partial<Options>> = (userOpts) => {
|
||||
const opts = { ...defaultOptions, ...userOpts }
|
||||
export const CreatedModifiedDate: QuartzTransformerPlugin<Partial<Options>> = (
|
||||
userOpts,
|
||||
) => {
|
||||
const opts = {...defaultOptions, ...userOpts}
|
||||
return {
|
||||
name: "CreatedModifiedDate",
|
||||
markdownPlugins() {
|
||||
@ -41,7 +43,9 @@ export const CreatedModifiedDate: QuartzTransformerPlugin<Partial<Options>> = (u
|
||||
let published: MaybeDate = undefined
|
||||
|
||||
const fp = file.data.filePath!
|
||||
const fullFp = path.isAbsolute(fp) ? fp : path.posix.join(file.cwd, fp)
|
||||
const fullFp = path.isAbsolute(fp)
|
||||
? fp
|
||||
: path.posix.join(file.cwd, fp)
|
||||
for (const source of opts.priority) {
|
||||
if (source === "filesystem") {
|
||||
const st = await fs.promises.stat(fullFp)
|
||||
@ -62,7 +66,9 @@ export const CreatedModifiedDate: QuartzTransformerPlugin<Partial<Options>> = (u
|
||||
}
|
||||
|
||||
try {
|
||||
modified ||= await repo.getFileLatestModifiedDateAsync(file.data.filePath!)
|
||||
modified ||= await repo.getFileLatestModifiedDateAsync(
|
||||
file.data.filePath!,
|
||||
)
|
||||
} catch {
|
||||
console.log(
|
||||
chalk.yellow(
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import remarkMath from "remark-math"
|
||||
import rehypeKatex from "rehype-katex"
|
||||
import rehypeMathjax from "rehype-mathjax/svg"
|
||||
import { QuartzTransformerPlugin } from "../types"
|
||||
import {QuartzTransformerPlugin} from "../types"
|
||||
|
||||
interface Options {
|
||||
renderEngine: "katex" | "mathjax"
|
||||
@ -22,9 +22,9 @@ export const Latex: QuartzTransformerPlugin<Partial<Options>> = (opts) => {
|
||||
},
|
||||
htmlPlugins() {
|
||||
if (engine === "katex") {
|
||||
return [[rehypeKatex, { output: "html", macros }]]
|
||||
return [[rehypeKatex, {output: "html", macros}]]
|
||||
} else {
|
||||
return [[rehypeMathjax, { macros }]]
|
||||
return [[rehypeMathjax, {macros}]]
|
||||
}
|
||||
},
|
||||
externalResources() {
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { QuartzTransformerPlugin } from "../types"
|
||||
import {QuartzTransformerPlugin} from "../types"
|
||||
import remarkBreaks from "remark-breaks"
|
||||
|
||||
export const HardLineBreaks: QuartzTransformerPlugin = () => {
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { QuartzTransformerPlugin } from "../types"
|
||||
import {QuartzTransformerPlugin} from "../types"
|
||||
import {
|
||||
FullSlug,
|
||||
RelativeURL,
|
||||
@ -10,9 +10,9 @@ import {
|
||||
transformLink,
|
||||
} from "../../util/path"
|
||||
import path from "path"
|
||||
import { visit } from "unist-util-visit"
|
||||
import {visit} from "unist-util-visit"
|
||||
import isAbsoluteUrl from "is-absolute-url"
|
||||
import { Root } from "hast"
|
||||
import {Root} from "hast"
|
||||
|
||||
interface Options {
|
||||
/** How to resolve Markdown paths */
|
||||
@ -32,8 +32,10 @@ const defaultOptions: Options = {
|
||||
externalLinkIcon: true,
|
||||
}
|
||||
|
||||
export const CrawlLinks: QuartzTransformerPlugin<Partial<Options>> = (userOpts) => {
|
||||
const opts = { ...defaultOptions, ...userOpts }
|
||||
export const CrawlLinks: QuartzTransformerPlugin<Partial<Options>> = (
|
||||
userOpts,
|
||||
) => {
|
||||
const opts = {...defaultOptions, ...userOpts}
|
||||
return {
|
||||
name: "LinkProcessing",
|
||||
htmlPlugins(ctx) {
|
||||
@ -66,8 +68,8 @@ export const CrawlLinks: QuartzTransformerPlugin<Partial<Options>> = (userOpts)
|
||||
tagName: "svg",
|
||||
properties: {
|
||||
"aria-hidden": "true",
|
||||
class: "external-icon",
|
||||
viewBox: "0 0 512 512",
|
||||
"class": "external-icon",
|
||||
"viewBox": "0 0 512 512",
|
||||
},
|
||||
children: [
|
||||
{
|
||||
@ -98,7 +100,9 @@ export const CrawlLinks: QuartzTransformerPlugin<Partial<Options>> = (userOpts)
|
||||
}
|
||||
|
||||
// don't process external links or intra-document anchors
|
||||
const isInternal = !(isAbsoluteUrl(dest) || dest.startsWith("#"))
|
||||
const isInternal = !(
|
||||
isAbsoluteUrl(dest) || dest.startsWith("#")
|
||||
)
|
||||
if (isInternal) {
|
||||
dest = node.properties.href = transformLink(
|
||||
file.data.slug!,
|
||||
@ -108,7 +112,10 @@ export const CrawlLinks: QuartzTransformerPlugin<Partial<Options>> = (userOpts)
|
||||
|
||||
// url.resolve is considered legacy
|
||||
// WHATWG equivalent https://nodejs.dev/en/api/v18/url/#urlresolvefrom-to
|
||||
const url = new URL(dest, "https://base.com/" + stripSlashes(curSlug, true))
|
||||
const url = new URL(
|
||||
dest,
|
||||
"https://base.com/" + stripSlashes(curSlug, true),
|
||||
)
|
||||
const canonicalDest = url.pathname
|
||||
let [destCanonical, _destAnchor] = splitAnchor(canonicalDest)
|
||||
if (destCanonical.endsWith("/")) {
|
||||
@ -116,7 +123,9 @@ export const CrawlLinks: QuartzTransformerPlugin<Partial<Options>> = (userOpts)
|
||||
}
|
||||
|
||||
// need to decodeURIComponent here as WHATWG URL percent-encodes everything
|
||||
const full = decodeURIComponent(stripSlashes(destCanonical, true)) as FullSlug
|
||||
const full = decodeURIComponent(
|
||||
stripSlashes(destCanonical, true),
|
||||
) as FullSlug
|
||||
const simple = simplifySlug(full)
|
||||
outgoing.add(simple)
|
||||
node.properties["data-slug"] = full
|
||||
|
||||
@ -1,22 +1,32 @@
|
||||
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 {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 rehypeRaw from "rehype-raw"
|
||||
import { SKIP, visit } from "unist-util-visit"
|
||||
import {SKIP, visit} from "unist-util-visit"
|
||||
import path from "path"
|
||||
import { splitAnchor } from "../../util/path"
|
||||
import { JSResource } from "../../util/resources"
|
||||
import {splitAnchor} from "../../util/path"
|
||||
import {JSResource} from "../../util/resources"
|
||||
// @ts-ignore
|
||||
import calloutScript from "../../components/scripts/callout.inline.ts"
|
||||
// @ts-ignore
|
||||
import checkboxScript from "../../components/scripts/checkbox.inline.ts"
|
||||
import { FilePath, pathToRoot, slugTag, slugifyFilePath } from "../../util/path"
|
||||
import { toHast } from "mdast-util-to-hast"
|
||||
import { toHtml } from "hast-util-to-html"
|
||||
import { PhrasingContent } from "mdast-util-find-and-replace/lib"
|
||||
import { capitalize } from "../../util/lang"
|
||||
import { PluggableList } from "unified"
|
||||
import {FilePath, pathToRoot, slugTag, slugifyFilePath} from "../../util/path"
|
||||
import {toHast} from "mdast-util-to-hast"
|
||||
import {toHtml} from "hast-util-to-html"
|
||||
import {PhrasingContent} from "mdast-util-find-and-replace/lib"
|
||||
import {capitalize} from "../../util/lang"
|
||||
import {PluggableList} from "unified"
|
||||
|
||||
export interface Options {
|
||||
comments: boolean
|
||||
@ -90,7 +100,8 @@ const arrowMapping: Record<string, string> = {
|
||||
}
|
||||
|
||||
function canonicalizeCallout(calloutName: string): keyof typeof calloutMapping {
|
||||
const normalizedCallout = calloutName.toLowerCase() as keyof typeof calloutMapping
|
||||
const normalizedCallout =
|
||||
calloutName.toLowerCase() as keyof typeof calloutMapping
|
||||
// if callout is not recognized, make it a custom one
|
||||
return calloutMapping[normalizedCallout] ?? calloutName
|
||||
}
|
||||
@ -111,7 +122,9 @@ export const wikilinkRegex = new RegExp(
|
||||
// ^\|([^\n])+\|\n(\|) -> matches the header row
|
||||
// ( ?:?-{3,}:? ?\|)+ -> matches the header row separator
|
||||
// (\|([^\n])+\|\n)+ -> matches the body rows
|
||||
export const tableRegex = new RegExp(/^\|([^\n])+\|\n(\|)( ?:?-{3,}:? ?\|)+\n(\|([^\n])+\|\n?)+/gm)
|
||||
export const tableRegex = new RegExp(
|
||||
/^\|([^\n])+\|\n(\|)( ?:?-{3,}:? ?\|)+\n(\|([^\n])+\|\n?)+/gm,
|
||||
)
|
||||
|
||||
// matches any wikilink, only used for escaping wikilinks inside tables
|
||||
export const tableWikilinkRegex = new RegExp(/(!?\[\[[^\]]*?\]\])/g)
|
||||
@ -129,19 +142,24 @@ const tagRegex = new RegExp(
|
||||
/(?:^| )#((?:[-_\p{L}\p{Emoji}\p{M}\d])+(?:\/[-_\p{L}\p{Emoji}\p{M}\d]+)*)/gu,
|
||||
)
|
||||
const blockReferenceRegex = new RegExp(/\^([-_A-Za-z0-9]+)$/g)
|
||||
const ytLinkRegex = /^.*(youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=|\&v=)([^#\&\?]*).*/
|
||||
const ytLinkRegex =
|
||||
/^.*(youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=|\&v=)([^#\&\?]*).*/
|
||||
const ytPlaylistLinkRegex = /[?&]list=([^#?&]*)/
|
||||
const videoExtensionRegex = new RegExp(/\.(mp4|webm|ogg|avi|mov|flv|wmv|mkv|mpg|mpeg|3gp|m4v)$/)
|
||||
const videoExtensionRegex = new RegExp(
|
||||
/\.(mp4|webm|ogg|avi|mov|flv|wmv|mkv|mpg|mpeg|3gp|m4v)$/,
|
||||
)
|
||||
const wikilinkImageEmbedRegex = new RegExp(
|
||||
/^(?<alt>(?!^\d*x?\d*$).*?)?(\|?\s*?(?<width>\d+)(x(?<height>\d+))?)?$/,
|
||||
)
|
||||
|
||||
export const ObsidianFlavoredMarkdown: QuartzTransformerPlugin<Partial<Options>> = (userOpts) => {
|
||||
const opts = { ...defaultOptions, ...userOpts }
|
||||
export const ObsidianFlavoredMarkdown: QuartzTransformerPlugin<
|
||||
Partial<Options>
|
||||
> = (userOpts) => {
|
||||
const opts = {...defaultOptions, ...userOpts}
|
||||
|
||||
const mdastToHtml = (ast: PhrasingContent | Paragraph) => {
|
||||
const hast = toHast(ast, { allowDangerousHtml: true })!
|
||||
return toHtml(hast, { allowDangerousHtml: true })
|
||||
const hast = toHast(ast, {allowDangerousHtml: true})!
|
||||
return toHtml(hast, {allowDangerousHtml: true})
|
||||
}
|
||||
|
||||
return {
|
||||
@ -194,7 +212,9 @@ export const ObsidianFlavoredMarkdown: QuartzTransformerPlugin<Partial<Options>>
|
||||
|
||||
const [fp, anchor] = splitAnchor(`${rawFp ?? ""}${rawHeader ?? ""}`)
|
||||
const blockRef = Boolean(rawHeader?.match(/^#?\^/)) ? "^" : ""
|
||||
const displayAnchor = anchor ? `#${blockRef}${anchor.trim().replace(/^#+/, "")}` : ""
|
||||
const displayAnchor = anchor
|
||||
? `#${blockRef}${anchor.trim().replace(/^#+/, "")}`
|
||||
: ""
|
||||
const displayAlias = rawAlias ?? rawHeader?.replace("#", "|") ?? ""
|
||||
const embedDisplay = value.startsWith("!") ? "!" : ""
|
||||
|
||||
@ -230,7 +250,17 @@ export const ObsidianFlavoredMarkdown: QuartzTransformerPlugin<Partial<Options>>
|
||||
if (value.startsWith("!")) {
|
||||
const ext: string = path.extname(fp).toLowerCase()
|
||||
const url = slugifyFilePath(fp as FilePath)
|
||||
if ([".png", ".jpg", ".jpeg", ".gif", ".bmp", ".svg", ".webp"].includes(ext)) {
|
||||
if (
|
||||
[
|
||||
".png",
|
||||
".jpg",
|
||||
".jpeg",
|
||||
".gif",
|
||||
".bmp",
|
||||
".svg",
|
||||
".webp",
|
||||
].includes(ext)
|
||||
) {
|
||||
const match = wikilinkImageEmbedRegex.exec(alias ?? "")
|
||||
const alt = match?.groups?.alt ?? ""
|
||||
const width = match?.groups?.width ?? "auto"
|
||||
@ -246,13 +276,23 @@ export const ObsidianFlavoredMarkdown: QuartzTransformerPlugin<Partial<Options>>
|
||||
},
|
||||
},
|
||||
}
|
||||
} else if ([".mp4", ".webm", ".ogv", ".mov", ".mkv"].includes(ext)) {
|
||||
} else if (
|
||||
[".mp4", ".webm", ".ogv", ".mov", ".mkv"].includes(ext)
|
||||
) {
|
||||
return {
|
||||
type: "html",
|
||||
value: `<video src="${url}" controls></video>`,
|
||||
}
|
||||
} else if (
|
||||
[".mp3", ".webm", ".wav", ".m4a", ".ogg", ".3gp", ".flac"].includes(ext)
|
||||
[
|
||||
".mp3",
|
||||
".webm",
|
||||
".wav",
|
||||
".m4a",
|
||||
".ogg",
|
||||
".3gp",
|
||||
".flac",
|
||||
].includes(ext)
|
||||
) {
|
||||
return {
|
||||
type: "html",
|
||||
@ -267,7 +307,7 @@ export const ObsidianFlavoredMarkdown: QuartzTransformerPlugin<Partial<Options>>
|
||||
const block = anchor
|
||||
return {
|
||||
type: "html",
|
||||
data: { hProperties: { transclude: true } },
|
||||
data: {hProperties: {transclude: true}},
|
||||
value: `<blockquote class="transclude" data-url="${url}" data-block="${block}" data-embed-alias="${alias}"><a href="${
|
||||
url + anchor
|
||||
}" class="transclude-inner">Transclude of ${url}${block}</a></blockquote>`,
|
||||
@ -360,18 +400,24 @@ export const ObsidianFlavoredMarkdown: QuartzTransformerPlugin<Partial<Options>>
|
||||
if (typeof replace === "string") {
|
||||
node.value = node.value.replace(regex, replace)
|
||||
} else {
|
||||
node.value = node.value.replace(regex, (substring: string, ...args) => {
|
||||
const replaceValue = replace(substring, ...args)
|
||||
if (typeof replaceValue === "string") {
|
||||
return replaceValue
|
||||
} else if (Array.isArray(replaceValue)) {
|
||||
return replaceValue.map(mdastToHtml).join("")
|
||||
} else if (typeof replaceValue === "object" && replaceValue !== null) {
|
||||
return mdastToHtml(replaceValue)
|
||||
} else {
|
||||
return substring
|
||||
}
|
||||
})
|
||||
node.value = node.value.replace(
|
||||
regex,
|
||||
(substring: string, ...args) => {
|
||||
const replaceValue = replace(substring, ...args)
|
||||
if (typeof replaceValue === "string") {
|
||||
return replaceValue
|
||||
} else if (Array.isArray(replaceValue)) {
|
||||
return replaceValue.map(mdastToHtml).join("")
|
||||
} else if (
|
||||
typeof replaceValue === "object" &&
|
||||
replaceValue !== null
|
||||
) {
|
||||
return mdastToHtml(replaceValue)
|
||||
} else {
|
||||
return substring
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
})
|
||||
@ -384,7 +430,11 @@ export const ObsidianFlavoredMarkdown: QuartzTransformerPlugin<Partial<Options>>
|
||||
plugins.push(() => {
|
||||
return (tree: Root, _file) => {
|
||||
visit(tree, "image", (node, index, parent) => {
|
||||
if (parent && index != undefined && videoExtensionRegex.test(node.url)) {
|
||||
if (
|
||||
parent &&
|
||||
index != undefined &&
|
||||
videoExtensionRegex.test(node.url)
|
||||
) {
|
||||
const newNode: Html = {
|
||||
type: "html",
|
||||
value: `<video controls src="${node.url}"></video>`,
|
||||
@ -408,7 +458,10 @@ export const ObsidianFlavoredMarkdown: QuartzTransformerPlugin<Partial<Options>>
|
||||
|
||||
// find first line and callout content
|
||||
const [firstChild, ...calloutContent] = node.children
|
||||
if (firstChild.type !== "paragraph" || firstChild.children[0]?.type !== "text") {
|
||||
if (
|
||||
firstChild.type !== "paragraph" ||
|
||||
firstChild.children[0]?.type !== "text"
|
||||
) {
|
||||
return
|
||||
}
|
||||
|
||||
@ -419,18 +472,31 @@ export const ObsidianFlavoredMarkdown: QuartzTransformerPlugin<Partial<Options>>
|
||||
|
||||
const match = firstLine.match(calloutRegex)
|
||||
if (match && match.input) {
|
||||
const [calloutDirective, typeString, calloutMetaData, collapseChar] = match
|
||||
const calloutType = canonicalizeCallout(typeString.toLowerCase())
|
||||
const [
|
||||
calloutDirective,
|
||||
typeString,
|
||||
calloutMetaData,
|
||||
collapseChar,
|
||||
] = match
|
||||
const calloutType = canonicalizeCallout(
|
||||
typeString.toLowerCase(),
|
||||
)
|
||||
const collapse = collapseChar === "+" || collapseChar === "-"
|
||||
const defaultState = collapseChar === "-" ? "collapsed" : "expanded"
|
||||
const titleContent = match.input.slice(calloutDirective.length).trim()
|
||||
const useDefaultTitle = titleContent === "" && restOfTitle.length === 0
|
||||
const defaultState =
|
||||
collapseChar === "-" ? "collapsed" : "expanded"
|
||||
const titleContent = match.input
|
||||
.slice(calloutDirective.length)
|
||||
.trim()
|
||||
const useDefaultTitle =
|
||||
titleContent === "" && restOfTitle.length === 0
|
||||
const titleNode: Paragraph = {
|
||||
type: "paragraph",
|
||||
children: [
|
||||
{
|
||||
type: "text",
|
||||
value: useDefaultTitle ? capitalize(typeString) : titleContent + " ",
|
||||
value: useDefaultTitle
|
||||
? capitalize(typeString)
|
||||
: titleContent + " ",
|
||||
},
|
||||
...restOfTitle,
|
||||
],
|
||||
@ -450,7 +516,8 @@ export const ObsidianFlavoredMarkdown: QuartzTransformerPlugin<Partial<Options>>
|
||||
</div>`,
|
||||
}
|
||||
|
||||
const blockquoteContent: (BlockContent | DefinitionContent)[] = [titleHtml]
|
||||
const blockquoteContent: (BlockContent | DefinitionContent)[] =
|
||||
[titleHtml]
|
||||
if (remainingText.length > 0) {
|
||||
blockquoteContent.push({
|
||||
type: "paragraph",
|
||||
@ -478,7 +545,7 @@ export const ObsidianFlavoredMarkdown: QuartzTransformerPlugin<Partial<Options>>
|
||||
node.data = {
|
||||
hProperties: {
|
||||
...(node.data?.hProperties ?? {}),
|
||||
className: classNames.join(" "),
|
||||
"className": classNames.join(" "),
|
||||
"data-callout": calloutType,
|
||||
"data-callout-fold": collapse,
|
||||
"data-callout-metadata": calloutMetaData,
|
||||
@ -606,10 +673,14 @@ export const ObsidianFlavoredMarkdown: QuartzTransformerPlugin<Partial<Options>>
|
||||
plugins.push(() => {
|
||||
return (tree: HtmlRoot) => {
|
||||
visit(tree, "element", (node) => {
|
||||
if (node.tagName === "img" && typeof node.properties.src === "string") {
|
||||
if (
|
||||
node.tagName === "img" &&
|
||||
typeof node.properties.src === "string"
|
||||
) {
|
||||
const match = node.properties.src.match(ytLinkRegex)
|
||||
const videoId = match && match[2].length == 11 ? match[2] : null
|
||||
const playlistId = node.properties.src.match(ytPlaylistLinkRegex)?.[1]
|
||||
const playlistId =
|
||||
node.properties.src.match(ytPlaylistLinkRegex)?.[1]
|
||||
if (videoId) {
|
||||
// YouTube video (with optional playlist)
|
||||
node.tagName = "iframe"
|
||||
@ -643,7 +714,10 @@ export const ObsidianFlavoredMarkdown: QuartzTransformerPlugin<Partial<Options>>
|
||||
plugins.push(() => {
|
||||
return (tree: HtmlRoot, _file) => {
|
||||
visit(tree, "element", (node) => {
|
||||
if (node.tagName === "input" && node.properties.type === "checkbox") {
|
||||
if (
|
||||
node.tagName === "input" &&
|
||||
node.properties.type === "checkbox"
|
||||
) {
|
||||
const isChecked = node.properties?.checked ?? false
|
||||
node.properties = {
|
||||
type: "checkbox",
|
||||
@ -705,7 +779,7 @@ export const ObsidianFlavoredMarkdown: QuartzTransformerPlugin<Partial<Options>>
|
||||
})
|
||||
}
|
||||
|
||||
return { js }
|
||||
return {js}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { QuartzTransformerPlugin } from "../types"
|
||||
import {QuartzTransformerPlugin} from "../types"
|
||||
|
||||
export interface Options {
|
||||
/** Replace {{ relref }} with quartz wikilinks []() */
|
||||
@ -22,7 +22,10 @@ const defaultOptions: Options = {
|
||||
replaceOrgLatex: true,
|
||||
}
|
||||
|
||||
const relrefRegex = new RegExp(/\[([^\]]+)\]\(\{\{< relref "([^"]+)" >\}\}\)/, "g")
|
||||
const relrefRegex = new RegExp(
|
||||
/\[([^\]]+)\]\(\{\{< relref "([^"]+)" >\}\}\)/,
|
||||
"g",
|
||||
)
|
||||
const predefinedHeadingIdRegex = new RegExp(/(.*) {#(?:.*)}/, "g")
|
||||
const hugoShortcodeRegex = new RegExp(/{{(.*)}}/, "g")
|
||||
const figureTagRegex = new RegExp(/< ?figure src="(.*)" ?>/, "g")
|
||||
@ -47,8 +50,10 @@ const quartzLatexRegex = new RegExp(/\$\$[\s\S]*?\$\$|\$.*?\$/, "g")
|
||||
* markdown to make it compatible with quartz but the list of changes applied it
|
||||
* is not exhaustive.
|
||||
* */
|
||||
export const OxHugoFlavouredMarkdown: QuartzTransformerPlugin<Partial<Options>> = (userOpts) => {
|
||||
const opts = { ...defaultOptions, ...userOpts }
|
||||
export const OxHugoFlavouredMarkdown: QuartzTransformerPlugin<
|
||||
Partial<Options>
|
||||
> = (userOpts) => {
|
||||
const opts = {...defaultOptions, ...userOpts}
|
||||
return {
|
||||
name: "OxHugoFlavouredMarkdown",
|
||||
textTransform(_ctx, src) {
|
||||
|
||||
@ -1,5 +1,8 @@
|
||||
import { QuartzTransformerPlugin } from "../types"
|
||||
import rehypePrettyCode, { Options as CodeOptions, Theme as CodeTheme } from "rehype-pretty-code"
|
||||
import {QuartzTransformerPlugin} from "../types"
|
||||
import rehypePrettyCode, {
|
||||
Options as CodeOptions,
|
||||
Theme as CodeTheme,
|
||||
} from "rehype-pretty-code"
|
||||
|
||||
interface Theme extends Record<string, CodeTheme> {
|
||||
light: CodeTheme
|
||||
@ -19,8 +22,10 @@ const defaultOptions: Options = {
|
||||
keepBackground: false,
|
||||
}
|
||||
|
||||
export const SyntaxHighlighting: QuartzTransformerPlugin<Partial<Options>> = (userOpts) => {
|
||||
const opts: CodeOptions = { ...defaultOptions, ...userOpts }
|
||||
export const SyntaxHighlighting: QuartzTransformerPlugin<Partial<Options>> = (
|
||||
userOpts,
|
||||
) => {
|
||||
const opts: CodeOptions = {...defaultOptions, ...userOpts}
|
||||
|
||||
return {
|
||||
name: "SyntaxHighlighting",
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import { QuartzTransformerPlugin } from "../types"
|
||||
import { Root } from "mdast"
|
||||
import { visit } from "unist-util-visit"
|
||||
import { toString } from "mdast-util-to-string"
|
||||
import {QuartzTransformerPlugin} from "../types"
|
||||
import {Root} from "mdast"
|
||||
import {visit} from "unist-util-visit"
|
||||
import {toString} from "mdast-util-to-string"
|
||||
import Slugger from "github-slugger"
|
||||
|
||||
export interface Options {
|
||||
@ -25,15 +25,18 @@ interface TocEntry {
|
||||
}
|
||||
|
||||
const slugAnchor = new Slugger()
|
||||
export const TableOfContents: QuartzTransformerPlugin<Partial<Options>> = (userOpts) => {
|
||||
const opts = { ...defaultOptions, ...userOpts }
|
||||
export const TableOfContents: QuartzTransformerPlugin<Partial<Options>> = (
|
||||
userOpts,
|
||||
) => {
|
||||
const opts = {...defaultOptions, ...userOpts}
|
||||
return {
|
||||
name: "TableOfContents",
|
||||
markdownPlugins() {
|
||||
return [
|
||||
() => {
|
||||
return async (tree: Root, file) => {
|
||||
const display = file.data.frontmatter?.enableToc ?? opts.showByDefault
|
||||
const display =
|
||||
file.data.frontmatter?.enableToc ?? opts.showByDefault
|
||||
if (display) {
|
||||
slugAnchor.reset()
|
||||
const toc: TocEntry[] = []
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
import { PluggableList } from "unified"
|
||||
import { StaticResources } from "../util/resources"
|
||||
import { ProcessedContent } from "./vfile"
|
||||
import { QuartzComponent } from "../components/types"
|
||||
import { FilePath } from "../util/path"
|
||||
import { BuildCtx } from "../util/ctx"
|
||||
import {PluggableList} from "unified"
|
||||
import {StaticResources} from "../util/resources"
|
||||
import {ProcessedContent} from "./vfile"
|
||||
import {QuartzComponent} from "../components/types"
|
||||
import {FilePath} from "../util/path"
|
||||
import {BuildCtx} from "../util/ctx"
|
||||
import DepGraph from "../depgraph"
|
||||
|
||||
export interface PluginTypes {
|
||||
@ -37,7 +37,11 @@ export type QuartzEmitterPlugin<Options extends OptionType = undefined> = (
|
||||
) => QuartzEmitterPluginInstance
|
||||
export type QuartzEmitterPluginInstance = {
|
||||
name: string
|
||||
emit(ctx: BuildCtx, content: ProcessedContent[], resources: StaticResources): Promise<FilePath[]>
|
||||
emit(
|
||||
ctx: BuildCtx,
|
||||
content: ProcessedContent[],
|
||||
resources: StaticResources,
|
||||
): Promise<FilePath[]>
|
||||
getQuartzComponents(ctx: BuildCtx): QuartzComponent[]
|
||||
getDependencyGraph?(
|
||||
ctx: BuildCtx,
|
||||
|
||||
@ -1,11 +1,13 @@
|
||||
import { Node, Parent } from "hast"
|
||||
import { Data, VFile } from "vfile"
|
||||
import {Node, Parent} from "hast"
|
||||
import {Data, VFile} from "vfile"
|
||||
|
||||
export type QuartzPluginData = Data
|
||||
export type ProcessedContent = [Node, VFile]
|
||||
|
||||
export function defaultProcessedContent(vfileData: Partial<QuartzPluginData>): ProcessedContent {
|
||||
const root: Parent = { type: "root", children: [] }
|
||||
export function defaultProcessedContent(
|
||||
vfileData: Partial<QuartzPluginData>,
|
||||
): ProcessedContent {
|
||||
const root: Parent = {type: "root", children: []}
|
||||
const vfile = new VFile("")
|
||||
vfile.data = vfileData
|
||||
return [root, vfile]
|
||||
|
||||
@ -158,7 +158,9 @@ export async function parseMarkdown(
|
||||
|
||||
const childPromises: WorkerPromise<ProcessedContent[]>[] = []
|
||||
for (const chunk of chunks(fps, CHUNK_SIZE)) {
|
||||
childPromises.push(pool.exec("parseFiles", [ctx.buildId, argv, chunk, ctx.allSlugs]))
|
||||
childPromises.push(
|
||||
pool.exec("parseFiles", [ctx.buildId, argv, chunk, ctx.allSlugs]),
|
||||
)
|
||||
}
|
||||
|
||||
const results: ProcessedContent[][] = await WorkerPromise.all(
|
||||
|
||||
@ -512,4 +512,4 @@ ol.overflow {
|
||||
ul {
|
||||
padding-left: 1rem;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import { QuartzConfig } from "../cfg"
|
||||
import { FullSlug } from "./path"
|
||||
import {QuartzConfig} from "../cfg"
|
||||
import {FullSlug} from "./path"
|
||||
|
||||
export interface Argv {
|
||||
directory: string
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import path from "path"
|
||||
import { FilePath } from "./path"
|
||||
import { globby } from "globby"
|
||||
import {FilePath} from "./path"
|
||||
import {globby} from "globby"
|
||||
|
||||
export function toPosixPath(fp: string): string {
|
||||
return fp.split(path.sep).join("/")
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user