Skip to content

Commit

Permalink
fix: seperate post layout build when ssg
Browse files Browse the repository at this point in the history
  • Loading branch information
YunYouJun committed Feb 24, 2024
1 parent 4b2e10c commit efd48e3
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 18 deletions.
1 change: 1 addition & 0 deletions demo/yun/.valaxy/typed-router.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ declare module 'vue-router/auto-routes' {
'/posts/post-updated': RouteRecordInfo<'/posts/post-updated', '/posts/post-updated', Record<never, never>, Record<never, never>>,
'/posts/redirect': RouteRecordInfo<'/posts/redirect', '/posts/redirect', Record<never, never>, Record<never, never>>,
'/posts/test': RouteRecordInfo<'/posts/test', '/posts/test', Record<never, never>, Record<never, never>>,
'/posts/test/a': RouteRecordInfo<'/posts/test/a', '/posts/test/a', Record<never, never>, Record<never, never>>,
'/posts/test-images': RouteRecordInfo<'/posts/test-images', '/posts/test-images', Record<never, never>, Record<never, never>>,
'/posts/test-tags': RouteRecordInfo<'/posts/test-tags', '/posts/test-tags', Record<never, never>, Record<never, never>>,
'/tags/': RouteRecordInfo<'/tags/', '/tags', Record<never, never>, Record<never, never>>,
Expand Down
3 changes: 3 additions & 0 deletions demo/yun/pages/posts/test/a.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
title: Nested Test
---
2 changes: 1 addition & 1 deletion docs/pages/themes/write.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ pnpm create valaxy
- `default.vue`: 默认布局
- `home.vue`: 首页布局
- `layout.vue`: 文章列表布局
- `post.vue`: 文章布局(放置于 `pages/posts/` 文件夹下的文章默认为 post 布局)
- `post.vue`: 文章布局(放置于 `pages/posts/` 文件夹下的文章默认为 `post 布局)
- `tags.vue`: 标签布局
- `locales`: 主题的多语言支持
- `en.yml`: 英文语言文件
Expand Down
3 changes: 3 additions & 0 deletions packages/valaxy/client/layouts/empty.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<template>
<RouterView />
</template>
6 changes: 0 additions & 6 deletions packages/valaxy/client/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,6 @@ if (useVueRouter)

// fix chinese path
routes.forEach((i) => {
// set post layout
if (i.path === '/posts') {
if (i.meta && !i.meta.layout)
i.meta.layout = 'post'
}

i?.children?.forEach((j) => {
j.path = encodeURI(j.path)
})
Expand Down
2 changes: 2 additions & 0 deletions packages/valaxy/node/plugins/markdown/markdownToVue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ export async function createMarkdownToVueRenderFn(

debug(`[render] ${file} in ${Date.now() - start}ms.`)

// console.log(code)

const result = {
code,
pageData,
Expand Down
1 change: 1 addition & 0 deletions packages/valaxy/node/plugins/markdown/transform/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export async function createMarkdownPlugin(
code = transformMermaid(code)
// TODO: PlantUML
// code = transformPlantUml(code, config.plantUmlServer)

return code
},

Expand Down
13 changes: 7 additions & 6 deletions packages/valaxy/node/plugins/preset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,20 @@ export async function ViteValaxyPlugins(
...valaxyConfig.vue,
}),

// https://github.com/JohnCampionJr/vite-plugin-vue-layouts
Layouts({
layoutsDirs: roots.map(root => `${root}/layouts`),

...valaxyConfig.layouts,
}),
ValaxyLoader,

UnheadVite(),

// https://github.com/posva/unplugin-vue-router
createRouterPlugin(options),

// https://github.com/JohnCampionJr/vite-plugin-vue-layouts
Layouts({
layoutsDirs: roots.map(root => `${root}/layouts`),

...valaxyConfig.layouts,
}),

// https://github.com/antfu/unplugin-vue-components
Components({
extensions: ['vue', 'md'],
Expand Down
12 changes: 11 additions & 1 deletion packages/valaxy/node/plugins/vueRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,17 @@ export function createRouterPlugin(options: ResolvedValaxyOptions) {
}

// page is post
// add layout info before enter route
if (route.fullPath === '/posts') {
// avoid /posts as parent layout use 'default'
route.addToMeta({
layout: 'empty',
})
}
else if (route.fullPath.startsWith('/posts/')) {
route.addToMeta({
layout: 'post',
})
}

// find page path
const path = route.components.get('default') || ''
Expand Down
7 changes: 3 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 comment on commit efd48e3

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉 Published on https://yun.valaxy.site as production
🚀 Deployed on https://65da4a8764c4cf39c0e9bf39--valaxy.netlify.app

Please sign in to comment.