Skip to content

Commit 3958eee

Browse files
authored
Merge pull request #1507 from oasisprotocol/lw/doccard-tags
Print document tags in DocCard
2 parents 923e422 + 9c10a01 commit 3958eee

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

docusaurus.config.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,14 @@ const config: Config = {
6363
],
6464
],
6565
markdown: {
66+
// Copy tags into sidebar props so we can print tags in DocCard
67+
parseFrontMatter: async (params) => {
68+
const frontmatter = await params.defaultParseFrontMatter(params);
69+
frontmatter.frontMatter.sidebar_custom_props ??= {}
70+
// @ts-expect-error Wrong type
71+
frontmatter.frontMatter.sidebar_custom_props.tags = frontmatter.frontMatter.tags
72+
return frontmatter
73+
},
6674
hooks: {
6775
onBrokenMarkdownLinks: process.env.NETLIFY ? 'warn' : 'throw',
6876
onBrokenMarkdownImages: process.env.NETLIFY ? 'warn' : 'throw',

src/css/custom.css

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,21 @@ table .card{
229229
max-width: 400px;
230230
}
231231

232+
.tag,
233+
a[rel="tag"] {
234+
border: 0.0625rem solid var(--ifm-color-primary);
235+
border-radius: 0.25rem;
236+
padding: 0.125rem 0.5rem;
237+
display: inline-block;
238+
background-color: transparent;
239+
font-weight: 400;
240+
font-size: 0.875rem;
241+
}
242+
243+
.tag {
244+
margin-right: 0.375rem;
245+
}
246+
232247
@media (max-width: 768px) {
233248
table .card{
234249
min-width: 182px;

src/theme/DocCard/index.tsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,13 @@ function CardLayout({
5656
icon,
5757
title,
5858
description,
59+
customProps,
5960
}: {
6061
href: string;
6162
icon: ReactNode;
6263
title: string;
6364
description?: string;
65+
customProps: {[key: string]: unknown} | undefined;
6466
}): ReactNode {
6567
return (
6668
<CardContainer href={href}>
@@ -77,6 +79,15 @@ function CardLayout({
7779
{description}
7880
</p>
7981
)}
82+
{customProps?.tags && Array.isArray(customProps.tags) ? (
83+
<div className="pill">
84+
{customProps.tags.map((tag) => (
85+
<div className="pills__item pills__item--active tag " key={tag}>
86+
{tag}
87+
</div>
88+
))}
89+
</div>
90+
) : null}
8091
</CardContainer>
8192
);
8293
}
@@ -97,6 +108,7 @@ function CardCategory({item}: {item: PropSidebarItemCategory}): ReactNode {
97108
title={item.label}
98109
// description={item.description ?? categoryItemsPlural(item.items.length)}
99110
description={item.description}
111+
customProps={item.customProps}
100112
/>
101113
);
102114
}
@@ -110,6 +122,7 @@ function CardLink({item}: {item: PropSidebarItemLink}): ReactNode {
110122
icon={icon}
111123
title={item.label}
112124
description={item.description ?? doc?.description}
125+
customProps={item.customProps}
113126
/>
114127
);
115128
}

0 commit comments

Comments
 (0)