2023-07-01 07:03:01 +00:00
|
|
|
import { QuartzComponentConstructor, QuartzComponentProps } from "../types"
|
2023-07-23 00:27:41 +00:00
|
|
|
import { Fragment, jsx, jsxs } from "preact/jsx-runtime"
|
2023-07-01 07:03:01 +00:00
|
|
|
import { toJsxRuntime } from "hast-util-to-jsx-runtime"
|
2023-07-23 00:27:41 +00:00
|
|
|
import style from "../styles/listPage.scss"
|
2023-07-01 07:03:01 +00:00
|
|
|
import { PageList } from "../PageList"
|
2023-07-16 06:02:12 +00:00
|
|
|
import { ServerSlug, canonicalizeServer } from "../../path"
|
2023-07-01 07:03:01 +00:00
|
|
|
|
|
|
|
function TagContent(props: QuartzComponentProps) {
|
|
|
|
const { tree, fileData, allFiles } = props
|
|
|
|
const slug = fileData.slug
|
|
|
|
|
2023-07-04 17:08:32 +00:00
|
|
|
if (slug?.startsWith("tags/")) {
|
2023-07-16 06:02:12 +00:00
|
|
|
const tag = canonicalizeServer(slug.slice("tags/".length) as ServerSlug)
|
2023-07-23 00:27:41 +00:00
|
|
|
const allPagesWithTag = allFiles.filter((file) => (file.frontmatter?.tags ?? []).includes(tag))
|
2023-07-01 07:03:01 +00:00
|
|
|
const listProps = {
|
|
|
|
...props,
|
2023-07-23 00:27:41 +00:00
|
|
|
allFiles: allPagesWithTag,
|
2023-07-01 07:03:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// @ts-ignore
|
2023-07-23 00:27:41 +00:00
|
|
|
const content = toJsxRuntime(tree, { Fragment, jsx, jsxs, elementAttributeNameCase: "html" })
|
|
|
|
return (
|
|
|
|
<div class="popover-hint">
|
|
|
|
<article>{content}</article>
|
|
|
|
<p>{allPagesWithTag.length} items with this tag.</p>
|
|
|
|
<div>
|
|
|
|
<PageList {...listProps} />
|
|
|
|
</div>
|
2023-07-01 07:03:01 +00:00
|
|
|
</div>
|
2023-07-23 00:27:41 +00:00
|
|
|
)
|
2023-07-01 07:03:01 +00:00
|
|
|
} else {
|
2023-07-16 06:02:12 +00:00
|
|
|
throw new Error(`Component "TagContent" tried to render a non-tag page: ${slug}`)
|
2023-07-01 07:03:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TagContent.css = style + PageList.css
|
|
|
|
export default (() => TagContent) satisfies QuartzComponentConstructor
|