Skip to content

Commit 2e4ed95

Browse files
authored
Merge pull request #48 from ansidev/patchfix/projects-by-technology-mpa-mode
Fix: make the projects by technology filter compatible with mpa build mode
2 parents 235bead + 68cd6f1 commit 2e4ed95

File tree

4 files changed

+51
-15
lines changed

4 files changed

+51
-15
lines changed
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
home: true
3+
layout: home
4+
---
5+
6+
<script setup>
7+
import { useData } from 'vitepress'
8+
import { computed } from 'vue'
9+
import { useSlugFilter } from '../../composables'
10+
import { data as projects } from '../../loaders/project.data'
11+
12+
const { params } = useData()
13+
</script>
14+
15+
<ProjectsPage :projects="projects" :technology="params.slug" />
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import { useMarkdownFrontmatterRoute } from 'vitepress-theme-ansidev/composables'
2+
3+
// projects-by-tech/[slug].paths.js
4+
export default useMarkdownFrontmatterRoute('demo/content/projects/**/!(index).md', 'techs')

demo/content/tags/[slug].paths.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
import { useMarkdownFrontmatterRoute } from 'vitepress-theme-ansidev/composables'
22

3-
// categories/[slug].paths.js
3+
// tags/[slug].paths.js
44
export default useMarkdownFrontmatterRoute('demo/content/posts/**/!(index).md', 'tags')

src/vitepress/pages/ProjectsPage.vue

+31-14
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,44 @@
22
import type { PropType } from 'vue'
33
import { computed } from 'vue'
44
import { useI18n } from 'vue-i18n'
5-
import { useUrlSearchParams } from '@vueuse/core'
65
import type { Project } from '../../core/types'
76
import ProjectList from '../components/ProjectList.vue'
87
import { useSlug, useSlugFilter } from '../composables'
98
109
const props = defineProps({
10+
projectPage: {
11+
type: String,
12+
required: false,
13+
default: '/projects.html'
14+
},
1115
projects: {
1216
type: Object as PropType<Project[]>,
1317
required: true,
1418
default: []
19+
},
20+
technology: {
21+
type: String,
22+
required: false
1523
}
1624
})
1725
1826
const { t } = useI18n()
19-
const params = useUrlSearchParams('history')
20-
const tech = params.tech
27+
const tech = props.technology
2128
const hasTechParam = typeof tech === 'string' && tech.length > 0
22-
const byTech: (project: Project) => boolean = project => !hasTechParam || project.techs.some(useSlugFilter(tech))
29+
const byTech: (project: Project) => boolean = (project) =>
30+
!hasTechParam || project.techs.some(useSlugFilter(tech))
2331
const projectsByTech = computed(() => props.projects.filter(byTech))
2432
const technologies = computed(() => {
25-
const uniqueTechnologies = [...new Set(props.projects.flatMap(project => project.techs))]
26-
return uniqueTechnologies.map(name => ({
27-
name,
28-
slug: useSlug(name),
29-
selected: hasTechParam && useSlug(name) === tech
30-
})).sort((a, b) => b.selected === a.selected ? 0 : b.selected ? 1 : -1)
33+
const uniqueTechnologies = [
34+
...new Set(props.projects.flatMap((project) => project.techs))
35+
]
36+
return uniqueTechnologies
37+
.map((name) => ({
38+
name,
39+
slug: useSlug(name),
40+
selected: hasTechParam && useSlug(name) === tech
41+
}))
42+
.sort((a, b) => (b.selected === a.selected ? 0 : b.selected ? 1 : -1))
3143
})
3244
</script>
3345

@@ -36,12 +48,17 @@ const technologies = computed(() => {
3648
<div>
3749
<p>
3850
<span class="mr-2">Technologies</span>
39-
<a v-if="hasTechParam" href="/projects.html">Reset</a>
51+
<a v-if="hasTechParam" :href="projectPage">Reset</a>
4052
</p>
4153
<p class="flex flex-row flex-wrap">
42-
<a v-for="technology in technologies"
43-
:class="['border rounded-md m-1 p-1', technology.selected ? 'bg-primary text-white! border-primary' : '']"
44-
:href="`/projects.html?tech=${technology.slug}`">
54+
<a
55+
v-for="technology in technologies"
56+
:class="[
57+
'border rounded-md m-1 p-1',
58+
technology.selected ? 'bg-primary text-white! border-primary' : ''
59+
]"
60+
:href="`/projects-by-tech/${technology.slug}`"
61+
>
4562
{{ technology.name }}
4663
</a>
4764
</p>

0 commit comments

Comments
 (0)