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

59 lines
1.2 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, displayClass }: QuartzComponentProps) {
2023-06-13 05:41:42 +00:00
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 ${displayClass ?? ""}`}>
2023-07-23 00:27:41 +00:00
{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;
2023-06-13 05:41:42 +00:00
padding-left: 0;
gap: 0.4rem;
margin: 1rem 0;
flex-wrap: wrap;
justify-self: end;
2023-07-02 20:08:29 +00:00
}
.section-li > .section > .tags {
justify-content: flex-end;
}
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
a.internal.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