quartz-research-note/quartz/components/TagList.tsx

53 lines
1.1 KiB
TypeScript
Raw Normal View History

import { pathToRoot, slugTag } from "../util/path"
2023-06-13 05:41:42 +00:00
import { QuartzComponentConstructor, QuartzComponentProps } from "./types"
function TagList({ fileData }: QuartzComponentProps) {
const tags = fileData.frontmatter?.tags
const baseDir = pathToRoot(fileData.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}`
2023-07-26 04:10:37 +00:00
const linkDest = baseDir + `/tags/${slugTag(tag)}`
2023-07-23 00:27:41 +00:00
return (
<li>
2023-07-23 21:02:57 +00:00
<a href={linkDest} class="internal tag-link">
2023-07-23 00:27:41 +00:00
{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;
margin: 1rem 0;
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-23 21:02:57 +00:00
a.tag-link {
2023-07-02 20:08:29 +00:00
border-radius: 8px;
background-color: var(--highlight);
padding: 0.2rem 0.4rem;
margin: 0 0.1rem;
2023-06-13 05:41:42 +00:00
}
`
export default (() => TagList) satisfies QuartzComponentConstructor