roadmap/quartz/components/TagList.tsx

53 lines
1.1 KiB
TypeScript
Raw Normal View History

import { canonicalizeServer, pathToRoot } from "../path"
2023-06-13 05:41:42 +00:00
import { QuartzComponentConstructor, QuartzComponentProps } from "./types"
2023-07-23 00:27:41 +00:00
import { slug as slugAnchor } from "github-slugger"
2023-06-13 05:41:42 +00:00
function TagList({ fileData }: QuartzComponentProps) {
const tags = fileData.frontmatter?.tags
const slug = canonicalizeServer(fileData.slug!)
2023-07-13 07:19:35 +00:00
const baseDir = pathToRoot(slug)
2023-06-17 21:36:06 +00:00
if (tags && tags.length > 0) {
2023-07-23 00:27:41 +00:00
return (
<ul class="tags">
{tags.map((tag) => {
const display = `#${tag}`
const linkDest = baseDir + `/tags/${slugAnchor(tag)}`
return (
<li>
<a href={linkDest} class="internal">
{display}
</a>
</li>
)
})}
</ul>
)
2023-06-13 05:41:42 +00:00
} else {
return null
}
}
TagList.css = `
.tags {
list-style: none;
display: flex;
padding-left: 0;
gap: 0.4rem;
2023-07-02 20:08:29 +00:00
}
.tags > li {
display: inline-block;
white-space: nowrap;
2023-07-02 20:08:29 +00:00
margin: 0;
overflow-wrap: normal;
}
2023-06-13 05:41:42 +00:00
2023-07-02 20:08:29 +00:00
.tags > li > a {
border-radius: 8px;
background-color: var(--highlight);
padding: 0.2rem 0.5rem;
2023-06-13 05:41:42 +00:00
}
`
export default (() => TagList) satisfies QuartzComponentConstructor