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 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>
|
||||||
|
|
||||||
|
|
|
@ -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 })),
|
||||||
|
})
|
||||||
|
|
Loading…
Reference in New Issue