Update page titles to not show "index"
This commit is contained in:
parent
c2108c4f83
commit
3d95f73093
10
.gitignore
vendored
10
.gitignore
vendored
@ -22,4 +22,12 @@ pnpm-debug.log*
|
|||||||
|
|
||||||
# Direnv junk
|
# Direnv junk
|
||||||
.direnv/*
|
.direnv/*
|
||||||
*/.direnv/*
|
*/.direnv/*
|
||||||
|
|
||||||
|
# Bot thing
|
||||||
|
blog-bot.json
|
||||||
|
|
||||||
|
public/*
|
||||||
|
quartz/public
|
||||||
|
public
|
||||||
|
.quartz-cache
|
||||||
@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"syncToken": "s15_108_10_8_22_1_32_28_0_1_1",
|
"syncToken": "s75_2959_24_27_45_1_44_40_0_1_1",
|
||||||
"filter": null,
|
"filter": null,
|
||||||
"appserviceUsers": {},
|
"appserviceUsers": {},
|
||||||
"appserviceTransactions": {},
|
"appserviceTransactions": {},
|
||||||
|
|||||||
1222
pnpm-lock.yaml
generated
1222
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
@ -1,10 +1,11 @@
|
|||||||
import { QuartzComponent, QuartzComponentConstructor, QuartzComponentProps } from "./types"
|
import { QuartzComponent, QuartzComponentConstructor, QuartzComponentProps } from "./types"
|
||||||
import { classNames } from "../util/lang"
|
import { classNames } from "../util/lang"
|
||||||
|
import { deslugify } from "../util/path"
|
||||||
|
|
||||||
const ArticleTitle: QuartzComponent = ({ fileData, displayClass }: QuartzComponentProps) => {
|
const ArticleTitle: QuartzComponent = ({ fileData, displayClass }: QuartzComponentProps) => {
|
||||||
const title = fileData.frontmatter?.title
|
const title = fileData.frontmatter?.title
|
||||||
if (title) {
|
if (title) {
|
||||||
return <h1 class={classNames(displayClass, "article-title")}>{title}</h1>
|
return <h1 class={classNames(displayClass, "article-title")}>{title == 'index' ? deslugify(fileData.slug!, 2) : title}</h1>
|
||||||
} else {
|
} else {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
import { FullSlug, isFolderPath, resolveRelative } from "../util/path"
|
import { deslugify, FullSlug, isFolderPath, resolveRelative } from "../util/path"
|
||||||
import { QuartzPluginData } from "../plugins/vfile"
|
import { QuartzPluginData } from "../plugins/vfile"
|
||||||
import { Date, getDate } from "./Date"
|
import { Date, getDate } from "./Date"
|
||||||
import { QuartzComponent, QuartzComponentProps } from "./types"
|
import { QuartzComponent, QuartzComponentProps } from "./types"
|
||||||
@ -79,7 +79,7 @@ export const PageList: QuartzComponent = ({ cfg, fileData, allFiles, limit, sort
|
|||||||
<div class="desc">
|
<div class="desc">
|
||||||
<h3>
|
<h3>
|
||||||
<a href={resolveRelative(fileData.slug!, page.slug!)} class="internal">
|
<a href={resolveRelative(fileData.slug!, page.slug!)} class="internal">
|
||||||
{title}
|
{title == "index" ? deslugify(page.slug!) : title}
|
||||||
</a>
|
</a>
|
||||||
</h3>
|
</h3>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -4,7 +4,7 @@ import { classNames } from "../util/lang"
|
|||||||
import { i18n } from "../i18n"
|
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 title = cfg?.pageTitle ?? fileData.slug
|
||||||
const baseDir = pathToRoot(fileData.slug!)
|
const baseDir = pathToRoot(fileData.slug!)
|
||||||
return (
|
return (
|
||||||
<h2 class={classNames(displayClass, "page-title")}>
|
<h2 class={classNames(displayClass, "page-title")}>
|
||||||
|
|||||||
@ -54,7 +54,7 @@ export function getFullSlug(window: Window): FullSlug {
|
|||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
function sluggify(s: string): string {
|
function sluggify(s: FullSlug): string {
|
||||||
return s
|
return s
|
||||||
.split("/")
|
.split("/")
|
||||||
.map((segment) =>
|
.map((segment) =>
|
||||||
@ -69,6 +69,17 @@ function sluggify(s: string): string {
|
|||||||
.replace(/\/$/, "")
|
.replace(/\/$/, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function deslugify(slug: string, dirs?: number): string {
|
||||||
|
const sliceStart = dirs === undefined ? -2 : -1 - dirs
|
||||||
|
|
||||||
|
return slug
|
||||||
|
.split("/")
|
||||||
|
.slice(sliceStart,-1)
|
||||||
|
.join(": ")
|
||||||
|
.replace(/-and-/g, "&")
|
||||||
|
.replace(/-/g, " ")
|
||||||
|
}
|
||||||
|
|
||||||
export function slugifyFilePath(fp: FilePath, excludeExt?: boolean): FullSlug {
|
export function slugifyFilePath(fp: FilePath, excludeExt?: boolean): FullSlug {
|
||||||
fp = stripSlashes(fp) as FilePath
|
fp = stripSlashes(fp) as FilePath
|
||||||
let ext = getFileExtension(fp)
|
let ext = getFileExtension(fp)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user