forked from jackyzha0/quartz
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🔄 synced local 'quartz/' with remote 'quartz/'
- Loading branch information
Showing
5 changed files
with
240 additions
and
236 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,22 @@ | ||
import { pathToRoot } from "../util/path" | ||
import { QuartzComponent, QuartzComponentConstructor, QuartzComponentProps } from "./types" | ||
import { classNames } from "../util/lang" | ||
import { i18n } from "../i18n" | ||
import { i18n } from "../i18n"; | ||
import { classNames } from "../util/lang"; | ||
import { pathToRoot } from "../util/path"; | ||
import { QuartzComponent, QuartzComponentConstructor, QuartzComponentProps } from "./types"; | ||
|
||
const PageTitle: QuartzComponent = ({ fileData, cfg, displayClass }: QuartzComponentProps) => { | ||
const title = cfg?.pageTitle ?? i18n(cfg.locale).propertyDefaults.title | ||
const baseDir = pathToRoot(fileData.slug!) | ||
return ( | ||
<h1 class={classNames(displayClass, "page-title")}> | ||
<a href={baseDir}>{title}</a> | ||
</h1> | ||
) | ||
} | ||
const title = cfg?.pageTitle ?? i18n(cfg.locale).propertyDefaults.title; | ||
const baseDir = pathToRoot(fileData.slug!); | ||
return ( | ||
<h1 class={classNames(displayClass, "page-title")}> | ||
<a href={baseDir}>{title}</a> | ||
</h1> | ||
); | ||
}; | ||
|
||
PageTitle.css = ` | ||
.page-title { | ||
margin: 0; | ||
} | ||
` | ||
`; | ||
|
||
export default (() => PageTitle) satisfies QuartzComponentConstructor | ||
export default (() => PageTitle) satisfies QuartzComponentConstructor; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,71 +1,73 @@ | ||
import { QuartzComponent, QuartzComponentConstructor, QuartzComponentProps } from "../types" | ||
import path from "path" | ||
import { Root } from "hast"; | ||
import path from "path"; | ||
|
||
import style from "../styles/listPage.scss" | ||
import { PageList } from "../PageList" | ||
import { stripSlashes, simplifySlug } from "../../util/path" | ||
import { Root } from "hast" | ||
import { classNames } from "../../util/lang" | ||
import { htmlToJsx } from "../../util/jsx" | ||
import { i18n } from "../../i18n" | ||
import { i18n } from "../../i18n"; | ||
import { htmlToJsx } from "../../util/jsx"; | ||
import { classNames } from "../../util/lang"; | ||
import { simplifySlug,stripSlashes } from "../../util/path"; | ||
import { PageList } from "../PageList"; | ||
import style from "../styles/listPage.scss"; | ||
import { QuartzComponent, QuartzComponentConstructor, QuartzComponentProps } from "../types"; | ||
|
||
interface FolderContentOptions { | ||
/** | ||
* Whether to display number of folders | ||
*/ | ||
showFolderCount: boolean | ||
/** | ||
* Whether to display number of folders | ||
*/ | ||
showFolderCount: boolean | ||
} | ||
|
||
const defaultOptions: FolderContentOptions = { | ||
showFolderCount: true, | ||
} | ||
showFolderCount: true, | ||
}; | ||
|
||
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 folderSlug = stripSlashes(simplifySlug(fileData.slug!)) | ||
const allPagesInFolder = allFiles.filter((file) => { | ||
const fileSlug = stripSlashes(simplifySlug(file.slug!)) | ||
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 | ||
return prefixed && isDirectChild | ||
}) | ||
const cssClasses: string[] = fileData.frontmatter?.cssclasses ?? [] | ||
const listProps = { | ||
...props, | ||
allFiles: allPagesInFolder, | ||
} | ||
const FolderContent: QuartzComponent = (props: QuartzComponentProps) => { | ||
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 folderParts = folderSlug.split(path.posix.sep); | ||
const fileParts = fileSlug.split(path.posix.sep); | ||
const isDirectChild = fileParts.length === folderParts.length + 1; | ||
return prefixed && isDirectChild; | ||
}); | ||
const cssClasses: string[] = fileData.frontmatter?.cssclasses ?? []; | ||
const listProps = { | ||
...props, | ||
allFiles: allPagesInFolder, | ||
}; | ||
|
||
const content = | ||
(tree as Root).children.length === 0 | ||
? fileData.description | ||
: htmlToJsx(fileData.filePath!, tree) | ||
const content = | ||
(tree as Root).children.length === 0 | ||
? fileData.description | ||
: htmlToJsx(fileData.filePath!, tree); | ||
|
||
return ( | ||
<div class={classNames(undefined, "popover-hint", ...cssClasses)}> | ||
<article> | ||
<p>{content}</p> | ||
</article> | ||
<div class="page-listing"> | ||
{options.showFolderCount && ( | ||
<p> | ||
{i18n(cfg.locale).pages.folderContent.itemsUnderFolder({ | ||
count: allPagesInFolder.length, | ||
})} | ||
</p> | ||
)} | ||
<div> | ||
<PageList {...listProps} /> | ||
</div> | ||
</div> | ||
</div> | ||
) | ||
} | ||
return ( | ||
<div class={classNames(undefined, "popover-hint", ...cssClasses)}> | ||
<article> | ||
<p>{content}</p> | ||
</article> | ||
{(!content || content?.props?.children?.length === 0) && ( | ||
<div class="page-listing"> | ||
{options.showFolderCount && ( | ||
<p> | ||
{i18n(cfg.locale).pages.folderContent.itemsUnderFolder({ | ||
count: allPagesInFolder.length, | ||
})} | ||
</p> | ||
)} | ||
<div> | ||
<PageList {...listProps} /> | ||
</div> | ||
</div> | ||
)} | ||
</div> | ||
); | ||
}; | ||
|
||
FolderContent.css = style + PageList.css | ||
return FolderContent | ||
}) satisfies QuartzComponentConstructor | ||
FolderContent.css = style + PageList.css; | ||
return FolderContent; | ||
}) satisfies QuartzComponentConstructor; |
Oops, something went wrong.