valaxy 0.3.11 → 0.6.0

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 (150) hide show
  1. package/README.md +0 -4
  2. package/{src/client → client}/App.vue +0 -0
  3. package/{src/client/composables/search/index.ts → client/app/data.ts} +0 -0
  4. package/{src/client → client}/components/AppLink.vue +0 -0
  5. package/client/components/PostCard.vue +84 -0
  6. package/{src/client → client}/components/PostList.vue +0 -0
  7. package/{src/client → client}/components/README.md +0 -0
  8. package/{src/client → client}/components/ValaxyBg.vue +0 -0
  9. package/{src/client → client}/components/ValaxyCopyright.vue +0 -0
  10. package/{src/client → client}/components/ValaxyFooter.vue +1 -1
  11. package/{src/client → client}/components/ValaxyHamburger.vue +0 -0
  12. package/{src/client → client}/components/ValaxyMd.vue +1 -5
  13. package/{src/client → client}/components/ValaxyOverlay.vue +0 -0
  14. package/{src/client → client}/components/ValaxyPagination.vue +0 -0
  15. package/{src/client → client}/components/ValaxyRightSidebar.vue +0 -0
  16. package/{src/client → client}/components/ValaxySidebar.vue +0 -0
  17. package/{src/client → client}/components/ValaxyToc.vue +3 -3
  18. package/{src/client → client}/composables/category.ts +0 -0
  19. package/{src/client → client}/composables/comments/index.ts +0 -0
  20. package/{src/client → client}/composables/comments/twikoo.ts +0 -0
  21. package/{src/client → client}/composables/comments/waline.ts +0 -0
  22. package/{src/client → client}/composables/common.ts +0 -0
  23. package/{src/client → client}/composables/dark.ts +0 -0
  24. package/client/composables/features/index.ts +0 -0
  25. package/{src/client → client}/composables/helper.ts +0 -0
  26. package/{src/client → client}/composables/index.ts +1 -1
  27. package/{src/client → client}/composables/layout.ts +0 -0
  28. package/client/composables/outline.ts +181 -0
  29. package/{src/client → client}/composables/post.ts +0 -0
  30. package/client/composables/search/index.ts +0 -0
  31. package/{src/client → client}/composables/sidebar.ts +68 -9
  32. package/{src/client → client}/composables/tag.ts +0 -0
  33. package/{src/client → client}/composables/widgets/aplayer.ts +0 -0
  34. package/{src/client → client}/composables/widgets/backToTop.ts +0 -0
  35. package/{src/client → client}/composables/widgets/codepen.ts +0 -0
  36. package/{src/client → client}/composables/widgets/index.ts +0 -0
  37. package/client/config.ts +75 -0
  38. package/{src/client → client}/index.html +0 -0
  39. package/{src/client → client}/index.ts +0 -0
  40. package/{src/client → client}/layouts/404.vue +0 -0
  41. package/{src/client → client}/layouts/README.md +0 -0
  42. package/{src/client → client}/locales/README.md +0 -0
  43. package/{src/client → client}/locales/en.yml +1 -0
  44. package/{src/client → client}/locales/zh-CN.yml +4 -3
  45. package/{src/client → client}/main.ts +8 -1
  46. package/{src/client → client}/modules/README.md +0 -0
  47. package/{src/client → client}/modules/nprogress.ts +0 -0
  48. package/{src/client → client}/modules/pinia.ts +0 -0
  49. package/{src/client → client}/modules/valaxy.ts +34 -9
  50. package/{src/client → client}/pages/README.md +0 -0
  51. package/{src/client → client}/pages/[...all].vue +0 -0
  52. package/{src/client → client}/pages/hi/[name].vue +0 -0
  53. package/{src/client → client}/pages/index.vue +0 -0
  54. package/{src/client → client}/pages/page/[page].vue +0 -0
  55. package/{src/client → client}/shims.d.ts +7 -1
  56. package/{src/client → client}/stores/app.ts +0 -0
  57. package/{src/client → client}/stores/user.ts +0 -0
  58. package/{src/client → client}/styles/common/button.scss +0 -0
  59. package/{src/client → client}/styles/common/code.scss +0 -0
  60. package/{src/client → client}/styles/common/custom-blocks.scss +0 -0
  61. package/{src/client → client}/styles/common/hamburger.scss +0 -0
  62. package/{src/client → client}/styles/common/markdown.scss +5 -1
  63. package/client/styles/common/scrollbar.scss +28 -0
  64. package/{src/client → client}/styles/common/sidebar.scss +0 -0
  65. package/{src/client → client}/styles/common/transition.scss +0 -0
  66. package/{src/client → client}/styles/css-vars.scss +0 -0
  67. package/{src/client → client}/styles/global/helper.scss +0 -0
  68. package/{src/client → client}/styles/global/i18n.scss +0 -0
  69. package/{src/client → client}/styles/global/index.scss +0 -0
  70. package/{src/client → client}/styles/global/nprogress.scss +0 -0
  71. package/{src/client → client}/styles/global/reset.scss +0 -0
  72. package/{src/client → client}/styles/index.scss +0 -0
  73. package/{src/client → client}/styles/mixins/config.scss +0 -0
  74. package/{src/client → client}/styles/mixins/index.scss +0 -0
  75. package/{src/client → client}/styles/mixins/size.scss +0 -0
  76. package/{src/client → client}/styles/mixins/variable.scss +0 -0
  77. package/{src/client → client}/styles/palette.scss +6 -2
  78. package/client/styles/third/katex.scss +3 -0
  79. package/{src/client → client}/styles/vars.scss +0 -0
  80. package/{src/client → client}/styles/widgets/banner.scss +0 -0
  81. package/{src/client → client}/types.ts +0 -0
  82. package/{src/client → client}/utils/helper.ts +22 -0
  83. package/{src/client → client}/utils/index.ts +0 -0
  84. package/client/utils/sidebar.ts +26 -0
  85. package/{src/client → client}/utils/time.ts +0 -0
  86. package/config/index.ts +18 -0
  87. package/dist/chunk-CP3UCJ2D.js +34 -0
  88. package/dist/chunk-EAN2KU6W.mjs +1 -0
  89. package/dist/chunk-HCVZ2UUO.mjs +34 -0
  90. package/dist/chunk-U5OMNIOK.js +1 -0
  91. package/dist/{config-de04677b.d.ts → config-ad23e743.d.ts} +28 -14
  92. package/dist/index.d.ts +67 -111
  93. package/dist/index.js +1 -1
  94. package/dist/index.mjs +1 -1
  95. package/dist/node/cli.js +7 -11
  96. package/dist/node/cli.mjs +7 -11
  97. package/dist/node/index.d.ts +2 -2
  98. package/dist/node/index.js +1 -1
  99. package/dist/node/index.mjs +1 -1
  100. package/{src/index.ts → index.ts} +1 -0
  101. package/{src/node → node}/build.ts +0 -0
  102. package/{src/node → node}/cli.ts +3 -2
  103. package/node/config.ts +156 -0
  104. package/{src/node → node}/index.ts +0 -0
  105. package/{src/node → node}/markdown/check.ts +0 -0
  106. package/{src/node → node}/markdown/highlight.ts +0 -0
  107. package/{src/node → node}/markdown/index.ts +21 -13
  108. package/{src/node → node}/markdown/markdown-it/container.ts +0 -0
  109. package/{src/node → node}/markdown/markdown-it/headings.ts +0 -0
  110. package/{src/node → node}/markdown/markdown-it/highlightLines.ts +0 -0
  111. package/{src/node → node}/markdown/markdown-it/katex.ts +0 -0
  112. package/{src/node → node}/markdown/markdown-it/parseHeader.ts +0 -0
  113. package/node/markdown/markdownToVue.ts +253 -0
  114. package/{src/node → node}/markdown/slugify.ts +0 -0
  115. package/{src/node → node}/options.ts +18 -2
  116. package/{src/node → node}/plugins/extendConfig.ts +6 -3
  117. package/node/plugins/index.ts +224 -0
  118. package/{src/node → node}/plugins/preset.ts +6 -36
  119. package/{src/node → node}/plugins/unocss.ts +0 -0
  120. package/{src/node → node}/plugins/valaxy.ts +0 -0
  121. package/{src/node → node}/rss.ts +1 -1
  122. package/{src/node → node}/server.ts +6 -4
  123. package/{src/node → node}/shims.d.ts +0 -0
  124. package/{src/node → node}/utils/cli.ts +1 -1
  125. package/node/utils/getGitTimestamp.ts +13 -0
  126. package/node/utils/index.ts +59 -0
  127. package/node/utils/net.ts +20 -0
  128. package/{src/node → node}/vite.ts +5 -1
  129. package/package.json +33 -13
  130. package/shared/index.ts +1 -0
  131. package/tsup.config.ts +7 -4
  132. package/{src/types → types}/config.ts +31 -108
  133. package/types/data.ts +31 -0
  134. package/{src/types → types}/index.ts +1 -0
  135. package/{src/types → types}/posts.ts +6 -1
  136. package/dist/chunk-6LIOFBAA.mjs +0 -1
  137. package/dist/chunk-ABPVSNYI.js +0 -83
  138. package/dist/chunk-QOANGHSR.mjs +0 -83
  139. package/dist/chunk-V3BMKLEW.js +0 -1
  140. package/src/client/components/PostCard.vue +0 -68
  141. package/src/client/composables/features/index.ts +0 -1
  142. package/src/client/composables/features/katex.ts +0 -15
  143. package/src/client/composables/search/algolia.ts +0 -115
  144. package/src/client/config.ts +0 -51
  145. package/src/client/modules/pwa.ts +0 -12
  146. package/src/client/styles/common/scrollbar.scss +0 -34
  147. package/src/node/config.ts +0 -52
  148. package/src/node/plugins/index.ts +0 -120
  149. package/src/node/plugins/markdown.ts +0 -57
  150. package/src/node/utils/index.ts +0 -26
@@ -1,68 +0,0 @@
1
- <script lang="ts" setup>
2
- import { useI18n } from 'vue-i18n'
3
- import type { Post } from '../../types'
4
- import { usePostProperty } from '~/composables'
5
-
6
- const props = defineProps<{
7
- post: Post
8
- }>()
9
-
10
- const { t } = useI18n()
11
-
12
- const { icon, styles } = usePostProperty(props.post.type)
13
- </script>
14
-
15
- <template>
16
- <YunCard m="y-4 auto" class="post-card" :style="styles">
17
- <AppLink
18
- class="post-title-link"
19
- :to="post.path || ''"
20
- m="t-3"
21
- >
22
- <div class="flex justify-center items-center title text-2xl" font="serif black">
23
- <div v-if="post.type" class="inline-flex" m="r-1" :class="icon" />{{ post.title }}
24
- </div>
25
- </AppLink>
26
-
27
- <YunPostMeta :frontmatter="post" />
28
-
29
- <div v-if="post.excerpt" class="markdown-body" text="left" w="full" p="x-6 lt-sm:4" v-html="post.excerpt" />
30
- <div m="b-5" />
31
-
32
- <a
33
- v-if="post.url"
34
- :href="post.url"
35
- class="post-link-btn shadow hover:shadow-md"
36
- rounded
37
- target="_blank"
38
- m="b-4"
39
- >
40
- {{ t('post.view_link') }}
41
- </a>
42
-
43
- <div v-if="post.categories || post.tags" w="full" class="yun-card-actions flex justify-between" border="t" text="sm">
44
- <div class="inline-flex">
45
- <router-link
46
- v-if="post.categories"
47
- :to="{
48
- path: '/categories/',
49
- query: { category: Array.isArray(post.categories) ? post.categories[post.categories.length - 1] : post.categories },
50
- }"
51
- class="post-categories inline-flex justify-center items-center" m="l-2"
52
- >
53
- <div m="x-1" i-ri-folder-2-line />
54
- {{ Array.isArray(post.categories) ? post.categories.join(' > ') : post.categories }}
55
- </router-link>
56
- </div>
57
-
58
- <div class="post-tags inline-flex" m="r-2">
59
- <template v-if="post.tags">
60
- <router-link v-for="tag, i in post.tags" :key="i" :to="{ path: '/tags/', query: { tag } }" m="x-1" class="post-tag inline-flex justify-center items-center">
61
- <div m="r-1" i-ri-price-tag-3-line />
62
- {{ tag }}
63
- </router-link>
64
- </template>
65
- </div>
66
- </div>
67
- </YunCard>
68
- </template>
@@ -1 +0,0 @@
1
- export * from './katex'
@@ -1,15 +0,0 @@
1
- import { useHead } from '@vueuse/head'
2
-
3
- /**
4
- * use katex css cdn
5
- */
6
- export function useKatex() {
7
- useHead({
8
- link: [
9
- {
10
- rel: 'stylesheet',
11
- href: 'https://cdn.jsdelivr.net/npm/katex@latest/dist/katex.min.css',
12
- },
13
- ],
14
- })
15
- }
@@ -1,115 +0,0 @@
1
- import { isClient, useScriptTag } from '@vueuse/core'
2
- import { useI18n } from 'vue-i18n'
3
- import { useRoute } from 'vue-router'
4
-
5
- const algoliasearchUrl = 'https://cdn.jsdelivr.net/npm/algoliasearch@4/dist/algoliasearch-lite.umd.js'
6
- const instantsearchUrl = 'https://cdn.jsdelivr.net/npm/instantsearch.js@4/dist/instantsearch.production.min.js'
7
-
8
- export function useAlgoliaSearch(config: {
9
- appId: string
10
- apiKey: string
11
- indexName: string
12
- hits: {
13
- per_page: number
14
- }
15
- }) {
16
- if (!isClient)
17
- return
18
-
19
- const route = useRoute()
20
- const { t } = useI18n()
21
-
22
- useScriptTag(algoliasearchUrl, () => {
23
- useScriptTag(instantsearchUrl, () => {
24
- const algoliaSettings = config
25
- const { indexName, appId, apiKey } = algoliaSettings
26
-
27
- const search = window.instantsearch({
28
- indexName,
29
- searchClient: window.algoliasearch(appId, apiKey),
30
- searchFunction: (helper: { search: () => void }) => {
31
- const searchInput = document.querySelector('.search-input') as HTMLInputElement
32
- if (searchInput.value)
33
- helper.search()
34
- },
35
- })
36
-
37
- // Registering Widgets
38
- search.addWidgets([
39
- window.instantsearch.widgets.configure({
40
- hitsPerPage: algoliaSettings.hits.per_page || 8,
41
- }),
42
-
43
- window.instantsearch.widgets.searchBox({
44
- container: '.search-input-container',
45
- placeholder: t('search.placeholder'),
46
- // Hide default icons of algolia search
47
- showReset: false,
48
- showSubmit: false,
49
- showLoadingIndicator: false,
50
- cssClasses: {
51
- input: 'search-input',
52
- },
53
- }),
54
-
55
- window.instantsearch.widgets.stats({
56
- container: '#algolia-stats',
57
- templates: {
58
- text: (data: any) => {
59
- const stats = t('search.hits_time', {
60
- hits: data.nbHits,
61
- time: data.processingTimeMS,
62
- })
63
- return `<span>${stats}</span>
64
- <a href="https://www.algolia.com/" target="_blank" class="algolia-powered">
65
- <img src="https://simpleicons.org/icons/algolia.svg" alt="Algolia">
66
- </a>
67
- `
68
- },
69
- },
70
- }),
71
-
72
- window.instantsearch.widgets.hits({
73
- container: '#algolia-hits',
74
- templates: {
75
- item: (data: any) => {
76
- const link = data.permalink ? data.permalink : route.path
77
- return `<a href="${link}" class="algolia-hit-item-link">
78
- ${data._highlightResult.title.value}
79
- <small>${data._highlightResult.slug.value}</small>
80
- </a>`
81
- },
82
- empty: (data: any) => {
83
- return `<div id="algolia-hits-empty">${t('search.empty', data.query)}</div>`
84
- },
85
- },
86
- cssClasses: {
87
- item: 'algolia-hit-item',
88
- },
89
- }),
90
-
91
- window.instantsearch.widgets.pagination({
92
- container: '#algolia-pagination',
93
- scrollTo: false,
94
- showFirst: false,
95
- showLast: false,
96
- templates: {
97
- first: '<div i-ri-arrow-left-line></div>',
98
- last: '<div i-ri-arrow-right-line></div>',
99
- previous: '<div i-ri-arrow-left-s-line></div>',
100
- next: '<div i-ri-arrow-right-s-line></div>',
101
- },
102
- cssClasses: {
103
- root: 'pagination',
104
- item: 'page-number',
105
- link: 'page-number',
106
- selectedItem: 'active',
107
- disabledItem: 'disabled-item',
108
- },
109
- }),
110
- ])
111
-
112
- search.start()
113
- })
114
- })
115
- }
@@ -1,51 +0,0 @@
1
- // @ts-expect-error virtual module @valaxyjs/config
2
- import valaxyConfig from '@valaxyjs/config'
3
- import type { ComputedRef, InjectionKey } from 'vue'
4
- import { computed, inject, readonly, shallowRef } from 'vue'
5
- import type { ThemeConfig } from '../../../valaxy-theme-yun'
6
- import type { ValaxyConfig } from '../types'
7
-
8
- /**
9
- * parse valaxy config
10
- * @param data
11
- * @returns
12
- */
13
- function parse(data: string): ValaxyConfig {
14
- const parsed = JSON.parse(data)
15
- return (import.meta.env.DEV ? readonly(parsed) : parsed) as ValaxyConfig
16
- }
17
-
18
- export const valaxyConfigSymbol: InjectionKey<ComputedRef<ValaxyConfig<ThemeConfig>>> = Symbol('valaxy:config')
19
- export const valaxyConfigRef = shallowRef<ValaxyConfig>(parse(valaxyConfig))
20
-
21
- // hmr
22
- if (import.meta.hot) {
23
- // /@valaxyjs/config must be static string
24
- import.meta.hot.accept('/@valaxyjs/config', (m) => {
25
- valaxyConfigRef.value = parse(m.default)
26
- })
27
- }
28
-
29
- export function initConfig() {
30
- return computed(() => valaxyConfigRef.value)
31
- }
32
-
33
- /*
34
- * get Config
35
- * @returns
36
- */
37
- export function useConfig() {
38
- const config = inject(valaxyConfigSymbol)
39
- if (!config)
40
- throw new Error('[Valaxy] config not properly injected in qpp')
41
- return config!
42
- }
43
-
44
- /**
45
- * getThemeConfig
46
- * @returns
47
- */
48
- export function useThemeConfig() {
49
- const config = useConfig()
50
- return computed(() => config!.value.themeConfig)
51
- }
@@ -1,12 +0,0 @@
1
- import type { UserModule } from '~/types'
2
-
3
- // https://github.com/antfu/vite-plugin-pwa#automatic-reload-when-new-content-available
4
- export const install: UserModule = ({ isClient, router }) => {
5
- if (!isClient)
6
- return
7
-
8
- router.isReady().then(async () => {
9
- const { registerSW } = await import('virtual:pwa-register')
10
- registerSW({ immediate: true })
11
- })
12
- }
@@ -1,34 +0,0 @@
1
- @use '~/styles/mixins' as *;
2
-
3
- .no-scroll {
4
- position: fixed;
5
- overflow-y: scroll;
6
- width: 100%;
7
- }
8
-
9
- ::-webkit-scrollbar {
10
- width: 8px;
11
- height: 8px;
12
- }
13
-
14
- ::-webkit-scrollbar-track {
15
- border-radius: 2px;
16
- background-color: rgba(255, 255, 255, 0.1);
17
- }
18
-
19
- ::-webkit-scrollbar-thumb {
20
- border-radius: 2px;
21
- background-color: rgba(get-css-var('c', 'primary', 'rgb'), 0.3);
22
-
23
- &:window-inactive {
24
- background-color: rgba(get-css-var('c', 'primary', 'rgb'), 0.3);
25
- }
26
-
27
- &:hover {
28
- background-color: rgba(get-css-var('c', 'primary', 'rgb'), 0.7);
29
- }
30
-
31
- &:active {
32
- background-color: rgba(get-css-var('c', 'primary', 'rgb'), 0.9);
33
- }
34
- }
@@ -1,52 +0,0 @@
1
- // import { loadConfig } from 'c12'
2
- import fs from 'fs'
3
- import { loadConfig } from 'unconfig'
4
- import defu from 'defu'
5
- import type { ValaxyConfig } from '../types'
6
- import { defaultValaxyConfig } from '../types'
7
- import type { ValaxyEntryOptions } from './options'
8
-
9
- // for user config
10
- export async function resolveConfig(options: ValaxyEntryOptions = {}) {
11
- // c12 merge array twice, so i deprecated it
12
- // const { config, configFile } = await loadConfig<ValaxyConfig>({
13
- // name: 'valaxy',
14
- // defaults: defaultValaxyConfig,
15
- // })
16
-
17
- const { config: userConfig, sources } = await loadConfig<ValaxyConfig>({
18
- sources: [
19
- {
20
- files: 'valaxy.config',
21
- extensions: ['ts', 'js', 'mjs', 'cjs', 'json'],
22
- },
23
- ],
24
- merge: false,
25
- })
26
- const configFile = sources[0]
27
- const config = defu(userConfig, defaultValaxyConfig)
28
-
29
- const theme = options.theme || config.theme || 'yun'
30
-
31
- try {
32
- const { defaultThemeConfig } = await import(`valaxy-theme-${theme}`)
33
- config.themeConfig = defu(config.themeConfig, defaultThemeConfig)
34
- }
35
- catch (e) {
36
- console.error(`valaxy-theme-${theme} doesn't have default config`)
37
- }
38
-
39
- try {
40
- const pkg = fs.readFileSync(require.resolve(`valaxy-theme-${theme}/package.json`), 'utf-8')
41
- config.themeConfig.pkg = JSON.parse(pkg)
42
- }
43
- catch (e) {
44
- console.error(`valaxy-theme-${theme} doesn't have package.json`)
45
- }
46
-
47
- return {
48
- config,
49
- configFile,
50
- theme,
51
- }
52
- }
@@ -1,120 +0,0 @@
1
- import fs from 'fs'
2
-
3
- import { join } from 'path'
4
- import type { Plugin } from 'vite'
5
- // import consola from 'consola'
6
- import { resolveConfig } from '../config'
7
- import type { ResolvedValaxyOptions, ValaxyServerOptions } from '../options'
8
- import { toAtFS } from '../utils'
9
- import { VALAXY_CONFIG_ID } from './valaxy'
10
-
11
- /**
12
- * for /@valaxyjs/styles
13
- * @param roots
14
- * @returns
15
- */
16
- function generateStyles(roots: string[]) {
17
- const imports: string[] = []
18
-
19
- for (const root of roots) {
20
- const styles: string[] = []
21
-
22
- const autoloadNames = ['index', 'css-vars']
23
- autoloadNames.forEach((name) => {
24
- styles.push(join(root, 'styles', `${name}.css`))
25
- styles.push(join(root, 'styles', `${name}.scss`))
26
- })
27
-
28
- for (const style of styles) {
29
- if (fs.existsSync(style))
30
- imports.push(`import "${toAtFS(style)}"`)
31
- }
32
- }
33
- return imports.join('\n')
34
- }
35
-
36
- function generateLocales(roots: string[]) {
37
- const imports: string[] = [
38
- 'const messages = { "zh-CN": {}, en: {} }',
39
- ]
40
- const languages = ['zh-CN', 'en']
41
-
42
- roots.forEach((root, i) => {
43
- languages.forEach((lang) => {
44
- const langYml = `${root}/locales/${lang}.yml`
45
- if (fs.existsSync(langYml) && fs.readFileSync(langYml, 'utf-8')) {
46
- const varName = lang.replace('-', '') + i
47
- imports.push(`import ${varName} from "${toAtFS(langYml)}"`)
48
- imports.push(`Object.assign(messages['${lang}'], ${varName})`)
49
- }
50
- })
51
- })
52
-
53
- imports.push('export default messages')
54
- return imports.join('\n')
55
- }
56
-
57
- export function createValaxyPlugin(options: ResolvedValaxyOptions, serverOptions: ValaxyServerOptions = {}): Plugin {
58
- const valaxyPrefix = '/@valaxy'
59
-
60
- let valaxyConfig = options.config
61
-
62
- const roots = [options.clientRoot, options.themeRoot, options.userRoot]
63
-
64
- return {
65
- name: 'Valaxy',
66
-
67
- configureServer(server) {
68
- server.watcher.add([
69
- options.configFile,
70
- options.userRoot,
71
- options.themeRoot,
72
- ])
73
- },
74
-
75
- resolveId(id) {
76
- if (id.startsWith(valaxyPrefix))
77
- return id
78
- return null
79
- },
80
-
81
- load(id) {
82
- if (id === `/${VALAXY_CONFIG_ID}`)
83
- // stringify twice for \"
84
- return `export default ${JSON.stringify(JSON.stringify(valaxyConfig))}`
85
-
86
- // generate styles
87
- if (id === '/@valaxyjs/styles')
88
- return generateStyles(roots)
89
-
90
- if (id === '/@valaxyjs/locales')
91
- return generateLocales(roots)
92
-
93
- if (id.startsWith(valaxyPrefix))
94
- return ''
95
- },
96
-
97
- async handleHotUpdate(ctx) {
98
- // handle valaxy.config.ts hmr
99
- const { file, server } = ctx
100
- if (file !== options.configFile)
101
- return
102
-
103
- const { config } = await resolveConfig()
104
-
105
- serverOptions.onConfigReload?.(config, options.config)
106
- Object.assign(options.config, config)
107
-
108
- // if (config.base !== options.config.base)
109
- // consola.warn('[valaxy]: config.base has changed. Please restart the dev server.')
110
- valaxyConfig = config
111
-
112
- const moduleIds = [`/${VALAXY_CONFIG_ID}`]
113
- const moduleEntries = [
114
- ...Array.from(moduleIds).map(id => server.moduleGraph.getModuleById(id)),
115
- ].filter(<T>(item: T): item is NonNullable<T> => !!item)
116
-
117
- return moduleEntries
118
- },
119
- }
120
- }
@@ -1,57 +0,0 @@
1
- import Markdown from 'vite-plugin-md'
2
-
3
- import type { Plugin } from 'vite'
4
- import type { ResolvedValaxyOptions } from '../options'
5
-
6
- import { setupMarkdownPlugins } from '../markdown'
7
- import { checkMd } from '../markdown/check'
8
-
9
- export type ViteMdOptions = Parameters<typeof Markdown>[0]
10
-
11
- export const excerpt_separator = '<!-- more -->'
12
-
13
- // https://github.com/antfu/vite-plugin-md
14
-
15
- export function createMarkdownPlugin(options: ResolvedValaxyOptions): Plugin[] {
16
- const mdOptions = options.config.markdownIt
17
-
18
- const defaultOptions: ViteMdOptions = {
19
- wrapperComponent: 'ValaxyMd',
20
- wrapperClasses: '',
21
-
22
- headEnabled: true,
23
- frontmatter: true,
24
- excerpt: excerpt_separator,
25
-
26
- markdownItSetup(md) {
27
- if (mdOptions.config)
28
- mdOptions.config(md)
29
-
30
- setupMarkdownPlugins(md, mdOptions)
31
- },
32
-
33
- transforms: {
34
- before: (code, id) => {
35
- checkMd(code, id)
36
-
37
- code.replace('{%', '\{\%')
38
- code.replace('%}', '\%\}')
39
- return code
40
- },
41
- },
42
- }
43
-
44
- return [Markdown(Object.assign(defaultOptions, options.config.markdown)), {
45
- name: 'valaxy:md',
46
- handleHotUpdate(ctx) {
47
- const { file, server } = ctx
48
- // send headers
49
- if (file.endsWith('.md')) {
50
- server.ws.send({
51
- type: 'custom',
52
- event: 'valaxy:md-update',
53
- })
54
- }
55
- },
56
- }]
57
- }
@@ -1,26 +0,0 @@
1
- import { dirname } from 'path'
2
- import consola from 'consola'
3
-
4
- export function slash(str: string) {
5
- return str.replace(/\\/g, '/')
6
- }
7
-
8
- export function ensurePrefix(prefix: string, str: string) {
9
- if (!str.startsWith(prefix))
10
- return prefix + str
11
- return str
12
- }
13
-
14
- export function toAtFS(path: string) {
15
- return `/@fs${ensurePrefix('/', slash(path))}`
16
- }
17
-
18
- export function resolveImportPath(importName: string) {
19
- try {
20
- return dirname(require.resolve(importName))
21
- }
22
- catch { }
23
-
24
- consola.error(`Failed to resolve package ${importName}`)
25
- throw new Error(`Failed to resolve package ${importName}`)
26
- }