Skip to content

Commit e706fe7

Browse files
committed
docs: more flexible example sorting
1 parent 57bd3ee commit e706fe7

File tree

6 files changed

+36
-7
lines changed

6 files changed

+36
-7
lines changed

src/lib/ui/ExamplesGrid.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
border: 1px solid #88888822;
3737
border-radius: 2px;
3838
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.05);
39-
padding: 1.5ex;
39+
padding: 1.5ex 1.5ex 0.4ex 1.5ex;
4040
}
4141
4242
&:hover {

src/routes/examples/+page.svelte

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
];
1616
</script>
1717

18-
<script>
18+
<script lang="ts">
1919
import { groupBy } from 'es-toolkit';
2020
import { SVELTEPRESS_CONTEXT_KEY } from '@sveltepress/theme-default/context';
2121
import { getContext } from 'svelte';
@@ -24,7 +24,14 @@
2424
2525
const pages = import.meta.glob('./**/*.svelte', {
2626
eager: true
27-
});
27+
}) as Record<
28+
string,
29+
{
30+
title: string;
31+
description?: string;
32+
sortKey?: number;
33+
}
34+
>;
2835
2936
const paths = groupBy(
3037
Object.keys(pages).filter(
@@ -66,6 +73,12 @@
6673
]?.replace('/static', '')
6774
}))
6875
);
76+
77+
function sortPages(a: string, b: string) {
78+
const sortA = pages[a].sortKey ?? 10;
79+
const sortB = pages[b].sortKey ?? 10;
80+
return sortA - sortB;
81+
}
6982
</script>
7083

7184
<p>
@@ -87,7 +100,9 @@
87100
].title}</a>
88101
</h3>
89102
<ul>
90-
{#each groupPages.filter((p) => !p.endsWith('/_index.svelte')) as page (page)}
103+
{#each groupPages
104+
.sort(sortPages)
105+
.filter((p) => !p.endsWith('/_index.svelte')) as page (page)}
91106
<li>
92107
<a
93108
href={page

src/routes/examples/[group]/+page.svelte

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<script>
1+
<script lang="ts">
22
import { page } from '$app/state';
33
44
import { SVELTEPRESS_CONTEXT_KEY } from '@sveltepress/theme-default/context';
@@ -9,7 +9,14 @@
99
1010
const pages = import.meta.glob('../**/*.svelte', {
1111
eager: true
12-
});
12+
}) as Record<
13+
string,
14+
{
15+
title: string;
16+
description?: string;
17+
sortKey?: number;
18+
}
19+
>;
1320
1421
const screenshots = import.meta.glob(
1522
'/static/examples/**/*.png',
@@ -46,6 +53,11 @@
4653
.filter(
4754
(page) => !page.endsWith('/_index.svelte')
4855
)
56+
.sort((a, b) => {
57+
const sortA = pages[a].sortKey ?? 10;
58+
const sortB = pages[b].sortKey ?? 10;
59+
return sortA - sortB;
60+
})
4961
.map((page) => ({
5062
page,
5163
title: pages[page].title,

src/routes/examples/axis/datawrapper-ticks.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<script module>
22
export const title = 'Datawrapper-style ticks';
3-
export const description = 'Foobar';
3+
export const sortKey = 99;
44
</script>
55

66
<script>

src/routes/examples/geo/us-choropleth-canvas.svelte

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
export const title = 'US choropleth map (canvas)';
33
export const description =
44
'See also the <a href="/examples/geo/us-choropleth">SVG version</a>';
5+
export const sortKey = 2;
56
</script>
67

78
<script>

src/routes/examples/geo/us-choropleth.svelte

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
export const title = 'US choropleth map';
33
export const description =
44
'See also the <a href="/examples/geo/us-choropleth-canvas">Canvas version</a>';
5+
export const sortKey = 1;
56
</script>
67

78
<script>

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy