mirror of
https://github.com/jackyzha0/quartz.git
synced 2025-12-24 13:24:05 -06:00
Add hideOnRoot option to Component.Backlinks
This commit is contained in:
parent
fac62575ae
commit
1df9e9564f
@ -137,6 +137,7 @@ The home page is the main web page of your Quartz. The content for the home page
|
||||
|
||||
Customization of the home page can be achieved by conditionally hiding or unhiding components; by passing in a boolean value to the `hideOnRoot:` options in `quartz.config.ts`. The components that support this feature are:
|
||||
|
||||
- [[Backlinks]] are shown by default, to hide them the configuration looks like: `Component.Backlinks({ hideOnRoot: true }){:ts}`
|
||||
- [[Breadcrumbs]] are hidden by default, to unhide them the configuration looks like: `Component.Breadcrumbs({ hideOnRoot: false }){:ts}`
|
||||
- Date and reading time are shown by default, to hide them the configuration looks like: `Component.ContentMeta({ hideOnRoot: true }){:ts}`
|
||||
|
||||
|
||||
@ -10,6 +10,7 @@ A backlink for a note is a link from another note to that note. Links in the bac
|
||||
|
||||
- Removing backlinks: delete all usages of `Component.Backlinks()` from `quartz.layout.ts`.
|
||||
- Hide when empty: hide `Backlinks` if given page doesn't contain any backlinks (default to `true`). To disable this, use `Component.Backlinks({ hideWhenEmpty: false })`.
|
||||
- Hide on root: hide `Backlinks` on the home page `content/index.md` (default to `false`). To enable this, use `Component.Backlinks({ hideOnRoot: true })`.
|
||||
- Component: `quartz/components/Backlinks.tsx`
|
||||
- Style: `quartz/components/styles/backlinks.scss`
|
||||
- Script: `quartz/components/scripts/search.inline.ts`
|
||||
|
||||
@ -7,10 +7,12 @@ import OverflowListFactory from "./OverflowList"
|
||||
|
||||
interface BacklinksOptions {
|
||||
hideWhenEmpty: boolean
|
||||
hideOnRoot: boolean
|
||||
}
|
||||
|
||||
const defaultOptions: BacklinksOptions = {
|
||||
hideWhenEmpty: true,
|
||||
hideOnRoot: false
|
||||
}
|
||||
|
||||
export default ((opts?: Partial<BacklinksOptions>) => {
|
||||
@ -23,6 +25,11 @@ export default ((opts?: Partial<BacklinksOptions>) => {
|
||||
displayClass,
|
||||
cfg,
|
||||
}: QuartzComponentProps) => {
|
||||
// Hide backlinks on root if enabled
|
||||
if (options.hideOnRoot && fileData.slug === "index") {
|
||||
return null
|
||||
}
|
||||
|
||||
const slug = simplifySlug(fileData.slug!)
|
||||
const backlinkFiles = allFiles.filter((file) => file.links?.includes(slug))
|
||||
if (options.hideWhenEmpty && backlinkFiles.length == 0) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user