2023-08-19 22:52:25 +00:00
|
|
|
import { pathToRoot, slugTag } from "../util/path"
|
2023-06-13 05:41:42 +00:00
|
|
|
import { QuartzComponentConstructor, QuartzComponentProps } from "./types"
|
|
|
|
|
2023-10-02 00:20:55 +00:00
|
|
|
function TagList({ fileData, displayClass }: QuartzComponentProps) {
|
2023-06-13 05:41:42 +00:00
|
|
|
const tags = fileData.frontmatter?.tags
|
2023-08-19 22:52:25 +00:00
|
|
|
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 (
|
2023-10-02 00:20:55 +00:00
|
|
|
<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;
|
2023-10-22 03:27:49 +00:00
|
|
|
display: flex;
|
2023-06-13 05:41:42 +00:00
|
|
|
padding-left: 0;
|
|
|
|
gap: 0.4rem;
|
2023-07-24 04:41:09 +00:00
|
|
|
margin: 1rem 0;
|
2023-10-22 03:27:49 +00:00
|
|
|
flex-wrap: wrap;
|
|
|
|
justify-self: end;
|
2023-07-02 20:08:29 +00:00
|
|
|
}
|
2023-10-22 04:05:46 +00:00
|
|
|
|
2023-10-22 04:12:11 +00:00
|
|
|
.section-li > .section > .tags {
|
2023-10-22 04:05:46 +00:00
|
|
|
justify-content: flex-end;
|
|
|
|
}
|
2023-07-02 20:08:29 +00:00
|
|
|
|
|
|
|
.tags > li {
|
|
|
|
display: inline-block;
|
2023-07-04 17:08:32 +00:00
|
|
|
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-10-22 03:27:49 +00:00
|
|
|
a.internal.tag-link {
|
2023-07-02 20:08:29 +00:00
|
|
|
border-radius: 8px;
|
|
|
|
background-color: var(--highlight);
|
2023-08-23 05:14:16 +00:00
|
|
|
padding: 0.2rem 0.4rem;
|
|
|
|
margin: 0 0.1rem;
|
2023-06-13 05:41:42 +00:00
|
|
|
}
|
|
|
|
`
|
|
|
|
|
|
|
|
export default (() => TagList) satisfies QuartzComponentConstructor
|