fix: save md refresh caused by vue-layouts pagesDir close #321 & click goDown, close #322

This commit is contained in:
YunYouJun 2024-01-20 23:20:40 +08:00
parent 1b58be3ee3
commit 9fcad8469f
7 changed files with 32 additions and 12 deletions

View File

@ -114,7 +114,7 @@ pnpm create valaxy
import { defineTheme } from 'valaxy'
export default defineTheme({
vueRouter: {
router: {
extendRoute(route) {
// want to get component absolute paths?
// const path = route.components.get('default')

View File

@ -1,7 +1,19 @@
<script lang="ts" setup>
function goDown() {
const banner = document.getElementById('yun-banner')
if (banner) {
window.scrollTo({
top: banner.clientHeight,
behavior: 'smooth',
})
}
}
</script>
<template>
<a class="go-down" aria-label="go-down" href="javascript:window.scrollTo(0, window.banner.clientHeight);">
<button class="go-down" aria-label="go-down" @click="goDown">
<div i-ri-arrow-down-s-line inline-flex />
</a>
</button>
</template>
<style lang="scss">

View File

@ -58,7 +58,7 @@ export interface ResolvedValaxyOptions<ThemeConfig = DefaultTheme.Config> {
*/
addonRoots: string[]
/**
* Theme name
* clientRoot, themeRoot, ...addonRoots, userRoot
*/
roots: string[]
theme: string

View File

@ -93,7 +93,8 @@ export async function ViteValaxyPlugins(
// https://github.com/JohnCampionJr/vite-plugin-vue-layouts
Layouts({
layoutsDirs: roots.map(root => `${root}/layouts`),
pagesDirs: roots.map(root => `${root}/pages`),
...valaxyConfig.layouts,
}),
// https://github.com/antfu/unplugin-vue-components

View File

@ -9,7 +9,7 @@ import type { Plugin, ResolvedConfig } from 'vite'
import { defu } from 'defu'
import pascalCase from 'pascalcase'
import type { DefaultTheme, PageDataPayload, Pkg, SiteConfig } from 'valaxy/types'
import { yellow } from 'kolorist'
import { dim, yellow } from 'kolorist'
import { defaultSiteConfig, mergeValaxyConfig, resolveSiteConfig, resolveUserThemeConfig } from '../config'
import type { ResolvedValaxyOptions, ValaxyServerOptions } from '../options'
import { processValaxyOptions, resolveOptions, resolveThemeValaxyConfig } from '../options'
@ -18,6 +18,7 @@ import { createMarkdownToVueRenderFn } from '../markdown/markdownToVue'
import type { ValaxyNodeConfig } from '../types'
import { checkMd } from '../markdown/check'
import { vLogger } from '../logger'
import { countPerformanceTime } from '../utils/performance'
/**
* for /@valaxyjs/styles
@ -231,6 +232,7 @@ export function createValaxyPlugin(options: ResolvedValaxyOptions, serverOptions
* @param ctx
*/
async handleHotUpdate(ctx) {
const endCount = countPerformanceTime()
const { file, server, read } = ctx
const reloadConfigAndEntries = (config: ValaxyNodeConfig) => {
@ -302,9 +304,8 @@ export function createValaxyPlugin(options: ResolvedValaxyOptions, serverOptions
// overwrite src so vue plugin can handle the HMR
ctx.read = () => vueSrc
vLogger.success(`${yellow('[HMR]')} ${path}`)
return []
vLogger.success(`${yellow('[HMR]')} ${path} ${dim(`updated in ${endCount()}`)}`)
}
},
}

View File

@ -42,7 +42,7 @@ export function createRouterPlugin(options: ResolvedValaxyOptions) {
routesFolder: roots.map(root => `${root}/pages`),
dts: `${options.clientRoot}/typed-router.d.ts`,
...valaxyConfig.vueRouter,
...valaxyConfig.router,
/**
* @experimental See https://github.com/posva/unplugin-vue-router/issues/43
@ -155,7 +155,7 @@ export function createRouterPlugin(options: ResolvedValaxyOptions) {
valaxyConfig.extendMd?.(ctx)
}
return valaxyConfig.vueRouter?.extendRoute?.(route)
return valaxyConfig.router?.extendRoute?.(route)
},
})
}

View File

@ -1,7 +1,10 @@
import type Vue from '@vitejs/plugin-vue'
import type Components from 'unplugin-vue-components/vite'
import type Layouts from 'vite-plugin-vue-layouts'
import type Router from 'unplugin-vue-router/vite'
import type { VitePluginConfig as UnoCSSConfig } from 'unocss/vite'
import type VueRouter from 'unplugin-vue-router/vite'
import type { EditableTreeNode } from 'unplugin-vue-router'
import type { UserConfig as ViteUserConfig } from 'vite'
import type { presetAttributify, presetIcons, presetTypography, presetUno } from 'unocss'
@ -66,7 +69,11 @@ export interface ValaxyExtendConfig {
vite?: ViteUserConfig
vue?: Parameters<typeof Vue>[0]
// unplugin
components?: Parameters<typeof Components>[0]
layouts?: Parameters<typeof Layouts>[0]
router?: Parameters<typeof Router>[0]
unocss?: UnoCSSConfig
/**
* unocss presets
@ -77,7 +84,6 @@ export interface ValaxyExtendConfig {
icons?: Parameters<typeof presetIcons>[0]
typography?: Parameters<typeof presetTypography>[0]
}
vueRouter?: Parameters<typeof VueRouter>[0]
/**
* @experimental
* Enable Vue Devtools & Valaxy Devtools