roadmap/quartz/components/TagList.tsx

45 lines
1.0 KiB
TypeScript
Raw Normal View History

import { canonicalizeServer, pathToRoot } from "../path"
2023-06-13 05:41:42 +00:00
import { QuartzComponentConstructor, QuartzComponentProps } from "./types"
import { slug as slugAnchor } from 'github-slugger'
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-06-13 05:41:42 +00:00
return <ul class="tags">{tags.map(tag => {
const display = `#${tag}`
const linkDest = baseDir + `/tags/${slugAnchor(tag)}`
return <li>
2023-07-02 20:08:29 +00:00
<a href={linkDest} class="internal">{display}</a>
2023-06-13 05:41:42 +00:00
</li>
})}</ul>
} 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