2023-07-01 14:03:01 +07:00
|
|
|
import { QuartzComponentConstructor, QuartzComponentProps } from "../types"
|
2023-07-23 07:27:41 +07:00
|
|
|
import { Fragment, jsx, jsxs } from "preact/jsx-runtime"
|
2023-07-01 14:03:01 +07:00
|
|
|
import { toJsxRuntime } from "hast-util-to-jsx-runtime"
|
|
|
|
import path from "path"
|
|
|
|
|
2023-07-23 07:27:41 +07:00
|
|
|
import style from "../styles/listPage.scss"
|
2023-07-01 14:03:01 +07:00
|
|
|
import { PageList } from "../PageList"
|
2023-07-16 13:02:12 +07:00
|
|
|
import { canonicalizeServer } from "../../path"
|
2023-07-01 14:03:01 +07:00
|
|
|
|
2023-07-05 00:08:32 +07:00
|
|
|
function FolderContent(props: QuartzComponentProps) {
|
2023-07-01 14:03:01 +07:00
|
|
|
const { tree, fileData, allFiles } = props
|
2023-07-16 13:02:12 +07:00
|
|
|
const folderSlug = canonicalizeServer(fileData.slug!)
|
2023-07-23 07:27:41 +07:00
|
|
|
const allPagesInFolder = allFiles.filter((file) => {
|
2023-07-24 11:41:09 +07:00
|
|
|
const fileSlug = canonicalizeServer(file.slug!)
|
|
|
|
const prefixed = fileSlug.startsWith(folderSlug) && fileSlug !== folderSlug
|
2023-07-01 14:03:01 +07:00
|
|
|
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 listProps = {
|
|
|
|
...props,
|
2023-07-23 07:27:41 +07:00
|
|
|
allFiles: allPagesInFolder,
|
2023-07-01 14:03:01 +07:00
|
|
|
}
|
2023-07-23 07:27:41 +07:00
|
|
|
|
2023-07-01 14:03:01 +07:00
|
|
|
// @ts-ignore
|
2023-07-23 07:27:41 +07:00
|
|
|
const content = toJsxRuntime(tree, { Fragment, jsx, jsxs, elementAttributeNameCase: "html" })
|
|
|
|
return (
|
|
|
|
<div class="popover-hint">
|
|
|
|
<article>{content}</article>
|
|
|
|
<p>{allPagesInFolder.length} items under this folder.</p>
|
|
|
|
<div>
|
|
|
|
<PageList {...listProps} />
|
|
|
|
</div>
|
2023-07-01 14:03:01 +07:00
|
|
|
</div>
|
2023-07-23 07:27:41 +07:00
|
|
|
)
|
2023-07-01 14:03:01 +07:00
|
|
|
}
|
|
|
|
|
2023-07-05 00:08:32 +07:00
|
|
|
FolderContent.css = style + PageList.css
|
|
|
|
export default (() => FolderContent) satisfies QuartzComponentConstructor
|