2023-07-01 10:03:01 +03:00
|
|
|
import { QuartzComponentConstructor, QuartzComponentProps } from "../types"
|
2023-07-23 03:27:41 +03:00
|
|
|
import { Fragment, jsx, jsxs } from "preact/jsx-runtime"
|
2023-07-01 10:03:01 +03:00
|
|
|
import { toJsxRuntime } from "hast-util-to-jsx-runtime"
|
|
|
|
import path from "path"
|
|
|
|
|
2023-07-23 03:27:41 +03:00
|
|
|
import style from "../styles/listPage.scss"
|
2023-07-01 10:03:01 +03:00
|
|
|
import { PageList } from "../PageList"
|
2023-08-20 02:28:44 +03:00
|
|
|
import { _stripSlashes, simplifySlug } from "../../util/path"
|
2023-08-20 11:08:18 +03:00
|
|
|
import { Root } from "hast"
|
2023-09-03 04:07:26 +03:00
|
|
|
import { pluralize } from "../../util/lang"
|
2023-07-01 10:03:01 +03:00
|
|
|
|
2023-07-04 20:08:32 +03:00
|
|
|
function FolderContent(props: QuartzComponentProps) {
|
2023-07-01 10:03:01 +03:00
|
|
|
const { tree, fileData, allFiles } = props
|
2023-08-20 02:28:44 +03:00
|
|
|
const folderSlug = _stripSlashes(simplifySlug(fileData.slug!))
|
2023-07-23 03:27:41 +03:00
|
|
|
const allPagesInFolder = allFiles.filter((file) => {
|
2023-08-21 01:02:24 +03:00
|
|
|
const fileSlug = _stripSlashes(simplifySlug(file.slug!))
|
2023-07-24 07:41:09 +03:00
|
|
|
const prefixed = fileSlug.startsWith(folderSlug) && fileSlug !== folderSlug
|
2023-07-01 10:03:01 +03: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 03:27:41 +03:00
|
|
|
allFiles: allPagesInFolder,
|
2023-07-01 10:03:01 +03:00
|
|
|
}
|
2023-07-23 03:27:41 +03:00
|
|
|
|
2023-08-20 22:46:37 +03:00
|
|
|
const content =
|
|
|
|
(tree as Root).children.length === 0
|
|
|
|
? fileData.description
|
|
|
|
: // @ts-ignore
|
|
|
|
toJsxRuntime(tree, { Fragment, jsx, jsxs, elementAttributeNameCase: "html" })
|
2023-08-20 11:08:18 +03:00
|
|
|
|
2023-07-23 03:27:41 +03:00
|
|
|
return (
|
|
|
|
<div class="popover-hint">
|
2023-08-23 23:10:23 +03:00
|
|
|
<article>
|
|
|
|
<p>{content}</p>
|
|
|
|
</article>
|
2023-09-03 04:07:26 +03:00
|
|
|
<p>{pluralize(allPagesInFolder.length, "item")} under this folder.</p>
|
2023-07-23 03:27:41 +03:00
|
|
|
<div>
|
|
|
|
<PageList {...listProps} />
|
|
|
|
</div>
|
2023-07-01 10:03:01 +03:00
|
|
|
</div>
|
2023-07-23 03:27:41 +03:00
|
|
|
)
|
2023-07-01 10:03:01 +03:00
|
|
|
}
|
|
|
|
|
2023-07-04 20:08:32 +03:00
|
|
|
FolderContent.css = style + PageList.css
|
|
|
|
export default (() => FolderContent) satisfies QuartzComponentConstructor
|