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