Skip to content

Commit 0b75bd6

Browse files
SkyBird233MingcongBai
authored andcommitted
feat(crowdsourcing): add crowdsourcing details
1 parent 6da1830 commit 0b75bd6

File tree

4 files changed

+72
-18
lines changed

4 files changed

+72
-18
lines changed

src/pages/aoscc/AosccDetail.vue

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,17 @@ import { ref, defineAsyncComponent, watch } from 'vue';
66
const route = useRoute();
77
const error = ref();
88
const articleComponent = ref();
9+
const articles = import.meta.glob('./articles/*.zh.md');
910
10-
function loadArticle() {
11-
const slugWithoutHash = route.params.slug.split('#')[0];
12-
articleComponent.value = defineAsyncComponent(() =>
13-
import(`./articles/${slugWithoutHash}.zh.md`).catch((err) => {
14-
console.error('Article not found:', err);
15-
error.value = err;
16-
})
17-
);
11+
function loadArticle(slug) {
12+
const path = `./articles/${slug.split('#')[0]}.zh.md`;
13+
const loader = articles[path];
14+
if (!loader) error.value = true;
15+
articleComponent.value = defineAsyncComponent(loader);
1816
}
1917
20-
loadArticle();
21-
watch(() => route.params.slug.split('#')[0], loadArticle);
18+
loadArticle(route.params.slug);
19+
watch(() => route.params.slug.split('#')[0], loadArticle(route.params.slug));
2220
</script>
2321

2422
<template>
Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,33 @@
11
<script setup>
2+
import CategorySecond from '../../components/CategorySecond.vue';
3+
import PageNotFound from '../../components/PageNotFound.vue';
4+
import { useRoute } from 'vue-router';
5+
import { ref, defineAsyncComponent, watch } from 'vue';
26
7+
const route = useRoute();
8+
const error = ref(false);
9+
const articleComponent = ref();
10+
const articles = import.meta.glob('./articles/*.zh.md');
11+
12+
function loadArticle(slug) {
13+
const path = `./articles/${slug.split('#')[0]}.zh.md`;
14+
const loader = articles[path];
15+
if (!loader) error.value = true;
16+
articleComponent.value = defineAsyncComponent(loader);
17+
}
18+
19+
loadArticle(route.params.slug);
20+
watch(() => route.params.slug.split('#')[0], loadArticle(route.params.slug));
321
</script>
422

523
<template>
6-
<category-second title="111" />
24+
<div class="pl-[1px]">
25+
<template v-if="error">
26+
<page-not-found />
27+
</template>
28+
<template v-else>
29+
<category-second v-if="!error" title="AOSCC" />
30+
<component class="vuepress-markdown-body" :is="articleComponent" />
31+
</template>
32+
</div>
733
</template>

src/pages/crowdsourcing/CrowdsourcingIndex.vue

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,22 @@
11
<script setup>
22
import CategorySecond from '/src/components/CategorySecond.vue';
3+
import AppLink from '../../components/AppLink.vue';
4+
5+
const csArticleFrontmatters = import.meta.glob(
6+
['./articles/*.zh.md', '!./articles/template*'],
7+
// Tricky solution for importing only the titles statically.
8+
// The `query` parameter creates a unique import identifier for Vite
9+
// which prevents conflicts with dynamic imports of the same files
10+
// in AosccDetail.
11+
// The query's name doesn't matter, but it must end with `.md`
12+
// for the plugin to pick it up.
13+
{ eager: true, import: 'title', query: 'title.md' }
14+
);
15+
16+
const catalog = Object.entries(csArticleFrontmatters).map(([path, title]) => {
17+
const slug = path.split('/').pop().replace('.zh.md', '');
18+
return { slug, title };
19+
});
320
</script>
421

522
<template>
@@ -13,13 +30,6 @@ import CategorySecond from '/src/components/CategorySecond.vue';
1330
AOSCC
1431
年度聚会等场合)时经常需要资金及物质支持。因此,我们接受针对特定项目及购买计划的金钱、物品(如电脑机箱、电源及硬盘等)及服务(如网站服务器资源等)捐赠。</p
1532
><br />
16-
<p
17-
>您可以前往 Wiki 站点查阅<a
18-
class="text-link"
19-
href="https://wiki.aosc.io/community/crowdsourcing/"
20-
>众筹项目记录</a
21-
>。</p
22-
>
2333
</div>
2434

2535
<category-second title="补充条例" />
@@ -45,6 +55,17 @@ import CategorySecond from '/src/components/CategorySecond.vue';
4555
<li>如众筹项目被取消,将全额退还捐款予捐赠者。</li>
4656
</ul>
4757
</div>
58+
59+
<category-second title="众筹项目记录" />
60+
<div class="p-6">
61+
<ul class="list-disc py-6 pl-16">
62+
<li v-for="item in catalog" :key="item.slug">
63+
<app-link :to="`/crowdsourcing/${item.slug}`">{{
64+
item.title
65+
}}</app-link>
66+
</li>
67+
</ul>
68+
</div>
4869
</div>
4970
</template>
5071

src/router.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import AoscWslRequirements from './pages/aosc-os/wsl/requirements/AoscWslRequire
3838
import AoscAsahiRelnote from './pages/aosc-os/asahi/relnote/AoscAsahiRelnote.vue';
3939
import AosccIndex from './pages/aoscc/AosccIndex.vue';
4040
import AosccDetail from './pages/aoscc/AosccDetail.vue';
41+
import CrowdsourcingDetail from './pages/crowdsourcing/CrowdsourcingDetail.vue';
4142

4243
const router = createRouter({
4344
history: createWebHistory(),
@@ -271,6 +272,14 @@ const router = createRouter({
271272
title: '社区众筹'
272273
}
273274
},
275+
{
276+
path: '/crowdsourcing/:slug',
277+
name: 'crowdsourcingDetail',
278+
component: CrowdsourcingDetail,
279+
meta: {
280+
title: '社区众筹'
281+
}
282+
},
274283
{
275284
path: '/news',
276285
name: 'news',

0 commit comments

Comments
 (0)