valaxy 0.19.8 → 0.19.10

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.
Files changed (35) hide show
  1. package/client/components/ValaxyApp.vue +3 -0
  2. package/client/components/ValaxyFootnoteTooltip.vue +19 -0
  3. package/client/composables/collections.ts +28 -0
  4. package/client/composables/common.ts +21 -4
  5. package/client/composables/dark.ts +0 -2
  6. package/client/composables/global.ts +16 -0
  7. package/client/composables/index.ts +1 -0
  8. package/client/define/collection.ts +27 -0
  9. package/client/define/index.ts +1 -0
  10. package/client/index.ts +3 -0
  11. package/client/modules/floating-vue.ts +10 -0
  12. package/client/modules/valaxy.ts +8 -7
  13. package/client/setup/main.ts +2 -0
  14. package/client/styles/css/css-vars.css +1 -1
  15. package/client/utils/time.ts +5 -6
  16. package/dist/chunk-D4PSNC26.mjs +157 -0
  17. package/dist/chunk-QWUYDMZE.cjs +156 -0
  18. package/dist/{config-_Vh4V6Lh.d.cts → config-DBw8bnRV.d.cts} +5 -0
  19. package/dist/{config-_Vh4V6Lh.d.ts → config-DBw8bnRV.d.ts} +5 -0
  20. package/dist/node/cli/index.cjs +1 -1
  21. package/dist/node/cli/index.mjs +1 -1
  22. package/dist/node/index.cjs +1 -1
  23. package/dist/node/index.d.cts +1 -1
  24. package/dist/node/index.d.ts +1 -1
  25. package/dist/node/index.mjs +1 -1
  26. package/dist/types/index.cjs +1 -1
  27. package/dist/types/index.d.cts +2 -2
  28. package/dist/types/index.d.ts +2 -2
  29. package/dist/types/index.mjs +1 -1
  30. package/package.json +30 -28
  31. package/types/config.ts +6 -0
  32. package/dist/chunk-T3PZ57XX.mjs +0 -157
  33. package/dist/chunk-YNR6K7DA.cjs +0 -156
  34. /package/dist/{chunk-635QRI6N.cjs → chunk-DXFOPAC2.cjs} +0 -0
  35. /package/dist/{chunk-FDUDFMUS.mjs → chunk-GLTG622Q.mjs} +0 -0
@@ -17,6 +17,7 @@ import { definePerson, defineWebPage, defineWebSite, useSchemaOrg } from '@unhea
17
17
  // they will be rendered correctly in the html results with vite-ssg
18
18
  import { useSiteConfig } from '../config'
19
19
  import { useFrontmatter } from '../composables'
20
+ import { useTimezone } from '../composables/global'
20
21
  import ValaxyAddons from './ValaxyAddons.vue'
21
22
 
22
23
  // <link rel="apple-touch-icon" href="/pwa-192x192.png">
@@ -96,6 +97,8 @@ useSchemaOrg([
96
97
  }),
97
98
  defineWebPage(),
98
99
  ])
100
+
101
+ useTimezone()
99
102
  </script>
100
103
 
101
104
  <template>
@@ -0,0 +1,19 @@
1
+ <script lang="ts">
2
+ import { PopperWrapper } from 'floating-vue'
3
+
4
+ const Component = ({
5
+ ...PopperWrapper,
6
+ name: 'ValaxyFootnoteTooltip',
7
+ vPopperTheme: 'tooltip',
8
+ }) as unknown as typeof PopperWrapper
9
+
10
+ export default Component
11
+ </script>
12
+
13
+ <style scoped>
14
+ @import 'floating-vue/dist/style.css';
15
+
16
+ div .v-popper {
17
+ display: inline
18
+ }
19
+ </style>
@@ -0,0 +1,28 @@
1
+ import { ref } from 'vue'
2
+ import type { CollectionConfig } from '../define'
3
+
4
+ /**
5
+ * Composable for Collections
6
+ * /collections/:collectionId/:slug
7
+ * @example /collections/love-letters/1
8
+ */
9
+ export function useCollections() {
10
+ // TODO
11
+
12
+ const collections = ref<CollectionConfig[]>([
13
+ {
14
+ id: 'i-and-she',
15
+ name: 'I and She',
16
+ description: 'Love letters from the past',
17
+ },
18
+ {
19
+ id: 'love-and-peace',
20
+ name: '爱与和平',
21
+ description: 'Recipes for a good life',
22
+ },
23
+ ])
24
+
25
+ return {
26
+ collections,
27
+ }
28
+ }
@@ -2,14 +2,31 @@ import { useRoute } from 'vue-router'
2
2
  import { computed, inject } from 'vue'
3
3
  import { isClient } from '@vueuse/core'
4
4
 
5
- import type { PageData, Post } from 'valaxy/types'
5
+ import type { PageData, PostFrontMatter } from 'valaxy/types'
6
6
  import { useSiteConfig } from '../config'
7
7
 
8
- export function useFrontmatter() {
8
+ /**
9
+ * Get `route.meta.frontmatter` from your markdown file
10
+ * @example
11
+ * ```md
12
+ * ---
13
+ * title: Hello World
14
+ * ---
15
+ * ```
16
+ *
17
+ * ```ts
18
+ * const fm = useFrontmatter()
19
+ * console.log(fm.value.title)
20
+ *
21
+ * const fm = useFrontmatter<{ custom: string }>()
22
+ * console.log(fm.value.custom)
23
+ * ```
24
+ */
25
+ export function useFrontmatter<T extends Record<string, any> = PostFrontMatter>() {
9
26
  // inject not in app root
10
27
  const route = useRoute()
11
- const frontmatter = computed<Post>(() => {
12
- return route.meta.frontmatter || {}
28
+ const frontmatter = computed(() => {
29
+ return route.meta.frontmatter as Partial<PostFrontMatter & T> || {}
13
30
  })
14
31
  return frontmatter
15
32
  }
@@ -32,7 +32,6 @@ export function useValaxyDark(options: {
32
32
  import('valaxy/client/styles/common/view-transition.css')
33
33
 
34
34
  function toggleDarkWithTransition(event: MouseEvent, options: { duration?: number, easing?: EffectTiming['easing'] } = {}) {
35
- // @ts-expect-error startViewTransition is not defined
36
35
  if (!document.startViewTransition) {
37
36
  toggleDark()
38
37
  return
@@ -45,7 +44,6 @@ export function useValaxyDark(options: {
45
44
  Math.max(y, innerHeight - y),
46
45
  )
47
46
 
48
- // @ts-expect-error startViewTransition is not defined
49
47
  const transition = document.startViewTransition(() => {
50
48
  toggleDark()
51
49
  })
@@ -0,0 +1,16 @@
1
+ import { useSiteConfig } from 'valaxy'
2
+ import { onBeforeMount, ref } from 'vue'
3
+
4
+ export const timezone = ref<string>()
5
+
6
+ /**
7
+ * use timezone
8
+ * register global timezone for formatDate
9
+ */
10
+ export function useTimezone() {
11
+ const siteConfig = useSiteConfig()
12
+
13
+ onBeforeMount(() => {
14
+ timezone.value = siteConfig.value.timezone
15
+ })
16
+ }
@@ -2,6 +2,7 @@
2
2
  export * from './categories'
3
3
  export * from './post'
4
4
  export * from './tags'
5
+ export * from './collections'
5
6
 
6
7
  // common
7
8
  export * from './common'
@@ -0,0 +1,27 @@
1
+ export interface CollectionConfig {
2
+ /**
3
+ * auto-generated by your collection path
4
+ * @example /collections/love-letters/1 => id: 'love-letters'
5
+ */
6
+ id?: string
7
+ /**
8
+ * @en
9
+ * The name of the collection.
10
+ *
11
+ * @zh
12
+ * 合集名称
13
+ */
14
+ name?: string
15
+ cover?: string
16
+ description?: string
17
+ categories?: string[]
18
+ tags?: string[]
19
+ }
20
+
21
+ /**
22
+ * @experimental
23
+ * @description Define the collection configuration.
24
+ */
25
+ export function defineCollection(config: CollectionConfig) {
26
+ return config
27
+ }
@@ -0,0 +1 @@
1
+ export * from './collection'
package/client/index.ts CHANGED
@@ -1,6 +1,9 @@
1
1
  export * from './addons'
2
2
  export * from './config'
3
3
 
4
+ // extend define
5
+ export * from './define'
6
+
4
7
  export * from './composables'
5
8
  export * from './stores'
6
9
 
@@ -0,0 +1,10 @@
1
+ import FloatingVue from 'floating-vue'
2
+ import type { ViteSSGContext } from 'vite-ssg'
3
+
4
+ import 'floating-vue/dist/style.css'
5
+ import type { DefaultTheme, ValaxyConfig } from 'valaxy/types'
6
+ import type { ComputedRef } from 'vue'
7
+
8
+ export async function install({ app }: ViteSSGContext, config: ComputedRef<ValaxyConfig<DefaultTheme.Config>>) {
9
+ app.use(FloatingVue, config.value.siteConfig.floatingVue)
10
+ }
@@ -42,17 +42,18 @@ function shouldHotReload(payload: PageDataPayload): boolean {
42
42
  return ensureSuffix('/', encodeURI(payloadPath)) === ensureSuffix('/', encodeURI(locationPath))
43
43
  }
44
44
 
45
+ // init i18n, by valaxy config
46
+ export const i18n = createI18n({
47
+ legacy: false,
48
+ locale: '',
49
+ messages: valaxyMessages,
50
+ })
51
+
45
52
  export async function install({ app, router }: ViteSSGContext, config: ComputedRef<ValaxyConfig<DefaultTheme.Config>>) {
46
53
  const locale = useStorage('valaxy-locale', config?.value.siteConfig.lang || 'en')
54
+ i18n.global.locale.value = locale.value
47
55
 
48
- // init i18n, by valaxy config
49
- const i18n = createI18n({
50
- legacy: false,
51
- locale: locale.value,
52
- messages: valaxyMessages,
53
- })
54
56
  app.use(i18n)
55
-
56
57
  router.isReady().then(() => {
57
58
  handleHMR(router)
58
59
  })
@@ -13,6 +13,7 @@ import { install as installValaxy } from '../modules/valaxy'
13
13
  import { install as installPinia } from '../modules/pinia'
14
14
  import { install as installNprogress } from '../modules/nprogress'
15
15
  import { install as installSchema } from '../modules/schemaOrg'
16
+ import { install as installFloatingVue } from '../modules/floating-vue'
16
17
 
17
18
  export default function setupMain(ctx: ViteSSGContext, config: ComputedRef<ValaxyConfig<DefaultTheme.Config>>) {
18
19
  // @ts-expect-error inject in runtime
@@ -23,6 +24,7 @@ export default function setupMain(ctx: ViteSSGContext, config: ComputedRef<Valax
23
24
  installSchema(ctx)
24
25
  installPinia(ctx)
25
26
  installNprogress(ctx)
27
+ installFloatingVue(ctx, config)
26
28
 
27
29
  if (import.meta.env.DEV && ctx.isClient) {
28
30
  import('../modules/devtools').then(({ install: installDevtools }) => {
@@ -9,7 +9,7 @@
9
9
  }
10
10
 
11
11
  html.dark {
12
- --va-c-bg: #1b1b1f;
12
+ --va-c-bg: #1a1a1d;
13
13
  --va-c-bg-light: #202127;
14
14
  --va-c-bg-dark: #1a1a1a;
15
15
  --va-c-bg-opacity: rgba(0, 0, 0, 0.8);
@@ -1,10 +1,10 @@
1
1
  import type { ToDateOptionsWithTZ } from 'date-fns-tz'
2
2
  import { format as formatWithTZ, toZonedTime } from 'date-fns-tz'
3
3
  import { format, toDate } from 'date-fns'
4
- import { useSiteConfig } from 'valaxy'
5
- import { useI18n } from 'vue-i18n'
6
4
  import { DateTime } from 'luxon'
7
5
  import type { Post } from '../../types'
6
+ import { i18n } from '../modules/valaxy'
7
+ import { timezone as globalTimezone } from '../composables/global'
8
8
 
9
9
  const referenceDate = new Date(1986, 3 /* Apr */, 4, 10, 32, 0, 900)
10
10
 
@@ -16,10 +16,9 @@ const referenceDate = new Date(1986, 3 /* Apr */, 4, 10, 32, 0, 900)
16
16
  * @param options the object with options. See [Options]{@link https://date-fns.org/docs/Options}
17
17
  */
18
18
  export function formatDate(date: string | number | Date, formatStr = 'yyyy-MM-dd', timezone?: string, options?: ToDateOptionsWithTZ): string {
19
- const { locale } = useI18n()
20
- const siteConfig = useSiteConfig()
19
+ const locale = i18n.global.locale.value
21
20
 
22
- const mergedOptions: ToDateOptionsWithTZ = Object.assign({ locale: { code: locale.value } }, options)
21
+ const mergedOptions: ToDateOptionsWithTZ = Object.assign({ locale: { code: locale } }, options)
23
22
  const clientTimezone = Intl.DateTimeFormat().resolvedOptions().timeZone
24
23
 
25
24
  try {
@@ -27,7 +26,7 @@ export function formatDate(date: string | number | Date, formatStr = 'yyyy-MM-dd
27
26
  * Format the timezone-less date to ISO. If none is specified, use the client's timezone.
28
27
  * If the input date is already in ISO format, the timezone won't be applied.
29
28
  */
30
- date = handleTimeWithZone(date, timezone || siteConfig.value.timezone || clientTimezone).toString()
29
+ date = handleTimeWithZone(date, timezone || globalTimezone.value || clientTimezone).toString()
31
30
  // Convert to the client's timezone unless the user specifies otherwise
32
31
  const zonedDate = toZonedTime(date, options?.timeZone || clientTimezone, mergedOptions)
33
32
  // The format function will never change the underlying date