valaxy 0.17.0-beta.2 → 0.17.0-beta.4

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.
@@ -38,7 +38,7 @@ const licenseHtml = computed(() => {
38
38
  {{ t('post.copyright.link') + t('symbol.colon') }}
39
39
  </strong>
40
40
  <a :href="url" target="_blank" :title="t('post.copyright.link')">
41
- {{ url }}
41
+ {{ decodeURI(url) }}
42
42
  </a>
43
43
  </li>
44
44
  <li class="post-copyright-license">
@@ -1,6 +1,6 @@
1
1
  import type { MaybeRef } from '@vueuse/core'
2
2
  import { computed, unref } from 'vue'
3
- import type { Post } from '../..'
3
+ import type { Post } from '../../types'
4
4
  import { useSiteStore } from '../stores'
5
5
 
6
6
  export interface BaseCategory {
@@ -16,10 +16,10 @@ export interface CategoryList {
16
16
  * total posts
17
17
  */
18
18
  total: number
19
- children: (Post | CategoryList)[]
19
+ children: Map<string, Post | CategoryList>
20
20
  }
21
21
  export type Category = CategoryList
22
- export type Categories = (Post | CategoryList)[]
22
+ export type Categories = Map<string, Post | CategoryList>
23
23
 
24
24
  // todo write unit test
25
25
  export function isCategoryList(category: any): category is CategoryList {
@@ -53,12 +53,12 @@ export function useCategories(category?: MaybeRef<string>, posts: Post[] = []) {
53
53
  const categoryList: CategoryList = {
54
54
  name: 'All',
55
55
  total: posts.length,
56
- children: [
57
- { name: 'Uncategorized', total: 0, children: [] },
58
- ],
56
+ children: new Map([
57
+ ['Uncategorized', { name: 'Uncategorized', total: 0, children: new Map() }],
58
+ ]),
59
59
  }
60
60
 
61
- const uncategorized = categoryList.children.find(item => item.name === 'Uncategorized')!
61
+ const uncategorized = categoryList.children.get('Uncategorized')!
62
62
 
63
63
  posts.forEach((post: Post) => {
64
64
  if (post.categories) {
@@ -69,20 +69,21 @@ export function useCategories(category?: MaybeRef<string>, posts: Post[] = []) {
69
69
  let parentCategory: CategoryList = curCategoryList
70
70
 
71
71
  post.categories.forEach((categoryName, i) => {
72
+ // console.log(parentCategory, curCategoryList.children, 'post', categoryName)
72
73
  curCategoryList.total += 1
73
- curCategoryList = (curCategoryList.children.find(item => item.name === categoryName)) as CategoryList
74
+ curCategoryList = curCategoryList.children.get(categoryName) as CategoryList
74
75
 
75
76
  if (!curCategoryList) {
76
77
  curCategoryList = {
77
78
  name: categoryName,
78
79
  total: 0,
79
- children: [],
80
+ children: new Map(),
80
81
  }
81
- parentCategory.children.push(curCategoryList)
82
+ parentCategory.children.set(categoryName, curCategoryList)
82
83
  }
83
84
 
84
85
  if (i === len - 1) {
85
- curCategoryList.children.push(post)
86
+ curCategoryList.children.set(post.path!, post)
86
87
  curCategoryList.total += 1
87
88
  }
88
89
 
@@ -92,23 +93,25 @@ export function useCategories(category?: MaybeRef<string>, posts: Post[] = []) {
92
93
  else {
93
94
  // for string
94
95
  const categoryName = post.categories
95
- const curCategory = categoryList.children.find(item => item.name === categoryName)
96
+ const curCategory = categoryList.children.get(categoryName)
96
97
  if (curCategory) {
97
98
  curCategory.total += 1
98
- curCategory.children.push(post)
99
+ curCategory.children.set(post.path!, post)
99
100
  }
100
101
  else {
101
- categoryList.children.push({
102
+ categoryList.children.set(categoryName, {
102
103
  name: categoryName,
103
104
  total: 1,
104
- children: [post],
105
+ children: new Map([
106
+ [post.path!, post],
107
+ ]),
105
108
  })
106
109
  }
107
110
  }
108
111
  }
109
112
  else {
110
113
  uncategorized.total += 1
111
- uncategorized.children.push(post)
114
+ uncategorized.children.set(post.path!, post)
112
115
  }
113
116
  })
114
117
 
@@ -116,7 +119,7 @@ export function useCategories(category?: MaybeRef<string>, posts: Post[] = []) {
116
119
 
117
120
  // clear uncategorized
118
121
  if (uncategorized!.total === 0)
119
- categoryList.children.shift()
122
+ categoryList.children.delete('Uncategorized')
120
123
 
121
124
  if (!categories) {
122
125
  return categoryList
@@ -125,7 +128,7 @@ export function useCategories(category?: MaybeRef<string>, posts: Post[] = []) {
125
128
  let curCategoryList = categoryList
126
129
  const categoryArr = categories.split('/')
127
130
  for (const categoryName of categoryArr) {
128
- const tempCList = curCategoryList.children.find(item => item.name === categoryName)
131
+ const tempCList = curCategoryList.children.get(categoryName)
129
132
  if (tempCList && tempCList.children) {
130
133
  curCategoryList = tempCList as CategoryList
131
134
  }
@@ -147,10 +150,7 @@ export function useCategories(category?: MaybeRef<string>, posts: Post[] = []) {
147
150
  export function removeItemFromCategory(categoryList: CategoryList, categoryName: string) {
148
151
  if (isCategoryList(categoryList)) {
149
152
  const categoryArr = categoryName.split('/')
150
- // todo loop find
151
- const categoryListItemIndex = categoryList.children.findIndex(item => item.name === categoryArr[0])
152
-
153
- categoryList.children.splice(categoryListItemIndex, 1)
153
+ categoryList.children.delete(categoryArr[0])
154
154
  }
155
155
  }
156
156
 
@@ -18,9 +18,12 @@ export function usePostTitle(post: ComputedRef<Post>) {
18
18
  * get all page in 'pages' folder
19
19
  */
20
20
  export function usePageList() {
21
+ const router = useRouter()
21
22
  return computed<Post[]>(() => {
22
23
  const excludePages = ['/:..all', '/:all(.*)*', '/', '/:path(.*)']
23
- const router = useRouter()
24
+ if (!router)
25
+ return []
26
+
24
27
  const routes = router.getRoutes()
25
28
  .filter(i => i.name)
26
29
  .filter(i => i.meta)
@@ -1,5 +1,5 @@
1
1
  import { computed } from 'vue'
2
- import type { Post } from '../..'
2
+ import type { Post } from '../../types'
3
3
  import { useSiteStore } from '../stores'
4
4
 
5
5
  export type Tags = Map<string, {
package/client/config.ts CHANGED
@@ -30,6 +30,9 @@ export const valaxyConfigRef = shallowRef<ValaxyConfig>(parse<ValaxyConfig>(vala
30
30
 
31
31
  export const valaxyContextRef = shallowRef<ValaxyContext>(parse<ValaxyContext>(valaxyContext))
32
32
 
33
+ valaxyConfigRef.value = parse<ValaxyConfig>(valaxyConfig)
34
+ valaxyContextRef.value = parse<ValaxyContext>(valaxyContext)
35
+
33
36
  // hmr
34
37
  if (import.meta.hot) {
35
38
  // /@valaxyjs/config must be static string
@@ -39,8 +39,7 @@ import valaxyMessages from '/@valaxyjs/locales'
39
39
  function shouldHotReload(payload: PageDataPayload): boolean {
40
40
  const payloadPath = payload.path.replace(/(\bindex)?\.md$/, '')
41
41
  const locationPath = location.pathname.replace(/(\bindex)?\.html$/, '')
42
- // console.log(payloadPath, locationPath)
43
- return ensureSuffix('/', payloadPath) === ensureSuffix('/', locationPath)
42
+ return ensureSuffix('/', encodeURI(payloadPath)) === ensureSuffix('/', encodeURI(locationPath))
44
43
  }
45
44
 
46
45
  export async function install({ app, router }: ViteSSGContext, config: ComputedRef<ValaxyConfig<DefaultTheme.Config>>) {
@@ -62,7 +61,7 @@ export async function install({ app, router }: ViteSSGContext, config: ComputedR
62
61
  function handleHMR(router: Router): void {
63
62
  // update route.data on HMR updates of active page
64
63
  if (import.meta.hot) {
65
- import.meta.hot!.on('valaxy:pageData', (payload: PageDataPayload) => {
64
+ import.meta.hot.on('valaxy:pageData', (payload: PageDataPayload) => {
66
65
  if (shouldHotReload(payload)) {
67
66
  // console.log(payload.pageData.headers)
68
67
  Object.assign(router.currentRoute.value.meta, payload.pageData)
@@ -12,6 +12,7 @@ import type { PageDataPayload } from '../../types'
12
12
  */
13
13
  export const useSiteStore = defineStore('site', () => {
14
14
  const reload = ref(1)
15
+ // for dev hot reload
15
16
  const postList = computed(() => {
16
17
  if (reload.value)
17
18
  return usePostList().value
@@ -19,6 +20,8 @@ export const useSiteStore = defineStore('site', () => {
19
20
  return usePostList().value
20
21
  })
21
22
 
23
+ // const postList = usePostList()
24
+
22
25
  const router = useRouter()
23
26
  if (router) {
24
27
  router.isReady().then(() => {
@@ -30,19 +33,22 @@ export const useSiteStore = defineStore('site', () => {
30
33
  if (payload.path.endsWith('.md'))
31
34
  path = payload.path.slice(0, -3)
32
35
 
33
- const routeName = path.split('/').slice(1).join('-')
34
-
36
+ const routeName = path
35
37
  if (!router.hasRoute(routeName))
36
38
  return
37
39
 
38
40
  // can not use generatedRoutes, otherwise will trigger ValaxyMain refresh
39
41
  const route = router.getRoutes().find(r => r.name === routeName)!
40
42
  router.removeRoute(routeName)
41
- if (route.meta)
42
- route.meta.frontmatter = payload.pageData.frontmatter
43
+ if (route.meta) {
44
+ route.meta.frontmatter = {
45
+ ...route.meta.frontmatter,
46
+ ...payload.pageData.frontmatter,
47
+ }
48
+ }
43
49
  router.addRoute(route)
44
50
 
45
- // trigger computed reload
51
+ // trigger `computed` reload, not server
46
52
  reload.value += 1
47
53
  })
48
54
  }
@@ -2,7 +2,7 @@ import dayjs from 'dayjs'
2
2
  import utc from 'dayjs/plugin/utc'
3
3
  import timezone from 'dayjs/plugin/timezone'
4
4
 
5
- import type { Post } from '../..'
5
+ import type { Post } from '../../types'
6
6
 
7
7
  dayjs.extend(utc)
8
8
  dayjs.extend(timezone)