mirror of
https://github.com/jackyzha0/quartz.git
synced 2026-03-24 15:05:42 -05:00
fixup! feat: add subfolders to folder page: remove separate folder list
This commit is contained in:
parent
405f6f5103
commit
9dac4c8239
@ -1,38 +0,0 @@
|
|||||||
import path from "path"
|
|
||||||
import { resolveRelative, SimpleSlug } from "../util/path"
|
|
||||||
import { QuartzComponent, QuartzComponentProps } from "./types"
|
|
||||||
|
|
||||||
type Props = {
|
|
||||||
limit?: number
|
|
||||||
} & QuartzComponentProps
|
|
||||||
|
|
||||||
export const FolderList: QuartzComponent = ({ cfg, fileData, allFolders, limit }: Props) => {
|
|
||||||
let list: SimpleSlug[] = allFolders.sort(_alphabetical)
|
|
||||||
if (limit) {
|
|
||||||
list = list.slice(0, limit)
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<ul>
|
|
||||||
{list.map((folderSlug) => {
|
|
||||||
const title = _getTitle(folderSlug)
|
|
||||||
|
|
||||||
return (
|
|
||||||
<li>
|
|
||||||
<a href={resolveRelative(fileData.slug!, folderSlug!)}>{title}</a>
|
|
||||||
</li>
|
|
||||||
)
|
|
||||||
})}
|
|
||||||
</ul>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
function _alphabetical(f1: SimpleSlug, f2: SimpleSlug): number {
|
|
||||||
const f1Title = _getTitle(f1)
|
|
||||||
const f2Title = _getTitle(f2)
|
|
||||||
return f1Title.localeCompare(f2Title)
|
|
||||||
}
|
|
||||||
|
|
||||||
function _getTitle(folderSlug: SimpleSlug): string {
|
|
||||||
return folderSlug.split(path.posix.sep).at(-1)!
|
|
||||||
}
|
|
||||||
@ -3,8 +3,7 @@ import path from "path"
|
|||||||
|
|
||||||
import style from "../styles/listPage.scss"
|
import style from "../styles/listPage.scss"
|
||||||
import { PageList, SortFn } from "../PageList"
|
import { PageList, SortFn } from "../PageList"
|
||||||
import { FolderList } from "../FolderList"
|
import { stripSlashes, simplifySlug, SimpleSlug, joinSegments, FullSlug } from "../../util/path"
|
||||||
import { stripSlashes, simplifySlug, SimpleSlug, joinSegments } from "../../util/path"
|
|
||||||
import { Root } from "hast"
|
import { Root } from "hast"
|
||||||
import { htmlToJsx } from "../../util/jsx"
|
import { htmlToJsx } from "../../util/jsx"
|
||||||
import { i18n } from "../../i18n"
|
import { i18n } from "../../i18n"
|
||||||
@ -32,7 +31,7 @@ export default ((opts?: Partial<FolderContentOptions>) => {
|
|||||||
const folderSlug = stripSlashes(simplifySlug(fileData.slug!))
|
const folderSlug = stripSlashes(simplifySlug(fileData.slug!))
|
||||||
|
|
||||||
const allPagesInFolder: QuartzPluginData[] = []
|
const allPagesInFolder: QuartzPluginData[] = []
|
||||||
const allSubfolders: Set<SimpleSlug> = new Set()
|
const allSubfolders: Set<FullSlug> = new Set()
|
||||||
|
|
||||||
allFiles.forEach((file) => {
|
allFiles.forEach((file) => {
|
||||||
const fileSlug = stripSlashes(simplifySlug(file.slug!))
|
const fileSlug = stripSlashes(simplifySlug(file.slug!))
|
||||||
@ -48,22 +47,21 @@ export default ((opts?: Partial<FolderContentOptions>) => {
|
|||||||
if (isDirectChild) {
|
if (isDirectChild) {
|
||||||
allPagesInFolder.push(file)
|
allPagesInFolder.push(file)
|
||||||
} else {
|
} else {
|
||||||
const folderSlug = joinSegments(...fileParts.slice(0, folderParts.length + 1))
|
const folderSlug = joinSegments(...fileParts.slice(0, folderParts.length + 1)) as FullSlug
|
||||||
allSubfolders.add(folderSlug as SimpleSlug)
|
if (!allSubfolders.has(folderSlug)) {
|
||||||
|
allPagesInFolder.push(_createFolderData(folderSlug))
|
||||||
|
}
|
||||||
|
allSubfolders.add(folderSlug)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
const cssClasses: string[] = fileData.frontmatter?.cssclasses ?? []
|
const cssClasses: string[] = fileData.frontmatter?.cssclasses ?? []
|
||||||
const classes = ["popover-hint", ...cssClasses].join(" ")
|
const classes = ["popover-hint", ...cssClasses].join(" ")
|
||||||
const pageListProps = {
|
const listProps = {
|
||||||
...props,
|
...props,
|
||||||
sort: options.sort,
|
sort: options.sort,
|
||||||
allFiles: allPagesInFolder,
|
allFiles: allPagesInFolder,
|
||||||
}
|
}
|
||||||
const folderListProps = {
|
|
||||||
...props,
|
|
||||||
allFolders: Array.from(allSubfolders.values()),
|
|
||||||
}
|
|
||||||
|
|
||||||
const content =
|
const content =
|
||||||
(tree as Root).children.length === 0
|
(tree as Root).children.length === 0
|
||||||
@ -82,15 +80,7 @@ export default ((opts?: Partial<FolderContentOptions>) => {
|
|||||||
</p>
|
</p>
|
||||||
)}
|
)}
|
||||||
<div>
|
<div>
|
||||||
<PageList {...pageListProps} />
|
<PageList {...listProps} />
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="page-listing">
|
|
||||||
{options.showSubfolders && (
|
|
||||||
<p>{allSubfolders.size === 1 ? "1 subfolder." : `${allSubfolders.size} subfolders.`}</p>
|
|
||||||
)}
|
|
||||||
<div>
|
|
||||||
<FolderList {...folderListProps} />
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -100,3 +90,12 @@ export default ((opts?: Partial<FolderContentOptions>) => {
|
|||||||
FolderContent.css = style + PageList.css
|
FolderContent.css = style + PageList.css
|
||||||
return FolderContent
|
return FolderContent
|
||||||
}) satisfies QuartzComponentConstructor
|
}) satisfies QuartzComponentConstructor
|
||||||
|
|
||||||
|
function _createFolderData(folderSlug: FullSlug): QuartzPluginData {
|
||||||
|
return {
|
||||||
|
slug: folderSlug,
|
||||||
|
frontmatter: {
|
||||||
|
title: folderSlug.split(path.posix.sep).at(-1)!,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user