valaxy 0.4.0 → 0.6.1
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/README.md +0 -4
- package/{src/client → client}/App.vue +0 -0
- package/{src/client/composables/search/index.ts → client/app/data.ts} +0 -0
- package/{src/client → client}/components/AppLink.vue +0 -0
- package/client/components/PostCard.vue +84 -0
- package/{src/client → client}/components/PostList.vue +0 -0
- package/{src/client → client}/components/README.md +0 -0
- package/{src/client → client}/components/ValaxyBg.vue +0 -0
- package/{src/client → client}/components/ValaxyCopyright.vue +0 -0
- package/{src/client → client}/components/ValaxyFooter.vue +1 -1
- package/{src/client → client}/components/ValaxyHamburger.vue +0 -0
- package/client/components/ValaxyMd.vue +74 -0
- package/{src/client → client}/components/ValaxyOverlay.vue +0 -0
- package/{src/client → client}/components/ValaxyPagination.vue +0 -0
- package/{src/client → client}/components/ValaxyRightSidebar.vue +0 -0
- package/{src/client → client}/components/ValaxySidebar.vue +0 -0
- package/{src/client → client}/components/ValaxyToc.vue +3 -3
- package/{src/client → client}/composables/category.ts +0 -0
- package/{src/client → client}/composables/comments/index.ts +0 -0
- package/{src/client → client}/composables/comments/twikoo.ts +0 -0
- package/{src/client → client}/composables/comments/waline.ts +0 -0
- package/{src/client → client}/composables/common.ts +0 -0
- package/client/composables/copy-code.ts +92 -0
- package/{src/client → client}/composables/dark.ts +0 -0
- package/client/composables/features/index.ts +0 -0
- package/{src/client → client}/composables/helper.ts +0 -0
- package/{src/client → client}/composables/index.ts +1 -1
- package/{src/client → client}/composables/layout.ts +0 -0
- package/client/composables/outline.ts +168 -0
- package/{src/client → client}/composables/post.ts +0 -0
- package/client/composables/search/index.ts +0 -0
- package/{src/client → client}/composables/sidebar.ts +46 -1
- package/{src/client → client}/composables/tag.ts +0 -0
- package/{src/client → client}/composables/widgets/aplayer.ts +0 -0
- package/{src/client → client}/composables/widgets/backToTop.ts +0 -0
- package/{src/client → client}/composables/widgets/codepen.ts +0 -0
- package/{src/client → client}/composables/widgets/index.ts +0 -0
- package/client/config.ts +75 -0
- package/{src/client → client}/index.html +0 -0
- package/{src/client → client}/index.ts +0 -0
- package/{src/client → client}/layouts/404.vue +0 -0
- package/{src/client → client}/layouts/README.md +0 -0
- package/{src/client → client}/locales/README.md +0 -0
- package/{src/client → client}/locales/en.yml +1 -0
- package/{src/client → client}/locales/zh-CN.yml +4 -3
- package/{src/client → client}/main.ts +4 -1
- package/{src/client → client}/modules/README.md +0 -0
- package/{src/client → client}/modules/nprogress.ts +0 -0
- package/{src/client → client}/modules/pinia.ts +0 -0
- package/{src/client → client}/modules/valaxy.ts +19 -7
- package/{src/client → client}/pages/README.md +0 -0
- package/{src/client → client}/pages/[...all].vue +0 -0
- package/{src/client → client}/pages/hi/[name].vue +0 -0
- package/{src/client → client}/pages/index.vue +0 -0
- package/{src/client → client}/pages/page/[page].vue +0 -0
- package/{src/client → client}/shims.d.ts +7 -1
- package/{src/client → client}/stores/app.ts +0 -0
- package/{src/client → client}/stores/user.ts +0 -0
- package/{src/client → client}/styles/common/button.scss +0 -0
- package/client/styles/common/code.scss +231 -0
- package/{src/client → client}/styles/common/custom-blocks.scss +0 -0
- package/{src/client → client}/styles/common/hamburger.scss +0 -0
- package/{src/client → client}/styles/common/markdown.scss +0 -2
- package/client/styles/common/scrollbar.scss +28 -0
- package/{src/client → client}/styles/common/sidebar.scss +0 -0
- package/{src/client → client}/styles/common/transition.scss +0 -0
- package/client/styles/css-vars.scss +62 -0
- package/{src/client → client}/styles/global/helper.scss +0 -0
- package/{src/client → client}/styles/global/i18n.scss +0 -0
- package/{src/client → client}/styles/global/index.scss +0 -0
- package/{src/client → client}/styles/global/nprogress.scss +0 -0
- package/{src/client → client}/styles/global/reset.scss +0 -0
- package/{src/client → client}/styles/index.scss +0 -0
- package/{src/client → client}/styles/mixins/config.scss +0 -0
- package/{src/client → client}/styles/mixins/index.scss +0 -0
- package/{src/client → client}/styles/mixins/size.scss +0 -0
- package/{src/client → client}/styles/mixins/variable.scss +0 -0
- package/{src/client → client}/styles/palette.scss +21 -2
- package/client/styles/third/katex.scss +3 -0
- package/client/styles/vars.scss +41 -0
- package/{src/client → client}/styles/widgets/banner.scss +0 -0
- package/{src/client → client}/types.ts +0 -0
- package/{src/client → client}/utils/helper.ts +22 -0
- package/{src/client → client}/utils/index.ts +0 -0
- package/client/utils/sidebar.ts +26 -0
- package/{src/client → client}/utils/time.ts +0 -0
- package/config/index.ts +18 -0
- package/dist/chunk-EAN2KU6W.mjs +1 -0
- package/dist/chunk-HMUGSKPK.mjs +40 -0
- package/dist/chunk-U5OMNIOK.js +1 -0
- package/dist/chunk-ZHHNO5RK.js +40 -0
- package/dist/{config-de04677b.d.ts → config-112ac884.d.ts} +37 -14
- package/dist/index.d.ts +65 -111
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/dist/node/cli.js +7 -11
- package/dist/node/cli.mjs +7 -11
- package/dist/node/index.d.ts +3 -2
- package/dist/node/index.js +1 -1
- package/dist/node/index.mjs +1 -1
- package/{src/index.ts → index.ts} +1 -0
- package/{src/node → node}/build.ts +0 -0
- package/{src/node → node}/cli.ts +3 -2
- package/node/config.ts +156 -0
- package/{src/node → node}/index.ts +0 -0
- package/{src/node → node}/markdown/check.ts +0 -0
- package/node/markdown/highlight.ts +38 -0
- package/{src/node → node}/markdown/index.ts +30 -16
- package/{src/node → node}/markdown/markdown-it/container.ts +0 -0
- package/{src/node → node}/markdown/markdown-it/headings.ts +0 -0
- package/{src/node → node}/markdown/markdown-it/highlightLines.ts +1 -1
- package/{src/node → node}/markdown/markdown-it/katex.ts +0 -0
- package/{src/node → node}/markdown/markdown-it/parseHeader.ts +0 -0
- package/node/markdown/markdownToVue.ts +274 -0
- package/{src/node → node}/markdown/slugify.ts +0 -0
- package/{src/node → node}/options.ts +18 -2
- package/{src/node → node}/plugins/extendConfig.ts +5 -3
- package/node/plugins/index.ts +224 -0
- package/{src/node → node}/plugins/preset.ts +8 -8
- package/{src/node → node}/plugins/unocss.ts +0 -0
- package/{src/node → node}/plugins/valaxy.ts +0 -0
- package/{src/node → node}/rss.ts +1 -1
- package/{src/node → node}/server.ts +0 -0
- package/{src/node → node}/shims.d.ts +0 -5
- package/{src/node → node}/utils/cli.ts +1 -1
- package/node/utils/getGitTimestamp.ts +13 -0
- package/node/utils/index.ts +59 -0
- package/node/utils/net.ts +20 -0
- package/{src/node → node}/vite.ts +5 -1
- package/package.json +32 -13
- package/shared/index.ts +1 -0
- package/tsup.config.ts +7 -4
- package/{src/types → types}/config.ts +31 -108
- package/types/data.ts +31 -0
- package/{src/types → types}/index.ts +1 -0
- package/{src/types → types}/posts.ts +6 -1
- package/dist/chunk-6LIOFBAA.mjs +0 -1
- package/dist/chunk-HRARZPSA.js +0 -83
- package/dist/chunk-N6HD5SHF.mjs +0 -83
- package/dist/chunk-V3BMKLEW.js +0 -1
- package/src/client/components/PostCard.vue +0 -68
- package/src/client/components/ValaxyMd.vue +0 -71
- package/src/client/composables/features/index.ts +0 -1
- package/src/client/composables/features/katex.ts +0 -15
- package/src/client/composables/search/algolia.ts +0 -115
- package/src/client/config.ts +0 -51
- package/src/client/styles/common/code.scss +0 -207
- package/src/client/styles/common/scrollbar.scss +0 -34
- package/src/client/styles/css-vars.scss +0 -39
- package/src/client/styles/vars.scss +0 -27
- package/src/node/config.ts +0 -52
- package/src/node/markdown/highlight.ts +0 -50
- package/src/node/plugins/index.ts +0 -120
- package/src/node/plugins/markdown.ts +0 -57
- package/src/node/utils/index.ts +0 -26
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { dirname, resolve } from 'path'
|
|
2
2
|
import _debug from 'debug'
|
|
3
|
+
import fg from 'fast-glob'
|
|
3
4
|
import type { ValaxyConfig } from '../types'
|
|
4
5
|
import { resolveConfig } from './config'
|
|
5
6
|
import { resolveImportPath } from './utils'
|
|
@@ -43,6 +44,7 @@ export interface ResolvedValaxyOptions {
|
|
|
43
44
|
* config file path
|
|
44
45
|
*/
|
|
45
46
|
configFile: string
|
|
47
|
+
pages: string[]
|
|
46
48
|
}
|
|
47
49
|
|
|
48
50
|
export interface ValaxyServerOptions {
|
|
@@ -66,17 +68,30 @@ export function getThemeRoot(name: string, entry: string) {
|
|
|
66
68
|
if (isPath(name))
|
|
67
69
|
return resolve(dirname(entry), name)
|
|
68
70
|
else
|
|
69
|
-
return resolveImportPath(`valaxy-theme-${name}/package.json`)
|
|
71
|
+
return dirname(resolveImportPath(`valaxy-theme-${name}/package.json`) || '')
|
|
70
72
|
}
|
|
71
73
|
|
|
72
74
|
// for cli options
|
|
73
75
|
export async function resolveOptions(options: ValaxyEntryOptions, mode: ResolvedValaxyOptions['mode'] = 'dev') {
|
|
74
|
-
const clientRoot = resolve(resolveImportPath('valaxy/package.json'), '
|
|
76
|
+
const clientRoot = resolve(dirname(resolveImportPath('valaxy/package.json', true)), 'client')
|
|
75
77
|
const userRoot = resolve(options.userRoot || process.cwd())
|
|
76
78
|
|
|
77
79
|
const { config: valaxyConfig, configFile, theme } = await resolveConfig(options)
|
|
78
80
|
const themeRoot = getThemeRoot(theme, userRoot)
|
|
79
81
|
|
|
82
|
+
// Important: fast-glob doesn't guarantee order of the returned files.
|
|
83
|
+
// We must sort the pages so the input list to rollup is stable across
|
|
84
|
+
// builds - otherwise different input order could result in different exports
|
|
85
|
+
// order in shared chunks which in turns invalidates the hash of every chunk!
|
|
86
|
+
// JavaScript built-in sort() is mandated to be stable as of ES2019 and
|
|
87
|
+
// supported in Node 12+, which is required by Vite.
|
|
88
|
+
const pages = (
|
|
89
|
+
await fg(['**.md'], {
|
|
90
|
+
cwd: userRoot,
|
|
91
|
+
ignore: ['**/node_modules'],
|
|
92
|
+
})
|
|
93
|
+
).sort()
|
|
94
|
+
|
|
80
95
|
const valaxyOptions: ResolvedValaxyOptions = {
|
|
81
96
|
mode,
|
|
82
97
|
clientRoot,
|
|
@@ -85,6 +100,7 @@ export async function resolveOptions(options: ValaxyEntryOptions, mode: Resolved
|
|
|
85
100
|
theme,
|
|
86
101
|
config: valaxyConfig,
|
|
87
102
|
configFile: configFile || '',
|
|
103
|
+
pages,
|
|
88
104
|
}
|
|
89
105
|
debug(valaxyOptions)
|
|
90
106
|
|
|
@@ -13,13 +13,14 @@ export function createConfigPlugin(options: ResolvedValaxyOptions): Plugin {
|
|
|
13
13
|
alias: {
|
|
14
14
|
'@/': `${toAtFS(options.userRoot)}/`,
|
|
15
15
|
'~/': `${toAtFS(options.clientRoot)}/`,
|
|
16
|
+
'valaxy/client': `${toAtFS(options.clientRoot)}/`,
|
|
17
|
+
'valaxy': toAtFS(resolve(options.clientRoot, 'index.ts')),
|
|
16
18
|
'@valaxyjs/client': `${toAtFS(options.clientRoot)}/`,
|
|
17
19
|
'@valaxyjs/config': '/@valaxyjs/config',
|
|
20
|
+
'@valaxyjs/context': '/@valaxyjs/context',
|
|
18
21
|
'valaxy/package.json': toAtFS(resolve(options.clientRoot, '../../package.json')),
|
|
19
|
-
'valaxy/': `${toAtFS(resolve(options.clientRoot, '../..'))}/`,
|
|
20
|
-
'valaxy': toAtFS(resolve(options.clientRoot, '../index.ts')),
|
|
21
22
|
[`valaxy-theme-${options.theme}/`]: `${toAtFS(resolve(options.themeRoot))}/`,
|
|
22
|
-
[`valaxy-theme-${options.theme}`]: `${toAtFS(resolve(options.themeRoot))}`,
|
|
23
|
+
[`valaxy-theme-${options.theme}`]: `${toAtFS(resolve(options.themeRoot))}/index.ts`,
|
|
23
24
|
},
|
|
24
25
|
},
|
|
25
26
|
|
|
@@ -36,6 +37,7 @@ export function createConfigPlugin(options: ResolvedValaxyOptions): Plugin {
|
|
|
36
37
|
'nprogress',
|
|
37
38
|
],
|
|
38
39
|
|
|
40
|
+
exclude: ['@docsearch/js'],
|
|
39
41
|
},
|
|
40
42
|
}
|
|
41
43
|
return mergeConfig(config, injection)
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
import fs from 'fs'
|
|
2
|
+
|
|
3
|
+
import { join, relative } from 'path'
|
|
4
|
+
import type { Plugin, ResolvedConfig } from 'vite'
|
|
5
|
+
// import consola from 'consola'
|
|
6
|
+
import { resolveConfig } from '../config'
|
|
7
|
+
import type { ResolvedValaxyOptions, ValaxyServerOptions } from '../options'
|
|
8
|
+
import { resolveImportPath, slash, toAtFS } from '../utils'
|
|
9
|
+
import { createMarkdownToVueRenderFn } from '../markdown/markdownToVue'
|
|
10
|
+
import type { PageDataPayload } from '../../types'
|
|
11
|
+
import { checkMd } from '../markdown/check'
|
|
12
|
+
import { VALAXY_CONFIG_ID } from './valaxy'
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* for /@valaxyjs/styles
|
|
16
|
+
* @param roots
|
|
17
|
+
* @returns
|
|
18
|
+
*/
|
|
19
|
+
function generateStyles(roots: string[], options: ResolvedValaxyOptions) {
|
|
20
|
+
const imports: string[] = []
|
|
21
|
+
|
|
22
|
+
// katex
|
|
23
|
+
if (options.config.features.katex) {
|
|
24
|
+
imports.push(`import "${toAtFS(resolveImportPath('katex/dist/katex.min.css', true))}"`)
|
|
25
|
+
imports.push(`import "${toAtFS(join(options.clientRoot, 'styles/third/katex.scss'))}"`)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
for (const root of roots) {
|
|
29
|
+
const styles: string[] = []
|
|
30
|
+
|
|
31
|
+
const autoloadNames = ['index', 'css-vars']
|
|
32
|
+
autoloadNames.forEach((name) => {
|
|
33
|
+
styles.push(join(root, 'styles', `${name}.css`))
|
|
34
|
+
styles.push(join(root, 'styles', `${name}.scss`))
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
for (const style of styles) {
|
|
38
|
+
if (fs.existsSync(style))
|
|
39
|
+
imports.push(`import "${toAtFS(style)}"`)
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return imports.join('\n')
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function generateLocales(roots: string[]) {
|
|
47
|
+
const imports: string[] = [
|
|
48
|
+
'const messages = { "zh-CN": {}, en: {} }',
|
|
49
|
+
]
|
|
50
|
+
const languages = ['zh-CN', 'en']
|
|
51
|
+
|
|
52
|
+
roots.forEach((root, i) => {
|
|
53
|
+
languages.forEach((lang) => {
|
|
54
|
+
const langYml = `${root}/locales/${lang}.yml`
|
|
55
|
+
if (fs.existsSync(langYml) && fs.readFileSync(langYml, 'utf-8')) {
|
|
56
|
+
const varName = lang.replace('-', '') + i
|
|
57
|
+
imports.push(`import ${varName} from "${toAtFS(langYml)}"`)
|
|
58
|
+
imports.push(`Object.assign(messages['${lang}'], ${varName})`)
|
|
59
|
+
}
|
|
60
|
+
})
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
imports.push('export default messages')
|
|
64
|
+
return imports.join('\n')
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export function createValaxyPlugin(options: ResolvedValaxyOptions, serverOptions: ValaxyServerOptions = {}): Plugin {
|
|
68
|
+
const valaxyPrefix = '/@valaxy'
|
|
69
|
+
|
|
70
|
+
let valaxyConfig = options.config
|
|
71
|
+
|
|
72
|
+
const roots = [options.clientRoot, options.themeRoot, options.userRoot]
|
|
73
|
+
|
|
74
|
+
let markdownToVue: Awaited<ReturnType<typeof createMarkdownToVueRenderFn>>
|
|
75
|
+
let hasDeadLinks = false
|
|
76
|
+
let config: ResolvedConfig
|
|
77
|
+
|
|
78
|
+
return {
|
|
79
|
+
name: 'valaxy',
|
|
80
|
+
enforce: 'pre',
|
|
81
|
+
|
|
82
|
+
async configResolved(resolvedConfig) {
|
|
83
|
+
config = resolvedConfig
|
|
84
|
+
markdownToVue = await createMarkdownToVueRenderFn(
|
|
85
|
+
options.userRoot,
|
|
86
|
+
options.config.markdownIt,
|
|
87
|
+
options.pages,
|
|
88
|
+
config.define,
|
|
89
|
+
config.command === 'build',
|
|
90
|
+
config.base,
|
|
91
|
+
options.config.lastUpdated,
|
|
92
|
+
)
|
|
93
|
+
},
|
|
94
|
+
|
|
95
|
+
configureServer(server) {
|
|
96
|
+
server.watcher.add([
|
|
97
|
+
options.configFile,
|
|
98
|
+
options.userRoot,
|
|
99
|
+
options.themeRoot,
|
|
100
|
+
])
|
|
101
|
+
},
|
|
102
|
+
|
|
103
|
+
resolveId(id) {
|
|
104
|
+
if (id.startsWith(valaxyPrefix))
|
|
105
|
+
return id
|
|
106
|
+
return null
|
|
107
|
+
},
|
|
108
|
+
|
|
109
|
+
load(id) {
|
|
110
|
+
if (id === `/${VALAXY_CONFIG_ID}`)
|
|
111
|
+
// stringify twice for \"
|
|
112
|
+
return `export default ${JSON.stringify(JSON.stringify(valaxyConfig))}`
|
|
113
|
+
|
|
114
|
+
if (id === '/@valaxyjs/context') {
|
|
115
|
+
return `export default ${JSON.stringify(JSON.stringify({
|
|
116
|
+
userRoot: options.userRoot,
|
|
117
|
+
// clientRoot: options.clientRoot,
|
|
118
|
+
}))}`
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// generate styles
|
|
122
|
+
if (id === '/@valaxyjs/styles')
|
|
123
|
+
return generateStyles(roots, options)
|
|
124
|
+
|
|
125
|
+
if (id === '/@valaxyjs/locales')
|
|
126
|
+
return generateLocales(roots)
|
|
127
|
+
|
|
128
|
+
if (id.startsWith(valaxyPrefix))
|
|
129
|
+
return ''
|
|
130
|
+
},
|
|
131
|
+
|
|
132
|
+
async transform(code, id) {
|
|
133
|
+
if (id.endsWith('.md')) {
|
|
134
|
+
checkMd(code, id)
|
|
135
|
+
code.replace('{%', '\{\%')
|
|
136
|
+
code.replace('%}', '\%\}')
|
|
137
|
+
|
|
138
|
+
// const scripts = [
|
|
139
|
+
// '<script setup>',
|
|
140
|
+
// 'import { useRoute } from "vue-router"',
|
|
141
|
+
// 'const route = useRoute()',
|
|
142
|
+
// `route.meta.headers = ${JSON.stringify(_md.__data)}`,
|
|
143
|
+
// `export const data = JSON.parse(${JSON.stringify(JSON.stringify(pageData))})`,
|
|
144
|
+
// `frontmatter.data = JSON.parse(${JSON.stringify(JSON.stringify(pageData))})`,
|
|
145
|
+
// '</script>',
|
|
146
|
+
// ]
|
|
147
|
+
|
|
148
|
+
// const li = code.lastIndexOf('</script>')
|
|
149
|
+
// code = code.slice(0, li) + scripts.join('\n') + code.slice(li + 9)
|
|
150
|
+
|
|
151
|
+
// transform .md files into vueSrc so plugin-vue can handle it
|
|
152
|
+
const { vueSrc, deadLinks, includes } = await markdownToVue(
|
|
153
|
+
code,
|
|
154
|
+
id,
|
|
155
|
+
config.publicDir,
|
|
156
|
+
)
|
|
157
|
+
if (deadLinks.length)
|
|
158
|
+
hasDeadLinks = true
|
|
159
|
+
|
|
160
|
+
if (includes.length) {
|
|
161
|
+
includes.forEach((i) => {
|
|
162
|
+
this.addWatchFile(i)
|
|
163
|
+
})
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
return vueSrc
|
|
167
|
+
}
|
|
168
|
+
},
|
|
169
|
+
|
|
170
|
+
renderStart() {
|
|
171
|
+
if (hasDeadLinks)
|
|
172
|
+
throw new Error('One or more pages contain dead links.')
|
|
173
|
+
},
|
|
174
|
+
|
|
175
|
+
async handleHotUpdate(ctx) {
|
|
176
|
+
// handle valaxy.config.ts hmr
|
|
177
|
+
const { file, server, read } = ctx
|
|
178
|
+
if (file !== options.configFile)
|
|
179
|
+
return
|
|
180
|
+
|
|
181
|
+
// send headers
|
|
182
|
+
if (file.endsWith('.md')) {
|
|
183
|
+
const content = await read()
|
|
184
|
+
const { pageData, vueSrc } = await markdownToVue(
|
|
185
|
+
content,
|
|
186
|
+
file,
|
|
187
|
+
join(options.userRoot, 'public'),
|
|
188
|
+
)
|
|
189
|
+
|
|
190
|
+
const path = `/${slash(relative(`${options.userRoot}/pages`, file))}`
|
|
191
|
+
const payload: PageDataPayload = {
|
|
192
|
+
// path: `/${slash(relative(srcDir, file))}`,
|
|
193
|
+
path,
|
|
194
|
+
pageData,
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
server.ws.send({
|
|
198
|
+
type: 'custom',
|
|
199
|
+
event: 'valaxy:pageData',
|
|
200
|
+
data: payload,
|
|
201
|
+
})
|
|
202
|
+
|
|
203
|
+
// overwrite src so vue plugin can handle the HMR
|
|
204
|
+
ctx.read = () => vueSrc
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
const { config } = await resolveConfig()
|
|
208
|
+
|
|
209
|
+
serverOptions.onConfigReload?.(config, options.config)
|
|
210
|
+
Object.assign(options.config, config)
|
|
211
|
+
|
|
212
|
+
// if (config.base !== options.config.base)
|
|
213
|
+
// consola.warn('[valaxy]: config.base has changed. Please restart the dev server.')
|
|
214
|
+
valaxyConfig = config
|
|
215
|
+
|
|
216
|
+
const moduleIds = [`/${VALAXY_CONFIG_ID}`, '/@valaxyjs/context']
|
|
217
|
+
const moduleEntries = [
|
|
218
|
+
...Array.from(moduleIds).map(id => server.moduleGraph.getModuleById(id)),
|
|
219
|
+
].filter(<T>(item: T): item is NonNullable<T> => !!item)
|
|
220
|
+
|
|
221
|
+
return moduleEntries
|
|
222
|
+
},
|
|
223
|
+
}
|
|
224
|
+
}
|
|
@@ -16,7 +16,7 @@ import Inspect from 'vite-plugin-inspect'
|
|
|
16
16
|
import { dim, yellow } from 'kolorist'
|
|
17
17
|
import type { ResolvedValaxyOptions, ValaxyServerOptions } from '../options'
|
|
18
18
|
import { setupMarkdownPlugins } from '../markdown'
|
|
19
|
-
import { createMarkdownPlugin, excerpt_separator } from './markdown'
|
|
19
|
+
// import { createMarkdownPlugin, excerpt_separator } from './markdown'
|
|
20
20
|
import { createUnocssPlugin } from './unocss'
|
|
21
21
|
import { createConfigPlugin } from './extendConfig'
|
|
22
22
|
import { createValaxyPlugin } from '.'
|
|
@@ -32,17 +32,17 @@ export async function ViteValaxyPlugins(
|
|
|
32
32
|
): Promise<(PluginOption | PluginOption[])[] | undefined> {
|
|
33
33
|
const { clientRoot, themeRoot, userRoot } = options
|
|
34
34
|
|
|
35
|
-
const MarkdownPlugin = createMarkdownPlugin(options)
|
|
35
|
+
// const MarkdownPlugin = createMarkdownPlugin(options)
|
|
36
36
|
const UnocssPlugin = await createUnocssPlugin(options)
|
|
37
37
|
|
|
38
38
|
const ValaxyPlugin = createValaxyPlugin(options, serverOptions)
|
|
39
39
|
|
|
40
40
|
const mdIt = new MarkdownIt({ html: true })
|
|
41
|
-
setupMarkdownPlugins(mdIt, options.config.markdownIt)
|
|
41
|
+
await setupMarkdownPlugins(mdIt, options.config.markdownIt)
|
|
42
42
|
|
|
43
43
|
const roots = [clientRoot, themeRoot, userRoot]
|
|
44
44
|
|
|
45
|
-
const { default: ThemePlugin } = await import(`valaxy-theme-${options.theme}`)
|
|
45
|
+
const { default: ThemePlugin } = (await import(`valaxy-theme-${options.theme}`))
|
|
46
46
|
|
|
47
47
|
const customElements = new Set([
|
|
48
48
|
// katex
|
|
@@ -90,8 +90,8 @@ export async function ViteValaxyPlugins(
|
|
|
90
90
|
},
|
|
91
91
|
}),
|
|
92
92
|
|
|
93
|
-
ValaxyPlugin,
|
|
94
93
|
createConfigPlugin(options),
|
|
94
|
+
ValaxyPlugin,
|
|
95
95
|
|
|
96
96
|
ThemePlugin(options.config.themeConfig),
|
|
97
97
|
|
|
@@ -118,7 +118,7 @@ export async function ViteValaxyPlugins(
|
|
|
118
118
|
})
|
|
119
119
|
|
|
120
120
|
const md = fs.readFileSync(path, 'utf-8')
|
|
121
|
-
const { data, excerpt } = matter(md, { excerpt_separator })
|
|
121
|
+
const { data, excerpt } = matter(md, { excerpt_separator: '<!-- more -->' })
|
|
122
122
|
|
|
123
123
|
// warn for post frontmatter
|
|
124
124
|
if (route.path.startsWith('/posts/')) {
|
|
@@ -160,7 +160,7 @@ export async function ViteValaxyPlugins(
|
|
|
160
160
|
allowOverrides: true,
|
|
161
161
|
// override: user -> theme -> client
|
|
162
162
|
// latter override former
|
|
163
|
-
dirs: roots.map(root => `${root}/components`).concat(['src/components', 'components']),
|
|
163
|
+
dirs: roots.map(root => `${root}/components`).concat(roots.map(root => `${root}/layouts`)).concat(['src/components', 'components']),
|
|
164
164
|
dts: `${options.userRoot}/components.d.ts`,
|
|
165
165
|
|
|
166
166
|
...pluginOptions,
|
|
@@ -170,7 +170,7 @@ export async function ViteValaxyPlugins(
|
|
|
170
170
|
// UnocssPlugin,
|
|
171
171
|
UnocssPlugin,
|
|
172
172
|
|
|
173
|
-
...MarkdownPlugin,
|
|
173
|
+
// ...MarkdownPlugin,
|
|
174
174
|
|
|
175
175
|
// https://github.com/intlify/bundle-tools/tree/main/packages/vite-plugin-vue-i18n
|
|
176
176
|
VueI18n({
|
|
File without changes
|
|
File without changes
|
package/{src/node → node}/rss.ts
RENAMED
|
@@ -24,7 +24,7 @@ const markdown = MarkdownIt({
|
|
|
24
24
|
export async function build(options: ResolvedValaxyOptions) {
|
|
25
25
|
const { config } = options
|
|
26
26
|
|
|
27
|
-
if (!config.url) {
|
|
27
|
+
if (!config.url || config.url === '/') {
|
|
28
28
|
consola.error('You must set "config.url" to generate rss.')
|
|
29
29
|
return
|
|
30
30
|
}
|
|
File without changes
|
|
@@ -7,7 +7,7 @@ import consola from 'consola'
|
|
|
7
7
|
import type { InlineConfig, ViteDevServer } from 'vite'
|
|
8
8
|
import { createServer } from '../server'
|
|
9
9
|
import type { ResolvedValaxyOptions } from '../options'
|
|
10
|
-
import { version } from '
|
|
10
|
+
import { version } from '../../package.json'
|
|
11
11
|
import { createSafelist } from '../plugins/unocss'
|
|
12
12
|
|
|
13
13
|
let server: ViteDevServer | undefined
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { spawn } from 'cross-spawn'
|
|
2
|
+
|
|
3
|
+
export function getGitTimestamp(file: string) {
|
|
4
|
+
return new Promise<number>((resolve, reject) => {
|
|
5
|
+
const child = spawn('git', ['log', '-1', '--pretty="%ci"', file])
|
|
6
|
+
let output = ''
|
|
7
|
+
child.stdout.on('data', d => (output += String(d)))
|
|
8
|
+
child.on('close', () => {
|
|
9
|
+
resolve(+new Date(output))
|
|
10
|
+
})
|
|
11
|
+
child.on('error', reject)
|
|
12
|
+
})
|
|
13
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { join } from 'path'
|
|
2
|
+
import isInstalledGlobally from 'is-installed-globally'
|
|
3
|
+
import globalDirs from 'global-dirs'
|
|
4
|
+
import { sync as resolve } from 'resolve'
|
|
5
|
+
import consola from 'consola'
|
|
6
|
+
|
|
7
|
+
export * from './getGitTimestamp'
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* transform obj for vite cde
|
|
11
|
+
* @param obj
|
|
12
|
+
* @returns
|
|
13
|
+
*/
|
|
14
|
+
export const transformObject = (obj: any) => {
|
|
15
|
+
return `JSON.parse(${JSON.stringify(JSON.stringify(obj))})`
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function slash(str: string) {
|
|
19
|
+
return str.replace(/\\/g, '/')
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function ensurePrefix(prefix: string, str: string) {
|
|
23
|
+
if (!str.startsWith(prefix))
|
|
24
|
+
return prefix + str
|
|
25
|
+
return str
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function toAtFS(path: string) {
|
|
29
|
+
return `/@fs${ensurePrefix('/', slash(path))}`
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function resolveImportPath(importName: string, ensure: true): string
|
|
33
|
+
export function resolveImportPath(importName: string, ensure?: boolean): string | undefined
|
|
34
|
+
export function resolveImportPath(importName: string, ensure = false) {
|
|
35
|
+
try {
|
|
36
|
+
return resolve(importName, {
|
|
37
|
+
preserveSymlinks: false,
|
|
38
|
+
})
|
|
39
|
+
}
|
|
40
|
+
catch {}
|
|
41
|
+
|
|
42
|
+
if (isInstalledGlobally) {
|
|
43
|
+
try {
|
|
44
|
+
return require.resolve(join(globalDirs.yarn.packages, importName))
|
|
45
|
+
}
|
|
46
|
+
catch {}
|
|
47
|
+
|
|
48
|
+
try {
|
|
49
|
+
return require.resolve(join(globalDirs.npm.packages, importName))
|
|
50
|
+
}
|
|
51
|
+
catch {}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (ensure)
|
|
55
|
+
throw new Error(`Failed to resolve package ${importName}`)
|
|
56
|
+
|
|
57
|
+
consola.error(`Failed to resolve package ${importName}`)
|
|
58
|
+
return undefined
|
|
59
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import net from 'net'
|
|
2
|
+
|
|
3
|
+
export async function findFreePort(start: number): Promise<number> {
|
|
4
|
+
if (await isPortFree(start))
|
|
5
|
+
return start
|
|
6
|
+
return await findFreePort(start + 1)
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
function isPortFree(port: number): Promise<boolean> {
|
|
10
|
+
return new Promise((resolve) => {
|
|
11
|
+
const server = net.createServer()
|
|
12
|
+
.listen(port, () => {
|
|
13
|
+
server.close()
|
|
14
|
+
resolve(true)
|
|
15
|
+
})
|
|
16
|
+
.on('error', () => {
|
|
17
|
+
resolve(false)
|
|
18
|
+
})
|
|
19
|
+
})
|
|
20
|
+
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { join } from 'path'
|
|
1
|
+
import { dirname, join } from 'path'
|
|
2
2
|
import type { InlineConfig } from 'vite'
|
|
3
3
|
import { splitVendorChunkPlugin } from 'vite'
|
|
4
4
|
import type { ResolvedValaxyOptions, ValaxyServerOptions } from './options'
|
|
5
5
|
|
|
6
6
|
import { ViteValaxyPlugins } from './plugins/preset'
|
|
7
|
+
import { resolveImportPath } from './utils'
|
|
7
8
|
|
|
8
9
|
export type Mode = 'dev' | 'build'
|
|
9
10
|
|
|
@@ -24,6 +25,8 @@ export async function createViteConfig(options: ResolvedValaxyOptions, serverOpt
|
|
|
24
25
|
// always string
|
|
25
26
|
define: {
|
|
26
27
|
__DEV__: options.mode === 'dev' ? 'true' : 'false',
|
|
28
|
+
|
|
29
|
+
__ALGOLIA__: !!options.config.search.algolia.enable,
|
|
27
30
|
},
|
|
28
31
|
|
|
29
32
|
root: options.clientRoot,
|
|
@@ -39,6 +42,7 @@ export async function createViteConfig(options: ResolvedValaxyOptions, serverOpt
|
|
|
39
42
|
options.clientRoot,
|
|
40
43
|
options.themeRoot,
|
|
41
44
|
options.userRoot,
|
|
45
|
+
dirname(resolveImportPath('katex/package.json', true)),
|
|
42
46
|
],
|
|
43
47
|
},
|
|
44
48
|
},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "valaxy",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.1",
|
|
4
4
|
"description": "📄 Vite & Vue powered static blog generator.",
|
|
5
5
|
"author": {
|
|
6
6
|
"email": "me@yunyoujun.cn",
|
|
@@ -16,10 +16,22 @@
|
|
|
16
16
|
"blog"
|
|
17
17
|
],
|
|
18
18
|
"exports": {
|
|
19
|
-
".":
|
|
19
|
+
".": {
|
|
20
|
+
"types": "./dist/index.d.ts",
|
|
21
|
+
"require": "./dist/index.js",
|
|
22
|
+
"import": "./dist/index.mjs"
|
|
23
|
+
},
|
|
24
|
+
"./client": "./dist/client.d.ts",
|
|
25
|
+
"./client/*": "./client/*",
|
|
26
|
+
"./node": {
|
|
27
|
+
"types": "./dist/node/index.d.ts",
|
|
28
|
+
"require": "./dist/node/index.js",
|
|
29
|
+
"import": "./dist/node/index.mjs"
|
|
30
|
+
},
|
|
20
31
|
"./*": "./*"
|
|
21
32
|
},
|
|
22
33
|
"main": "dist/index.js",
|
|
34
|
+
"module": "dist/index.mjs",
|
|
23
35
|
"types": "dist/index.d.ts",
|
|
24
36
|
"bin": {
|
|
25
37
|
"vala": "./bin/valaxy.js",
|
|
@@ -29,20 +41,27 @@
|
|
|
29
41
|
"node": ">=14.0.0"
|
|
30
42
|
},
|
|
31
43
|
"dependencies": {
|
|
44
|
+
"@antfu/utils": "^0.5.2",
|
|
32
45
|
"@ctrl/tinycolor": "^3.4.1",
|
|
46
|
+
"@docsearch/css": "^3.1.0",
|
|
47
|
+
"@docsearch/js": "^3.1.0",
|
|
33
48
|
"@iconify-json/carbon": "^1.1.5",
|
|
34
49
|
"@iconify-json/ri": "^1.1.2",
|
|
35
50
|
"@intlify/vite-plugin-vue-i18n": "^3.4.0",
|
|
36
51
|
"@vitejs/plugin-vue": "^2.3.3",
|
|
37
|
-
"@vueuse/core": "^8.
|
|
52
|
+
"@vueuse/core": "^8.7.4",
|
|
38
53
|
"@vueuse/head": "^0.7.6",
|
|
39
54
|
"consola": "^2.15.3",
|
|
40
55
|
"critters": "^0.0.16",
|
|
56
|
+
"cross-spawn": "^7.0.3",
|
|
41
57
|
"dayjs": "^1.11.3",
|
|
42
58
|
"escape-html": "^1.0.3",
|
|
43
59
|
"feed": "^4.2.2",
|
|
60
|
+
"gray-matter": "^4.0.3",
|
|
44
61
|
"katex": "^0.16.0",
|
|
45
62
|
"kolorist": "^1.5.1",
|
|
63
|
+
"lru-cache": "^7.10.1",
|
|
64
|
+
"markdown-it": "^13.0.1",
|
|
46
65
|
"markdown-it-anchor": "^8.6.4",
|
|
47
66
|
"markdown-it-attrs": "^4.1.4",
|
|
48
67
|
"markdown-it-container": "^3.0.0",
|
|
@@ -53,38 +72,38 @@
|
|
|
53
72
|
"nprogress": "^0.2.0",
|
|
54
73
|
"open": "^8.4.0",
|
|
55
74
|
"pinia": "^2.0.14",
|
|
56
|
-
"
|
|
57
|
-
"
|
|
58
|
-
"sass": "^1.52.2",
|
|
75
|
+
"sass": "^1.52.3",
|
|
76
|
+
"shiki": "^0.10.1",
|
|
59
77
|
"star-markdown-css": "^0.3.3",
|
|
60
78
|
"unconfig": "^0.3.4",
|
|
61
|
-
"unocss": "^0.
|
|
79
|
+
"unocss": "^0.39.3",
|
|
62
80
|
"unplugin-vue-components": "^0.19.6",
|
|
63
|
-
"vite": "^2.9.
|
|
81
|
+
"vite": "^2.9.12",
|
|
64
82
|
"vite-plugin-inspect": "^0.5.0",
|
|
65
|
-
"vite-plugin-
|
|
66
|
-
"vite-plugin-pages": "^0.23.0",
|
|
83
|
+
"vite-plugin-pages": "^0.24.2",
|
|
67
84
|
"vite-plugin-vue-layouts": "^0.6.0",
|
|
68
85
|
"vite-ssg": "0.19.2",
|
|
69
86
|
"vite-ssg-sitemap": "0.2.7",
|
|
70
87
|
"vue": "^3.2.37",
|
|
71
88
|
"vue-i18n": "^9.1.10",
|
|
72
|
-
"vue-router": "^4.0.
|
|
89
|
+
"vue-router": "^4.0.16",
|
|
73
90
|
"yargs": "^17.5.1"
|
|
74
91
|
},
|
|
75
92
|
"devDependencies": {
|
|
93
|
+
"@types/cross-spawn": "^6.0.2",
|
|
76
94
|
"@types/katex": "^0.14.0",
|
|
95
|
+
"@types/lru-cache": "^7.10.10",
|
|
77
96
|
"@types/markdown-it-link-attributes": "^3.0.1",
|
|
78
97
|
"@types/nprogress": "^0.2.0",
|
|
79
98
|
"@types/yargs": "^17.0.10",
|
|
80
99
|
"debug": "^4.3.4",
|
|
81
100
|
"diacritics": "^1.3.0",
|
|
82
101
|
"https-localhost": "^4.7.1",
|
|
83
|
-
"type-fest": "^2.13.
|
|
102
|
+
"type-fest": "^2.13.1"
|
|
84
103
|
},
|
|
85
104
|
"scripts": {
|
|
86
105
|
"build": "rimraf dist && tsup --splitting",
|
|
87
|
-
"dev": "tsup --
|
|
106
|
+
"dev": "tsup --splitting --watch",
|
|
88
107
|
"lint": "eslint \"**/*.{vue,ts,js}\"",
|
|
89
108
|
"preview": "vite preview",
|
|
90
109
|
"preview-https": "serve dist"
|
package/shared/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const EXTERNAL_URL_RE = /^https?:/i
|
package/tsup.config.ts
CHANGED
|
@@ -3,19 +3,22 @@ import { defineConfig } from 'tsup'
|
|
|
3
3
|
export default defineConfig((options) => {
|
|
4
4
|
return {
|
|
5
5
|
entry: [
|
|
6
|
-
'
|
|
7
|
-
'
|
|
8
|
-
'
|
|
6
|
+
'index.ts',
|
|
7
|
+
// 'client/index.ts',
|
|
8
|
+
'node/index.ts',
|
|
9
|
+
'node/cli.ts',
|
|
10
|
+
// 'types/index.ts',
|
|
9
11
|
],
|
|
10
12
|
// https://tsup.egoist.sh/#code-splitting
|
|
11
13
|
// Code splitting currently only works with the esm output format, and it's enabled by default. If you want code splitting for cjs output format as well, try using --splitting flag which is an experimental feature to get rid of the limitation in esbuild.
|
|
12
|
-
splitting: true,
|
|
14
|
+
// splitting: true,
|
|
13
15
|
clean: true,
|
|
14
16
|
dts: true,
|
|
15
17
|
format: ['cjs', 'esm'],
|
|
16
18
|
minify: !options.watch,
|
|
17
19
|
external: [
|
|
18
20
|
'@valaxyjs/config',
|
|
21
|
+
'@valaxyjs/context',
|
|
19
22
|
'valaxy-theme-yun',
|
|
20
23
|
],
|
|
21
24
|
}
|