Skip to content

Commit ada9fb4

Browse files
CategoryList: sort categories and items alphabetically
1 parent 3eade13 commit ada9fb4

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

web/src/components/CategoryList.astro

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ interface Props {
99
}
1010
1111
const { itemsByCategory, what } = Astro.props;
12-
const categories = Object.keys(itemsByCategory);
1312
const slugify = (str: string) => str.replace(/\s+/g, '-');
1413
1514
const categoryEmojis: Record<string, string> = {
@@ -115,21 +114,27 @@ function displayCategory(category: string) {
115114
<section data-pagefind-ignore>
116115
<h5>Table of Contents</h5>
117116
<div class="mtatoc-list">
118-
{categories.map(category => (
117+
{Object.keys(itemsByCategory).sort((a, b) => a.localeCompare(b))
118+
.map(category => (
119119
<div class="mtatoc-item">
120120
<a href={`#${slugify(category)}`}>{displayCategory(category)}</a>
121121
</div>
122122
))}
123123
</div>
124124

125125

126-
{Object.entries(itemsByCategory).map(([category, items]) => (
126+
{Object.entries(itemsByCategory)
127+
.sort(([a], [b]) => a.localeCompare(b))
128+
.map(([category, items]) => (
127129
<section id={slugify(category)}>
128130
<h4>{displayTitle(category)}
129131
<a href={`#${slugify(category)}`}><Icon size="1.5rem" name="external" class="mtainfoicon"/></a>
130132
</h4>
131133
<ul>
132-
{items.map(item => (
134+
{items
135+
.slice()
136+
.sort((a, b) => a.id.localeCompare(b.id))
137+
.map(item => (
133138
<li set:html={displayItem(item)}></li>
134139
))}
135140
</ul>

0 commit comments

Comments
 (0)