refactor(ArticleMenu): 🎨 New resolve method for ArticlesMenu (#310)

pull/304/head
北雁云依 2024-04-15 18:54:46 +08:00 committed by GitHub
parent 6361395286
commit ac59d96a77
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 23 additions and 16 deletions

View File

@ -5,10 +5,21 @@ import { data } from './articlesmenu.data'
const route = useRoute() const route = useRoute()
const articles = computed(() => const articles = computed(() =>
data.menu[route.path].items.map(item => ({ data
...item, .filter((article) => {
link: item.link.replace('.md', ''), 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> </script>

View File

@ -1,14 +1,10 @@
import { sidebar } from "../../sidebar"; import { createContentLoader } from 'vitepress'
declare const data: { declare const data: { url: string, title: string }[]
menu: {
[key: string]: { base: string; items: { text: string; link: string }[] };
};
};
export { data };
export default { export { data }
load() {
return { menu: sidebar }; export default createContentLoader('**/*.md', {
}, transform: list =>
}; list.map(item => ({ url: item.url, title: item.frontmatter.title })),
})