refactor(ArticleMenu): 🎨 New resolve method for ArticlesMenu (#310)
parent
6361395286
commit
ac59d96a77
|
@ -5,10 +5,21 @@ import { data } from './articlesmenu.data'
|
|||
|
||||
const route = useRoute()
|
||||
const articles = computed(() =>
|
||||
data.menu[route.path].items.map(item => ({
|
||||
...item,
|
||||
link: item.link.replace('.md', ''),
|
||||
})),
|
||||
data
|
||||
.filter((article) => {
|
||||
if (!article.url.startsWith(route.path))
|
||||
return false
|
||||
if (article.url === route.path)
|
||||
return false
|
||||
const relateUrl = article.url.replace(route.path, '')
|
||||
const slashCount = relateUrl.split('/').length - 1
|
||||
if (slashCount > 1)
|
||||
return false
|
||||
if (slashCount === 1 && !relateUrl.endsWith('/'))
|
||||
return false
|
||||
return true
|
||||
})
|
||||
.map(article => ({ link: article.url, text: article.title })),
|
||||
)
|
||||
</script>
|
||||
|
||||
|
|
|
@ -1,14 +1,10 @@
|
|||
import { sidebar } from "../../sidebar";
|
||||
import { createContentLoader } from 'vitepress'
|
||||
|
||||
declare const data: {
|
||||
menu: {
|
||||
[key: string]: { base: string; items: { text: string; link: string }[] };
|
||||
};
|
||||
};
|
||||
export { data };
|
||||
declare const data: { url: string, title: string }[]
|
||||
|
||||
export default {
|
||||
load() {
|
||||
return { menu: sidebar };
|
||||
},
|
||||
};
|
||||
export { data }
|
||||
|
||||
export default createContentLoader('**/*.md', {
|
||||
transform: list =>
|
||||
list.map(item => ({ url: item.url, title: item.frontmatter.title })),
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue