mirror of
https://github.com/jackyzha0/quartz.git
synced 2026-02-03 22:15:42 -06:00
style: Fixed styling according to prettier
This commit is contained in:
parent
34ca053936
commit
15ff47b82d
@ -1,5 +1,5 @@
|
|||||||
import { PageLayout, SharedLayout } from "./quartz/cfg";
|
import { PageLayout, SharedLayout } from "./quartz/cfg"
|
||||||
import * as Component from "./quartz/components";
|
import * as Component from "./quartz/components"
|
||||||
|
|
||||||
// components shared across all pages
|
// components shared across all pages
|
||||||
export const sharedPageComponents: SharedLayout = {
|
export const sharedPageComponents: SharedLayout = {
|
||||||
@ -12,7 +12,7 @@ export const sharedPageComponents: SharedLayout = {
|
|||||||
"Discord Community": "https://discord.gg/cRFFHYye7t",
|
"Discord Community": "https://discord.gg/cRFFHYye7t",
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
};
|
}
|
||||||
|
|
||||||
// components for pages that display a single page (e.g. a single note)
|
// components for pages that display a single page (e.g. a single note)
|
||||||
export const defaultContentPageLayout: PageLayout = {
|
export const defaultContentPageLayout: PageLayout = {
|
||||||
@ -45,7 +45,7 @@ export const defaultContentPageLayout: PageLayout = {
|
|||||||
Component.DesktopOnly(Component.TableOfContents()),
|
Component.DesktopOnly(Component.TableOfContents()),
|
||||||
Component.Backlinks(),
|
Component.Backlinks(),
|
||||||
],
|
],
|
||||||
};
|
}
|
||||||
|
|
||||||
// components for pages that display lists of pages (e.g. tags or folders)
|
// components for pages that display lists of pages (e.g. tags or folders)
|
||||||
export const defaultListPageLayout: PageLayout = {
|
export const defaultListPageLayout: PageLayout = {
|
||||||
@ -65,4 +65,4 @@ export const defaultListPageLayout: PageLayout = {
|
|||||||
Component.Explorer(),
|
Component.Explorer(),
|
||||||
],
|
],
|
||||||
right: [],
|
right: [],
|
||||||
};
|
}
|
||||||
|
|||||||
@ -1,14 +1,14 @@
|
|||||||
import { QuartzComponent, QuartzComponentConstructor, QuartzComponentProps } from "./types";
|
import { QuartzComponent, QuartzComponentConstructor, QuartzComponentProps } from "./types"
|
||||||
import { QuartzPluginData } from "../plugins/vfile";
|
import { QuartzPluginData } from "../plugins/vfile"
|
||||||
import { classNames } from "../util/lang";
|
import { classNames } from "../util/lang"
|
||||||
import { resolveRelative, simplifySlug, FullSlug, SimpleSlug } from "../util/path";
|
import { resolveRelative, simplifySlug, FullSlug, SimpleSlug } from "../util/path"
|
||||||
import style from "./styles/breadcrumbs.scss";
|
import style from "./styles/breadcrumbs.scss"
|
||||||
|
|
||||||
interface ParentBreadcrumbsOptions {
|
interface ParentBreadcrumbsOptions {
|
||||||
spacerSymbol?: string;
|
spacerSymbol?: string
|
||||||
rootName?: string;
|
rootName?: string
|
||||||
resolveFrontmatterTitle?: boolean;
|
resolveFrontmatterTitle?: boolean
|
||||||
frontmatterProp?: string,
|
frontmatterProp?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
const defaultOptions: ParentBreadcrumbsOptions = {
|
const defaultOptions: ParentBreadcrumbsOptions = {
|
||||||
@ -16,88 +16,89 @@ const defaultOptions: ParentBreadcrumbsOptions = {
|
|||||||
rootName: "Home",
|
rootName: "Home",
|
||||||
resolveFrontmatterTitle: true,
|
resolveFrontmatterTitle: true,
|
||||||
frontmatterProp: "parent",
|
frontmatterProp: "parent",
|
||||||
};
|
}
|
||||||
|
|
||||||
export default ((opts?: ParentBreadcrumbsOptions) => {
|
export default ((opts?: ParentBreadcrumbsOptions) => {
|
||||||
const options = { ...defaultOptions, ...opts };
|
const options = { ...defaultOptions, ...opts }
|
||||||
const parentKey = options.frontmatterProp;
|
const parentKey = options.frontmatterProp
|
||||||
|
|
||||||
const ParentBreadcrumbs: QuartzComponent = ({
|
const ParentBreadcrumbs: QuartzComponent = ({
|
||||||
fileData,
|
fileData,
|
||||||
allFiles,
|
allFiles,
|
||||||
displayClass,
|
displayClass,
|
||||||
}: QuartzComponentProps) => {
|
}: QuartzComponentProps) => {
|
||||||
|
|
||||||
const parseWikiLink = (content: string): string => {
|
const parseWikiLink = (content: string): string => {
|
||||||
if (!content) return "";
|
if (!content) return ""
|
||||||
let clean = content.trim().replace(/^["']|["']$/g, "");
|
let clean = content.trim().replace(/^["']|["']$/g, "")
|
||||||
clean = clean.replace(/^\[\[|\]\]$/g, "");
|
clean = clean.replace(/^\[\[|\]\]$/g, "")
|
||||||
return clean.split("|")[0];
|
return clean.split("|")[0]
|
||||||
};
|
}
|
||||||
|
|
||||||
const findFile = (name: string) => {
|
const findFile = (name: string) => {
|
||||||
const targetSlug = simplifySlug(name as FullSlug);
|
const targetSlug = simplifySlug(name as FullSlug)
|
||||||
return allFiles.find((f: QuartzPluginData) => {
|
return allFiles.find((f: QuartzPluginData) => {
|
||||||
const fSlug = simplifySlug(f.slug!);
|
const fSlug = simplifySlug(f.slug!)
|
||||||
return fSlug === targetSlug || fSlug.endsWith(targetSlug) || f.frontmatter?.title === name;
|
return fSlug === targetSlug || fSlug.endsWith(targetSlug) || f.frontmatter?.title === name
|
||||||
});
|
})
|
||||||
};
|
}
|
||||||
|
|
||||||
type BreadcrumbNode = { displayName: string; path: string; };
|
type BreadcrumbNode = { displayName: string; path: string }
|
||||||
const crumbs: Array<BreadcrumbNode[]> = [];
|
const crumbs: Array<BreadcrumbNode[]> = []
|
||||||
|
|
||||||
let current = fileData;
|
let current = fileData
|
||||||
const visited = new Set<string>();
|
const visited = new Set<string>()
|
||||||
if (current.slug) visited.add(current.slug);
|
if (current.slug) visited.add(current.slug)
|
||||||
|
|
||||||
while (current && current.frontmatter?.[parentKey!]) {
|
while (current && current.frontmatter?.[parentKey!]) {
|
||||||
const rawParent = current.frontmatter[parentKey!];
|
const rawParent = current.frontmatter[parentKey!]
|
||||||
const parentList = Array.isArray(rawParent) ? rawParent : [rawParent];
|
const parentList = Array.isArray(rawParent) ? rawParent : [rawParent]
|
||||||
|
|
||||||
const currentLevelNodes: BreadcrumbNode[] = [];
|
const currentLevelNodes: BreadcrumbNode[] = []
|
||||||
let nextParent: QuartzPluginData | undefined = undefined;
|
let nextParent: QuartzPluginData | undefined = undefined
|
||||||
|
|
||||||
for (const p of parentList) {
|
for (const p of parentList) {
|
||||||
const linkStr = parseWikiLink(p as string);
|
const linkStr = parseWikiLink(p as string)
|
||||||
const parentFile = findFile(linkStr);
|
const parentFile = findFile(linkStr)
|
||||||
|
|
||||||
if (parentFile && parentFile.slug) {
|
if (parentFile && parentFile.slug) {
|
||||||
currentLevelNodes.push({
|
currentLevelNodes.push({
|
||||||
displayName: options.resolveFrontmatterTitle
|
displayName: options.resolveFrontmatterTitle
|
||||||
? parentFile.frontmatter?.title ?? parentFile.slug
|
? (parentFile.frontmatter?.title ?? parentFile.slug)
|
||||||
: parentFile.slug,
|
: parentFile.slug,
|
||||||
path: resolveRelative(fileData.slug!, parentFile.slug!)
|
path: resolveRelative(fileData.slug!, parentFile.slug!),
|
||||||
});
|
})
|
||||||
|
|
||||||
if (!nextParent && !visited.has(parentFile.slug)) {
|
if (!nextParent && !visited.has(parentFile.slug)) {
|
||||||
nextParent = parentFile;
|
nextParent = parentFile
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (currentLevelNodes.length > 0) {
|
if (currentLevelNodes.length > 0) {
|
||||||
crumbs.push(currentLevelNodes);
|
crumbs.push(currentLevelNodes)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nextParent) {
|
if (nextParent) {
|
||||||
visited.add(nextParent.slug!);
|
visited.add(nextParent.slug!)
|
||||||
current = nextParent;
|
current = nextParent
|
||||||
} else {
|
} else {
|
||||||
break;
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (current.slug !== "index") {
|
if (current.slug !== "index") {
|
||||||
crumbs.push([{
|
crumbs.push([
|
||||||
|
{
|
||||||
displayName: options.rootName!,
|
displayName: options.rootName!,
|
||||||
path: resolveRelative(fileData.slug!, "index" as SimpleSlug)
|
path: resolveRelative(fileData.slug!, "index" as SimpleSlug),
|
||||||
}]);
|
},
|
||||||
|
])
|
||||||
}
|
}
|
||||||
|
|
||||||
crumbs.reverse();
|
crumbs.reverse()
|
||||||
|
|
||||||
if (crumbs.length === 0 && fileData.slug === "index") {
|
if (crumbs.length === 0 && fileData.slug === "index") {
|
||||||
return <></>;
|
return <></>
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -117,9 +118,9 @@ export default ((opts?: ParentBreadcrumbsOptions) => {
|
|||||||
<p>{fileData.frontmatter?.title}</p>
|
<p>{fileData.frontmatter?.title}</p>
|
||||||
</div>
|
</div>
|
||||||
</nav>
|
</nav>
|
||||||
);
|
)
|
||||||
};
|
}
|
||||||
|
|
||||||
ParentBreadcrumbs.css = style;
|
ParentBreadcrumbs.css = style
|
||||||
return ParentBreadcrumbs;
|
return ParentBreadcrumbs
|
||||||
}) satisfies QuartzComponentConstructor;
|
}) satisfies QuartzComponentConstructor
|
||||||
|
|||||||
@ -1,29 +1,29 @@
|
|||||||
import Content from "./pages/Content";
|
import Content from "./pages/Content"
|
||||||
import TagContent from "./pages/TagContent";
|
import TagContent from "./pages/TagContent"
|
||||||
import FolderContent from "./pages/FolderContent";
|
import FolderContent from "./pages/FolderContent"
|
||||||
import NotFound from "./pages/404";
|
import NotFound from "./pages/404"
|
||||||
import ArticleTitle from "./ArticleTitle";
|
import ArticleTitle from "./ArticleTitle"
|
||||||
import Darkmode from "./Darkmode";
|
import Darkmode from "./Darkmode"
|
||||||
import ReaderMode from "./ReaderMode";
|
import ReaderMode from "./ReaderMode"
|
||||||
import Head from "./Head";
|
import Head from "./Head"
|
||||||
import PageTitle from "./PageTitle";
|
import PageTitle from "./PageTitle"
|
||||||
import ContentMeta from "./ContentMeta";
|
import ContentMeta from "./ContentMeta"
|
||||||
import Spacer from "./Spacer";
|
import Spacer from "./Spacer"
|
||||||
import TableOfContents from "./TableOfContents";
|
import TableOfContents from "./TableOfContents"
|
||||||
import Explorer from "./Explorer";
|
import Explorer from "./Explorer"
|
||||||
import TagList from "./TagList";
|
import TagList from "./TagList"
|
||||||
import Graph from "./Graph";
|
import Graph from "./Graph"
|
||||||
import Backlinks from "./Backlinks";
|
import Backlinks from "./Backlinks"
|
||||||
import Search from "./Search";
|
import Search from "./Search"
|
||||||
import Footer from "./Footer";
|
import Footer from "./Footer"
|
||||||
import DesktopOnly from "./DesktopOnly";
|
import DesktopOnly from "./DesktopOnly"
|
||||||
import MobileOnly from "./MobileOnly";
|
import MobileOnly from "./MobileOnly"
|
||||||
import RecentNotes from "./RecentNotes";
|
import RecentNotes from "./RecentNotes"
|
||||||
import Breadcrumbs from "./Breadcrumbs";
|
import Breadcrumbs from "./Breadcrumbs"
|
||||||
import Comments from "./Comments";
|
import Comments from "./Comments"
|
||||||
import Flex from "./Flex";
|
import Flex from "./Flex"
|
||||||
import ConditionalRender from "./ConditionalRender";
|
import ConditionalRender from "./ConditionalRender"
|
||||||
import ParentBreadcrumbs from "./ParentBreadcrumbs";
|
import ParentBreadcrumbs from "./ParentBreadcrumbs"
|
||||||
|
|
||||||
export {
|
export {
|
||||||
ParentBreadcrumbs,
|
ParentBreadcrumbs,
|
||||||
@ -52,4 +52,4 @@ export {
|
|||||||
Comments,
|
Comments,
|
||||||
Flex,
|
Flex,
|
||||||
ConditionalRender,
|
ConditionalRender,
|
||||||
};
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user