Skip to content

Commit 4f54b67

Browse files
SkyBird233MingcongBai
authored andcommitted
feat(crowdsourcing): sort entries by date
1 parent ce6a60a commit 4f54b67

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

src/pages/crowdsourcing/CrowdsourcingIndex.vue

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import CategorySecond from '/src/components/CategorySecond.vue';
33
import AppLink from '../../components/AppLink.vue';
44
5-
const csArticleFrontmatters = import.meta.glob(
5+
const csArticleTitles = import.meta.glob(
66
['./articles/*.zh.md', '!./articles/template*'],
77
// Tricky solution for importing only the titles statically.
88
// The `query` parameter creates a unique import identifier for Vite
@@ -13,9 +13,14 @@ const csArticleFrontmatters = import.meta.glob(
1313
{ eager: true, import: 'title', query: 'title.md' }
1414
);
1515
16-
const catalog = Object.entries(csArticleFrontmatters).map(([path, title]) => {
16+
const csArticleDates = import.meta.glob(
17+
['./articles/*.zh.md', '!./articles/template*'],
18+
{ eager: true, import: 'date', query: 'date.md' }
19+
);
20+
21+
const catalog = Object.entries(csArticleTitles).map(([path, title]) => {
1722
const slug = path.split('/').pop().replace('.zh.md', '');
18-
return { slug, title };
23+
return { slug, title, date: csArticleDates[path] };
1924
});
2025
</script>
2126

@@ -55,11 +60,17 @@ const catalog = Object.entries(csArticleFrontmatters).map(([path, title]) => {
5560
</ul>
5661

5762
<category-second title="众筹项目记录" />
58-
<ul class="list-disc py-6 pl-16">
59-
<li v-for="item in catalog" :key="item.slug">
60-
<app-link :to="`/crowdsourcing/${item.slug}`">{{
61-
item.title
62-
}}</app-link>
63+
<ul class="list-disc px-16 py-6">
64+
<li
65+
v-for="item in catalog.toSorted(
66+
(a, b) => Date.parse(a.date) - Date.parse(b.date)
67+
)"
68+
:key="item.slug"
69+
class="flex justify-between">
70+
<app-link :to="`/crowdsourcing/${item.slug}`">
71+
{{ item.title }}
72+
</app-link>
73+
<span>[{{ item.date.split('T')[0] }}]</span>
6374
</li>
6475
</ul>
6576
</div>

0 commit comments

Comments
 (0)