valaxy 0.19.2 → 0.19.3

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,101 +1,3 @@
1
- <script setup lang="ts">
2
- import { computed } from 'vue'
3
- import { useHead, useSeoMeta } from '@unhead/vue'
4
-
5
- // @ts-expect-error virtual module
6
- import ValaxyUserApp from '/@valaxyjs/UserAppVue'
7
-
8
- // @ts-expect-error virtual module
9
- import ValaxyThemeApp from '/@valaxyjs/ThemeAppVue'
10
- import pkg from 'valaxy/package.json'
11
- import { useI18n } from 'vue-i18n'
12
- import { definePerson, defineWebPage, defineWebSite, useSchemaOrg } from '@unhead/schema-org'
13
-
14
- // https://github.com/vueuse/head
15
- // you can use this to manipulate the document head in any components,
16
- // they will be rendered correctly in the html results with vite-ssg
17
- import { useSiteConfig } from './config'
18
- import ValaxyAddons from './components/ValaxyAddons.vue'
19
- import { useFrontmatter } from './composables'
20
-
21
- // <link rel="apple-touch-icon" href="/pwa-192x192.png">
22
- // <link rel="mask-icon" href="/safari-pinned-tab.svg" color="#00aba9">
23
-
24
- const siteConfig = useSiteConfig()
25
- // todo, allow user config
26
- const fm = useFrontmatter()
27
-
28
- const { locale } = useI18n()
29
-
30
- const title = computed(() => fm.value[`title_${locale.value}`] || fm.value.title)
31
- useHead({
32
- title,
33
- titleTemplate: computed(() => fm.value.titleTemplate || ((title: string) => title ? `${title} - ${siteConfig.value.title}` : siteConfig.value.title)),
34
- link: [
35
- {
36
- rel: 'icon',
37
- href: siteConfig.value.favicon,
38
- type: siteConfig.value.favicon?.endsWith('svg') ? 'image/svg+xml' : 'image/png',
39
- },
40
- ],
41
- meta: [
42
- { name: 'description', content: computed(() => siteConfig.value.description) },
43
- {
44
- name: 'generator',
45
- content: `Valaxy ${pkg.version}`,
46
- },
47
- ],
48
-
49
- templateParams: {
50
- schemaOrg: {
51
- host: siteConfig.value.url,
52
- },
53
- },
54
- })
55
-
56
- // seo
57
- // todo: get first image url from markdown
58
- const siteUrl = computed(() => fm.value.url || siteConfig.value.url)
59
- const description = computed(() => fm.value.excerpt || fm.value.description || siteConfig.value.description)
60
-
61
- useSeoMeta({
62
- description,
63
- ogDescription: description,
64
- ogLocale: computed(() => locale.value || fm.value.lang || siteConfig.value.lang || 'en'),
65
- ogLocaleAlternate: computed(() => siteConfig.value.languages.filter(l => l !== locale.value)),
66
- ogSiteName: computed(() => siteConfig.value.title),
67
- ogTitle: computed(() => fm.value.title || siteConfig.value.title),
68
- ogImage: computed(() => fm.value.ogImage || fm.value.cover || siteConfig.value.favicon),
69
- ogType: 'website',
70
- ogUrl: siteUrl,
71
- })
72
-
73
- // for SEO
74
- useSchemaOrg([
75
- // https://unhead.unjs.io/guide/guides/identity.html
76
- // Personal Website or Blog
77
- definePerson({
78
- name: siteConfig.value.author.name,
79
- url: siteUrl.value,
80
- image: siteConfig.value.author.avatar,
81
- sameAs: siteConfig.value.social.map(s => s.link),
82
- }),
83
- defineWebSite({
84
- name: title.value,
85
- datePublished: computed(() => fm.value.date),
86
- dateModified: computed(() => fm.value.updated),
87
- }),
88
- defineWebPage(),
89
- ])
90
- </script>
91
-
92
1
  <template>
93
- <ValaxyThemeApp />
94
- <ValaxyAddons />
95
- <ValaxyUserApp />
96
- <router-view v-slot="{ Component, route }">
97
- <transition name="app-transition">
98
- <component :is="Component" :key="route" />
99
- </transition>
100
- </router-view>
2
+ <ValaxyApp />
101
3
  </template>
@@ -0,0 +1,98 @@
1
+ <script setup lang="ts">
2
+ // TODO: add docs to override ValaxyApp
3
+ import { computed } from 'vue'
4
+ import { useHead, useSeoMeta } from '@unhead/vue'
5
+
6
+ // @ts-expect-error virtual module
7
+ import ValaxyUserApp from '/@valaxyjs/UserAppVue'
8
+ // @ts-expect-error virtual module
9
+ import ValaxyThemeApp from '/@valaxyjs/ThemeAppVue'
10
+
11
+ import pkg from 'valaxy/package.json'
12
+ import { useI18n } from 'vue-i18n'
13
+ import { definePerson, defineWebPage, defineWebSite, useSchemaOrg } from '@unhead/schema-org'
14
+
15
+ // https://github.com/vueuse/head
16
+ // you can use this to manipulate the document head in any components,
17
+ // they will be rendered correctly in the html results with vite-ssg
18
+ import { useSiteConfig } from '../config'
19
+ import { useFrontmatter } from '../composables'
20
+ import ValaxyAddons from './ValaxyAddons.vue'
21
+
22
+ // <link rel="apple-touch-icon" href="/pwa-192x192.png">
23
+ // <link rel="mask-icon" href="/safari-pinned-tab.svg" color="#00aba9">
24
+
25
+ const siteConfig = useSiteConfig()
26
+ // todo, allow user config
27
+ const fm = useFrontmatter()
28
+
29
+ const { locale } = useI18n()
30
+
31
+ const title = computed(() => fm.value[`title_${locale.value}`] || fm.value.title)
32
+ useHead({
33
+ title,
34
+ titleTemplate: computed(() => fm.value.titleTemplate || ((title: string) => title ? `${title} - ${siteConfig.value.title}` : siteConfig.value.title)),
35
+ link: [
36
+ {
37
+ rel: 'icon',
38
+ href: siteConfig.value.favicon,
39
+ type: siteConfig.value.favicon?.endsWith('svg') ? 'image/svg+xml' : 'image/png',
40
+ },
41
+ ],
42
+ meta: [
43
+ { name: 'description', content: computed(() => siteConfig.value.description) },
44
+ {
45
+ name: 'generator',
46
+ content: `Valaxy ${pkg.version}`,
47
+ },
48
+ ],
49
+
50
+ templateParams: {
51
+ schemaOrg: {
52
+ host: siteConfig.value.url,
53
+ },
54
+ },
55
+ })
56
+
57
+ // seo
58
+ // todo: get first image url from markdown
59
+ const siteUrl = computed(() => fm.value.url || siteConfig.value.url)
60
+ const description = computed(() => fm.value.excerpt || fm.value.description || siteConfig.value.description)
61
+
62
+ useSeoMeta({
63
+ description,
64
+ ogDescription: description,
65
+ ogLocale: computed(() => locale.value || fm.value.lang || siteConfig.value.lang || 'en'),
66
+ ogLocaleAlternate: computed(() => siteConfig.value.languages.filter(l => l !== locale.value)),
67
+ ogSiteName: computed(() => siteConfig.value.title),
68
+ ogTitle: computed(() => fm.value.title || siteConfig.value.title),
69
+ ogImage: computed(() => fm.value.ogImage || fm.value.cover || siteConfig.value.favicon),
70
+ ogType: 'website',
71
+ ogUrl: siteUrl,
72
+ })
73
+
74
+ // for SEO
75
+ useSchemaOrg([
76
+ // https://unhead.unjs.io/guide/guides/identity.html
77
+ // Personal Website or Blog
78
+ definePerson({
79
+ name: siteConfig.value.author.name,
80
+ url: siteUrl.value,
81
+ image: siteConfig.value.author.avatar,
82
+ sameAs: siteConfig.value.social.map(s => s.link),
83
+ }),
84
+ defineWebSite({
85
+ name: title.value,
86
+ datePublished: computed(() => fm.value.date),
87
+ dateModified: computed(() => fm.value.updated),
88
+ }),
89
+ defineWebPage(),
90
+ ])
91
+ </script>
92
+
93
+ <template>
94
+ <ValaxyThemeApp />
95
+ <ValaxyAddons />
96
+ <ValaxyUserApp />
97
+ <router-view />
98
+ </template>
@@ -1,74 +1,10 @@
1
1
  import { computed, shallowRef } from 'vue'
2
- import type { DefaultTheme, Header } from 'valaxy/types'
2
+ import type { DefaultTheme } from 'valaxy/types'
3
+ import type { MenuItem } from '@valaxyjs/utils'
4
+ import { getHeaders } from '@valaxyjs/utils'
3
5
  import { onContentUpdated } from '../../utils'
4
6
  import { useFrontmatter, useThemeConfig } from '../..'
5
7
 
6
- /**
7
- * @en
8
- * Menu item, the title menu parsed from the article.
9
- *
10
- * @zh
11
- * 菜单项,从文章中解析出的标题菜单。
12
- */
13
- export type MenuItem = Omit<Header, 'slug' | 'children'> & {
14
- children?: MenuItem[]
15
- }
16
-
17
- export function resolveHeaders(
18
- headers: MenuItem[],
19
- levelsRange: Exclude<DefaultTheme.Config['outline'], false> = [2, 4],
20
- ) {
21
- const levels: [number, number]
22
- = typeof levelsRange === 'number'
23
- ? [levelsRange, levelsRange]
24
- : levelsRange === 'deep'
25
- ? [2, 6]
26
- : levelsRange
27
-
28
- return groupHeaders(headers, levels)
29
- }
30
-
31
- function groupHeaders(headers: MenuItem[], levelsRange: [number, number]) {
32
- const result: MenuItem[] = []
33
-
34
- headers = headers.map(h => ({ ...h }))
35
- headers.forEach((h, index) => {
36
- if (h.level >= levelsRange[0] && h.level <= levelsRange[1]) {
37
- if (addToParent(index, headers, levelsRange))
38
- result.push(h)
39
- }
40
- })
41
-
42
- return result
43
- }
44
-
45
- function addToParent(
46
- currIndex: number,
47
- headers: MenuItem[],
48
- levelsRange: [number, number],
49
- ) {
50
- if (currIndex === 0)
51
- return true
52
-
53
- const currentHeader = headers[currIndex]
54
- for (let index = currIndex - 1; index >= 0; index--) {
55
- const header = headers[index]
56
-
57
- if (
58
- header.level < currentHeader.level
59
- && header.level >= levelsRange[0]
60
- && header.level <= levelsRange[1]
61
- ) {
62
- if (header.children == null)
63
- header.children = []
64
- header.children.push(currentHeader)
65
- return false
66
- }
67
- }
68
-
69
- return true
70
- }
71
-
72
8
  /**
73
9
  * export headers & handleClick to generate outline
74
10
  */
@@ -83,7 +19,11 @@ export function useOutline() {
83
19
  onContentUpdated(() => {
84
20
  if (pageOutline.value === false)
85
21
  return
86
- headers.value = getHeaders(pageOutline.value)
22
+ headers.value = getHeaders({
23
+ range: pageOutline.value,
24
+ selector: '.markdown-body',
25
+ filter: el => !!el.id && el.hasChildNodes(),
26
+ })
87
27
  })
88
28
 
89
29
  const handleClick = ({ target: el }: Event) => {
@@ -107,46 +47,3 @@ export function useOutline() {
107
47
  handleClick,
108
48
  }
109
49
  }
110
-
111
- /**
112
- * get headers from document directly
113
- */
114
- export function getHeaders(range: Exclude<DefaultTheme.Config['outline'], false>) {
115
- // when transition, the markdown-body will be two
116
- // the first is the old one, the last is the new one
117
- const markdownBodyElements = document.querySelectorAll('.markdown-body') as NodeListOf<HTMLElement>
118
- const markdownBody = markdownBodyElements[markdownBodyElements.length - 1]
119
- const headers = Array.from(markdownBody.querySelectorAll('.markdown-body :where(h1,h2,h3,h4,h5,h6)'))
120
- .filter(el => el.id && el.hasChildNodes())
121
- .map((el) => {
122
- const level = Number(el.tagName[1])
123
- return {
124
- title: serializeHeader(el),
125
- link: `#${el.id}`,
126
- level,
127
- // @ts-expect-error lang
128
- lang: el.lang,
129
- }
130
- })
131
-
132
- return resolveHeaders(headers, range)
133
- }
134
-
135
- function serializeHeader(h: Element): string {
136
- let ret = ''
137
- for (const node of Array.from(h.childNodes)) {
138
- if (node.nodeType === 1) {
139
- if (
140
- (node as Element).classList.contains('VABadge')
141
- || (node as Element).classList.contains('header-anchor')
142
- )
143
- continue
144
-
145
- ret += node.textContent
146
- }
147
- else if (node.nodeType === 3) {
148
- ret += node.textContent
149
- }
150
- }
151
- return ret.trim()
152
- }
package/client/index.ts CHANGED
@@ -9,3 +9,6 @@ export * from './utils'
9
9
  export * from './setups'
10
10
 
11
11
  export * from './types'
12
+
13
+ // child packages
14
+ export * from '@valaxyjs/utils'
package/client/main.ts CHANGED
@@ -19,6 +19,7 @@ import { setupLayouts } from 'virtual:generated-layouts'
19
19
  import { initValaxyConfig, valaxyConfigSymbol } from 'valaxy'
20
20
  import AppLink from './components/AppLink.vue'
21
21
 
22
+ // import App from '/@valaxyjs/App.vue'
22
23
  import App from './App.vue'
23
24
 
24
25
  import setupMain from './setup/main'
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});var m=Object.create;var o=Object.defineProperty;var i=Object.getOwnPropertyDescriptor;var u=Object.getOwnPropertyNames;var d=Object.getPrototypeOf,f=Object.prototype.hasOwnProperty;var l=(e=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(e,{get:(t,n)=>(typeof require<"u"?require:t)[n]}):e)(function(e){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+e+'" is not supported')});var p=(e,t)=>()=>(e&&(t=e(e=0)),t);var R=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var a=(e,t,n,c)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of u(t))!f.call(e,r)&&r!==n&&o(e,r,{get:()=>t[r],enumerable:!(c=i(t,r))||c.enumerable});return e};var h=(e,t,n)=>(n=e!=null?m(d(e)):{},a(t||!e||!e.__esModule?o(n,"default",{value:e,enumerable:!0}):n,e));var s,I,U= exports.e =p(()=>{"use strict";s=()=>typeof document>"u"?new URL("file:"+__filename).href:document.currentScript&&document.currentScript.src||new URL("main.js",document.baseURI).href,I= exports.d =s()});exports.a = l; exports.b = R; exports.c = h; exports.d = I; exports.e = U;
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});var m=Object.create;var o=Object.defineProperty;var i=Object.getOwnPropertyDescriptor;var u=Object.getOwnPropertyNames;var d=Object.getPrototypeOf,f=Object.prototype.hasOwnProperty;var l=(e=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(e,{get:(t,n)=>(typeof require<"u"?require:t)[n]}):e)(function(e){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+e+'" is not supported')});var p=(e,t)=>()=>(e&&(t=e(e=0)),t);var R=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var a=(e,t,n,c)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of u(t))!f.call(e,r)&&r!==n&&o(e,r,{get:()=>t[r],enumerable:!(c=i(t,r))||c.enumerable});return e};var h=(e,t,n)=>(n=e!=null?m(d(e)):{},a(t||!e||!e.__esModule?o(n,"default",{value:e,enumerable:!0}):n,e));var s,I,U= exports.e =p(()=>{"use strict";s=()=>typeof document>"u"?new URL(`file:${__filename}`).href:document.currentScript&&document.currentScript.src||new URL("main.js",document.baseURI).href,I= exports.d =s()});exports.a = l; exports.b = R; exports.c = h; exports.d = I; exports.e = U;