valaxy 0.9.3 → 0.10.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/client/App.vue CHANGED
@@ -1,6 +1,8 @@
1
1
  <script setup lang="ts">
2
2
  import { computed } from 'vue'
3
3
  import { useHead } from '@vueuse/head'
4
+ // @ts-expect-error virtual module
5
+ import ValaxyUserApp from '/@valaxyjs/UserAppVue'
4
6
  import { isDark } from './composables'
5
7
 
6
8
  // https://github.com/vueuse/head
@@ -10,28 +12,34 @@ import { useConfig } from './config'
10
12
 
11
13
  // <link rel="apple-touch-icon" href="/pwa-192x192.png">
12
14
  // <link rel="mask-icon" href="/safari-pinned-tab.svg" color="#00aba9">
13
- // <meta name="msapplication-TileColor" content = "#00aba9" >
14
15
 
15
16
  const config = useConfig()
17
+ const themeColor = computed(() => isDark.value ? '#00aba9' : '#ffffff')
16
18
  useHead({
17
19
  title: config.value.title,
18
20
  link: [
19
21
  {
20
22
  rel: 'icon',
21
23
  href: config.value.favicon,
22
- type: config.value.favicon.endsWith('svg') ? 'image/svg+xml' : 'image/png',
24
+ type: config.value.favicon?.endsWith('svg') ? 'image/svg+xml' : 'image/png',
23
25
  },
24
26
  ],
25
27
  meta: [
26
28
  { name: 'description', content: config.value.description },
27
29
  {
28
30
  name: 'theme-color',
29
- content: computed(() => isDark.value ? '#00aba9' : '#ffffff'),
31
+ content: themeColor,
32
+ },
33
+ {
34
+ name: 'msapplication-TileColor',
35
+ content: themeColor,
30
36
  },
31
37
  ],
32
38
  })
33
39
  </script>
34
40
 
35
41
  <template>
42
+ <ValaxyUserApp />
43
+ <ValaxyAddons />
36
44
  <router-view />
37
45
  </template>
@@ -0,0 +1,10 @@
1
+ <script lang="ts" setup>
2
+ // @ts-expect-error virtual
3
+ import addonComponents from '/@valaxyjs/addons'
4
+ </script>
5
+
6
+ <template>
7
+ <component :is="component" v-bind="props" v-for="({ component, props }, index) in addonComponents" :key="index" />
8
+ </template>
9
+
10
+ <style lang="scss" scoped></style>
@@ -60,13 +60,3 @@ useCopyCode()
60
60
  </article>
61
61
  </Transition>
62
62
  </template>
63
-
64
- <style lang="scss">
65
- .markdown-body {
66
- .end {
67
- .line {
68
- height: 1px;
69
- }
70
- }
71
- }
72
- </style>
@@ -25,7 +25,7 @@ withDefaults(defineProps<{
25
25
  right: 0;
26
26
  bottom: 0;
27
27
  left: 0;
28
- z-index: calc(var(--yun-z-sidebar) - 1);
28
+ z-index: calc(var(--va-z-overlay) - 1);
29
29
  transition: opacity 0.4s;
30
30
 
31
31
  display: none;
@@ -99,6 +99,11 @@ export function useCategory(category?: string, posts: Post[] = []): ParentCatego
99
99
  }
100
100
  })
101
101
 
102
+ categoryMap.children.forEach((child) => {
103
+ if ('posts' in child)
104
+ child.posts.sort((a, b) => (b.top || 0) - (a.top || 0))
105
+ })
106
+
102
107
  // clear uncategorized
103
108
  if (uncategorized!.total === 0)
104
109
  categoryMap.children?.delete('Uncategorized')
@@ -7,7 +7,7 @@ import { useConfig } from '../config'
7
7
 
8
8
  export function useFrontmatter() {
9
9
  const route = useRoute()
10
- const frontmatter = computed<Post>(() => route.meta.frontmatter)
10
+ const frontmatter = computed<Post>(() => route.meta.frontmatter || {})
11
11
 
12
12
  return frontmatter
13
13
  }
@@ -88,7 +88,7 @@ export function useActiveAnchor(
88
88
 
89
89
  const scrollY = window.scrollY
90
90
  const innerHeight = window.innerHeight
91
- const offsetHeight = (document.querySelector('.yun-main') as HTMLElement)!.offsetHeight
91
+ const offsetHeight = container.value.offsetHeight
92
92
  const isBottom = (scrollY + innerHeight) === offsetHeight
93
93
 
94
94
  // console.log(scrollY, innerHeight, offsetHeight)
@@ -14,7 +14,25 @@ export const usePostTitle = (post: Ref<Post>) => {
14
14
  }
15
15
 
16
16
  /**
17
- * get post list
17
+ * get all page in 'pages' folder
18
+ * @returns
19
+ */
20
+ export function usePageList() {
21
+ const router = useRouter()
22
+ return computed<Post[]>(() => {
23
+ const excludePages = ['/:..all', '/:all(.*)*', '/']
24
+ const routes = router.getRoutes()
25
+ .filter(i => i.meta.frontmatter)
26
+ .filter(i => i.path && !excludePages.includes(i.path))
27
+ .map((i) => {
28
+ return Object.assign({ path: i.path, excerpt: i.meta.excerpt }, i.meta.frontmatter)
29
+ })
30
+ return routes
31
+ })
32
+ }
33
+
34
+ /**
35
+ * get post list in 'pages/posts' folder
18
36
  * todo: use vue provide/inject to global
19
37
  * @param params
20
38
  * @returns
@@ -22,15 +40,12 @@ export const usePostTitle = (post: Ref<Post>) => {
22
40
  export function usePostList(params: {
23
41
  type?: string
24
42
  } = {}) {
25
- const router = useRouter()
26
43
  return computed(() => {
27
- const routes = router.getRoutes()
28
- .filter(i => i.path.startsWith('/posts') && i.meta.frontmatter && i.meta.frontmatter.date)
29
- .filter(i => !i.path.endsWith('.html'))
30
- .filter(i => !params.type || i.meta.frontmatter.type === params.type)
31
- .map((i) => {
32
- return Object.assign({ path: i.path, excerpt: i.meta.excerpt }, i.meta.frontmatter)
33
- })
44
+ const routes = usePageList().value
45
+ .filter(i => i.path?.startsWith('/posts'))
46
+ .filter(i => !i.path?.endsWith('.html'))
47
+ .filter(i => i.date)
48
+ .filter(i => !params.type || i.type === params.type)
34
49
 
35
50
  /**
36
51
  * 置顶
@@ -42,21 +57,6 @@ export function usePostList(params: {
42
57
  })
43
58
  }
44
59
 
45
- /**
46
- * get all page
47
- * @returns
48
- */
49
- export function usePageList() {
50
- const router = useRouter()
51
- return computed<Post[]>(() => {
52
- const routes = router.getRoutes()
53
- .map((i) => {
54
- return Object.assign({ path: i.path, excerpt: i.meta.excerpt }, i.meta.frontmatter)
55
- })
56
- return routes
57
- })
58
- }
59
-
60
60
  /**
61
61
  * get prev and next post
62
62
  * @param path
package/client/config.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  // @ts-expect-error virtual module @valaxyjs/config
2
- import valaxyConfig from '/@valaxyjs/config'
2
+ import valaxySiteConfig from '/@valaxyjs/site'
3
3
  // @ts-expect-error virtual module @valaxyjs/context
4
4
  import valaxyContext from '/@valaxyjs/context'
5
5
  import type { ComputedRef, InjectionKey } from 'vue'
@@ -8,7 +8,7 @@ import { computed, inject, readonly, shallowRef } from 'vue'
8
8
  // fix build caused by pnpm
9
9
  // This is likely not portable. A type annotation is necessary.
10
10
  // https://github.com/microsoft/TypeScript/issues/42873
11
- import type { ValaxyConfig } from 'valaxy/types'
11
+ import type { DefaultThemeConfig, SiteConfig as ValaxySiteConfig } from 'valaxy/types'
12
12
 
13
13
  /**
14
14
  * parse valaxy config
@@ -24,16 +24,16 @@ interface ValaxyContext {
24
24
  userRoot: string
25
25
  }
26
26
 
27
- export const valaxyConfigSymbol: InjectionKey<ComputedRef<ValaxyConfig>> = Symbol('valaxy:config')
28
- export const valaxyConfigRef = shallowRef<ValaxyConfig>(parse<ValaxyConfig>(valaxyConfig))
27
+ export const valaxySiteConfigSymbol: InjectionKey<ComputedRef<ValaxySiteConfig>> = Symbol('valaxy:site')
28
+ export const valaxySiteConfigRef = shallowRef<ValaxySiteConfig>(parse<ValaxySiteConfig>(valaxySiteConfig))
29
29
 
30
30
  export const valaxyContextRef = shallowRef<ValaxyContext>(parse<ValaxyContext>(valaxyContext))
31
31
 
32
32
  // hmr
33
33
  if (import.meta.hot) {
34
- // /@valaxyjs/config must be static string
35
- import.meta.hot.accept('/@valaxyjs/config', (m) => {
36
- valaxyConfigRef.value = parse<ValaxyConfig>(m.default)
34
+ // /@valaxyjs/site must be static string
35
+ import.meta.hot.accept('/@valaxyjs/site', (m) => {
36
+ valaxySiteConfigRef.value = parse<ValaxySiteConfig>(m.default)
37
37
  })
38
38
 
39
39
  // context
@@ -42,33 +42,43 @@ if (import.meta.hot) {
42
42
  })
43
43
  }
44
44
 
45
- export function initConfig() {
46
- return computed(() => valaxyConfigRef.value)
45
+ export function initSite() {
46
+ return computed(() => valaxySiteConfigRef.value)
47
47
  }
48
48
 
49
49
  export function initContext() {
50
50
  return computed(() => valaxyContextRef.value)
51
51
  }
52
52
 
53
- /*
53
+ /**
54
54
  * get valaxy config
55
55
  * @public
56
56
  * @returns
57
57
  */
58
- export function useConfig<ThemeConfig = any>() {
59
- const config = inject<ComputedRef<ValaxyConfig<ThemeConfig>>>(valaxyConfigSymbol)
58
+ export function useSite<ThemeConfig = DefaultThemeConfig>() {
59
+ const config = inject<ComputedRef<ValaxySiteConfig<ThemeConfig>>>(valaxySiteConfigSymbol)
60
60
  if (!config)
61
- throw new Error('[Valaxy] config not properly injected in app')
61
+ throw new Error('[Valaxy] site config not properly injected in app')
62
62
  return config!
63
63
  }
64
64
 
65
+ /**
66
+ * alias for useSite
67
+ * @public
68
+ * @returns
69
+ */
70
+ export function useConfig<ThemeConfig = DefaultThemeConfig>() {
71
+ return useSite<ThemeConfig>()
72
+ }
73
+
65
74
  /**
66
75
  * You can use like this: import { useThemeConfig } from 'valaxy-theme-xxx'
67
76
  * if you want to: import { useThemeConfig } from 'valaxy'
68
77
  * you need pass themeConfig by yourself
78
+ * @internal
69
79
  * @returns
70
80
  */
71
- export function useThemeConfig<T = Record<string, any>>() {
72
- const config = useConfig<T>()
81
+ export function useThemeConfig<ThemeConfig = DefaultThemeConfig>() {
82
+ const config = useSite<ThemeConfig>()
73
83
  return computed(() => config!.value.themeConfig)
74
84
  }
@@ -13,7 +13,7 @@ const { t } = useI18n()
13
13
  </slot>
14
14
  </ValaxySidebar>
15
15
 
16
- <main class="yun-main" text="center">
16
+ <main class="va-main" text="center">
17
17
  <YunCard m="4" p="10" text="yellow-600">
18
18
  <div text-4xl>
19
19
  <div i-ri-alarm-warning-line inline-block />
@@ -0,0 +1,3 @@
1
+ <template>
2
+ <Layout />
3
+ </template>
@@ -0,0 +1,34 @@
1
+ <template>
2
+ <router-view v-slot="{ Component }">
3
+ <component :is="Component">
4
+ <template #main-header>
5
+ <slot name="main-header" />
6
+ </template>
7
+
8
+ <template #main-header-after>
9
+ <slot name="main-header-after" />
10
+ </template>
11
+ <template #main>
12
+ <slot name="main" />
13
+ </template>
14
+ <template #main-content>
15
+ <slot name="main-content" />
16
+ </template>
17
+ <template #main-content-after>
18
+ <slot name="main-content-after" />
19
+ </template>
20
+ <template #main-nav-before>
21
+ <slot name="main-nav-before" />
22
+ </template>
23
+ <template #main-nav-after>
24
+ <slot name="main-nav-after" />
25
+ </template>
26
+ <template #aside-custom>
27
+ <slot name="aside-custom" />
28
+ </template>
29
+ <template #footer>
30
+ <slot name="footer" />
31
+ </template>
32
+ </component>
33
+ </router-view>
34
+ </template>
@@ -0,0 +1,3 @@
1
+ <template>
2
+ <Layout />
3
+ </template>
@@ -12,7 +12,7 @@ import { useStorage } from '@vueuse/core'
12
12
 
13
13
  import type { Router } from 'vue-router'
14
14
  import type { PageDataPayload } from '../../types'
15
- import { initConfig, valaxyConfigSymbol } from '../config'
15
+ import { initSite, valaxySiteConfigSymbol } from '../config'
16
16
  import { ensureSuffix } from '@antfu/utils'
17
17
 
18
18
  import type { UserModule } from 'valaxy/client/types'
@@ -45,8 +45,8 @@ function shouldHotReload(payload: PageDataPayload): boolean {
45
45
 
46
46
  export const install: UserModule = ({ app, router }) => {
47
47
  // inject valaxy config before modules
48
- const config = initConfig()
49
- app.provide(valaxyConfigSymbol, config)
48
+ const config = initSite()
49
+ app.provide(valaxySiteConfigSymbol, config)
50
50
 
51
51
  const locale = useStorage('valaxy-locale', config.value.lang || 'en')
52
52
 
package/client/setups.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import type { ViteSSGContext } from 'vite-ssg'
2
2
  import type { Awaitable } from '@antfu/utils'
3
3
 
4
- type AppContext = ViteSSGContext
4
+ export type AppContext = ViteSSGContext
5
5
 
6
6
  export type AppSetup = (ctx: AppContext) => Awaitable<void>
7
7
 
@@ -36,3 +36,12 @@ a.header-anchor:hover,
36
36
  a.header-anchor:focus {
37
37
  text-decoration: none;
38
38
  }
39
+
40
+ // end line
41
+ .markdown-body {
42
+ .end {
43
+ .line {
44
+ height: 1px;
45
+ }
46
+ }
47
+ }
@@ -11,7 +11,7 @@
11
11
  left: 0;
12
12
 
13
13
  width: calc(100vw - 64px);
14
- max-width: var(--va-sidebar-width-mobile);
14
+ max-width: var(--va-sidebar-width);
15
15
 
16
16
  background-image: var(--yun-sidebar-bg-image);
17
17
  background-color: var(--yun-sidebar-bg-color);
@@ -1,8 +1,6 @@
1
1
  @use "../mixins" as *;
2
2
 
3
3
  html {
4
- scroll-behavior: smooth;
5
-
6
4
  -webkit-tap-highlight-color: transparent;
7
5
  }
8
6
 
@@ -1,49 +1,48 @@
1
1
  @use "sass:map";
2
2
 
3
3
  $breakpoints: (
4
- 'sm': 640px,
5
- 'md': 768px,
6
- 'lg': 1024px,
7
- 'xl': 1280px,
8
- '2xl': 1536px,
4
+ "sm": 640px,
5
+ "md": 768px,
6
+ "lg": 1024px,
7
+ "xl": 1280px,
8
+ "2xl": 1536px,
9
9
  );
10
10
 
11
11
  // for mobile
12
12
  @mixin mobile {
13
- @media screen and (max-width: map.get($breakpoints, 'sm')) {
13
+ @media screen and (max-width: map.get($breakpoints, "sm")) {
14
14
  @content;
15
15
  }
16
16
  }
17
17
 
18
18
  // for tablet
19
19
  @mixin tablet {
20
- @media screen and (min-width: map.get($breakpoints, 'sm')) and (max-width: map.get($breakpoints, 'lg')) {
20
+ @media screen and (min-width: map.get($breakpoints, "sm")) and (max-width: map.get($breakpoints, "lg")) {
21
21
  @content;
22
22
  }
23
23
  }
24
24
 
25
25
  // for desktop
26
26
  @mixin desktop {
27
- @media screen and (min-width: map.get($breakpoints, 'lg')) {
27
+ @media screen and (min-width: map.get($breakpoints, "lg")) {
28
28
  @content;
29
29
  }
30
30
  }
31
31
 
32
-
33
32
  @mixin sm-md {
34
- @media screen and (min-width: map.get($breakpoints, 'sm')) and (max-width: map.get($breakpoints, 'md')) {
33
+ @media screen and (min-width: map.get($breakpoints, "sm")) and (max-width: map.get($breakpoints, "md")) {
35
34
  @content;
36
35
  }
37
36
  }
38
37
 
39
38
  @mixin md-lg {
40
- @media screen and (min-width: map.get($breakpoints, 'md')) and (max-width: map.get($breakpoints, 'lg')) {
39
+ @media screen and (min-width: map.get($breakpoints, "md")) and (max-width: map.get($breakpoints, "lg")) {
41
40
  @content;
42
41
  }
43
42
  }
44
43
 
45
- @mixin xl {
46
- @media screen and (min-width: map.get($breakpoints, 'xl')) {
44
+ @mixin media($size) {
45
+ @media screen and (min-width: map.get($breakpoints, $size)) {
47
46
  @content;
48
47
  }
49
48
  }
@@ -54,7 +54,7 @@ $light: map.merge(
54
54
  "c-bg-light": white,
55
55
  "c-bg-dark": #fafafa,
56
56
 
57
- "c-bg-soft": white,
57
+ "c-bg-soft": #f9f9f9,
58
58
  "c-bg-alt": #f9f9f9,
59
59
  "c-bg-mute": #f1f1f1,
60
60
 
@@ -3,7 +3,7 @@
3
3
  $common: () !default;
4
4
  $common: map.merge(
5
5
  (
6
- "sidebar-width-mobile": 320px,
6
+ "sidebar-width": 320px,
7
7
  ),
8
8
  $common
9
9
  );
@@ -4,12 +4,6 @@
4
4
  <head>
5
5
  <meta charset="UTF-8">
6
6
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
7
- <script>
8
- (function () {
9
- const locale = localStorage.getItem('valaxy-locale') || 'en'
10
- document.documentElement.setAttribute('lang', locale)
11
- })()
12
- </script>
13
7
  <!-- head -->
14
8
  </head>
15
9