hexo-theme-shokax 0.4.6-dev5 → 0.4.6
Sign up to get free protection for your applications and to get access to all the features.
- package/CODE_OF_CONDUCT.md +128 -128
- package/CONTRIBUTING.md +58 -58
- package/LICENSE +660 -660
- package/LICENSE-shoka +21 -21
- package/README.md +76 -99
- package/README_en.MD +75 -91
- package/UsageRestrictions.md +25 -25
- package/_config.yml +381 -381
- package/_images.yml +9 -9
- package/eslint.config.mjs +55 -55
- package/languages/README.md +19 -19
- package/languages/default.yml +1 -1
- package/languages/en.yml +153 -153
- package/languages/ja.yml +153 -153
- package/languages/zh-CN.yml +153 -153
- package/languages/zh-HK.yml +153 -153
- package/languages/zh-TW.yml +153 -153
- package/layout/_alternate/atom.ejs +30 -30
- package/layout/_alternate/json.ejs +16 -16
- package/layout/_alternate/rss.ejs +34 -34
- package/layout/_mixin/breadcrumb.pug +33 -33
- package/layout/_mixin/card.pug +38 -38
- package/layout/_mixin/comment.pug +6 -6
- package/layout/_mixin/postmeta.pug +29 -29
- package/layout/_mixin/segment.pug +35 -35
- package/layout/_mixin/sidebar.pug +40 -40
- package/layout/_mixin/widgets.pug +28 -28
- package/layout/_partials/footer.pug +43 -43
- package/layout/_partials/head/head.pug +55 -55
- package/layout/_partials/head/head_com.pug +24 -24
- package/layout/_partials/head/pwa.pug +18 -18
- package/layout/_partials/header.pug +18 -18
- package/layout/_partials/layout.pug +140 -140
- package/layout/_partials/loading.pug +13 -13
- package/layout/_partials/pagination.pug +4 -4
- package/layout/_partials/post/copyright.pug +20 -20
- package/layout/_partials/post/footer.pug +17 -17
- package/layout/_partials/post/nav.pug +13 -13
- package/layout/_partials/post/post.pug +41 -41
- package/layout/_partials/post/reward.pug +18 -18
- package/layout/_partials/sidebar/menu.pug +37 -37
- package/layout/_partials/sidebar/overview.pug +42 -42
- package/layout/_partials/third-party/baidu-analytics.pug +11 -11
- package/layout/_partials/third-party/clarity.pug +8 -8
- package/layout/_partials/third-party/google-analytics.pug +9 -9
- package/layout/archive.pug +118 -118
- package/layout/category.pug +59 -59
- package/layout/index.pug +33 -33
- package/layout/page.pug +55 -55
- package/layout/post.pug +36 -36
- package/layout/tag.pug +43 -43
- package/package.json +72 -72
- package/scripts/filters/locals.js +52 -0
- package/scripts/filters/post.js +5 -0
- package/scripts/generaters/archive.js +133 -0
- package/scripts/generaters/config.js +51 -0
- package/scripts/generaters/images.js +23 -0
- package/scripts/generaters/index.js +107 -0
- package/scripts/generaters/pages.js +15 -0
- package/scripts/generaters/script.js +156 -0
- package/scripts/helpers/asset.js +73 -0
- package/scripts/helpers/engine.js +177 -0
- package/scripts/helpers/list_categories.js +80 -0
- package/scripts/helpers/summary_ai.js +107 -0
- package/scripts/helpers/symbols_count_time.js +69 -0
- package/scripts/plugin/check.js +32 -0
- package/scripts/plugin/index.js +81 -0
- package/scripts/plugin/lib/injects-point.js +20 -0
- package/scripts/plugin/lib/injects.js +89 -0
- package/scripts/tags/links.js +44 -0
- package/scripts/tags/media.js +19 -0
- package/scripts/utils.js +13 -0
- package/source/assets/algolia_logo.svg +9 -9
- package/source/assets/logo.svg +16 -16
- package/source/css/_colors.styl +207 -207
- package/source/css/_common/components/components.styl +6 -6
- package/source/css/_common/components/highlight/highlight.styl +357 -357
- package/source/css/_common/components/highlight/operation.styl +21 -21
- package/source/css/_common/components/pages/collapse.styl +119 -119
- package/source/css/_common/components/pages/home.styl +391 -391
- package/source/css/_common/components/pages/pages.styl +56 -56
- package/source/css/_common/components/pages/tag-cloud.styl +12 -12
- package/source/css/_common/components/post/breadcrumb.styl +39 -39
- package/source/css/_common/components/post/copyright.styl +41 -41
- package/source/css/_common/components/post/expand.styl +263 -263
- package/source/css/_common/components/post/footer.styl +11 -11
- package/source/css/_common/components/post/header.styl +79 -79
- package/source/css/_common/components/post/nav.styl +64 -64
- package/source/css/_common/components/post/post.styl +29 -29
- package/source/css/_common/components/post/reward.styl +50 -50
- package/source/css/_common/components/post/rtl.styl +12 -12
- package/source/css/_common/components/post/tags.styl +39 -39
- package/source/css/_common/components/tags/collapse.styl +72 -72
- package/source/css/_common/components/tags/container.styl +49 -49
- package/source/css/_common/components/tags/label.styl +12 -12
- package/source/css/_common/components/tags/links.styl +77 -77
- package/source/css/_common/components/tags/list.styl +131 -131
- package/source/css/_common/components/tags/note.styl +70 -70
- package/source/css/_common/components/tags/player.styl +361 -361
- package/source/css/_common/components/tags/quiz.styl +200 -200
- package/source/css/_common/components/tags/tabs.styl +89 -89
- package/source/css/_common/components/tags/tags.styl +9 -9
- package/source/css/_common/components/third-party/loading.styl +222 -222
- package/source/css/_common/components/third-party/mermaid/class.styl +90 -90
- package/source/css/_common/components/third-party/mermaid/flowchart.styl +72 -72
- package/source/css/_common/components/third-party/mermaid/gantt.styl +251 -251
- package/source/css/_common/components/third-party/mermaid/git.styl +7 -7
- package/source/css/_common/components/third-party/mermaid/mermaid.styl +37 -37
- package/source/css/_common/components/third-party/mermaid/pie.styl +9 -9
- package/source/css/_common/components/third-party/mermaid/sequence.styl +95 -95
- package/source/css/_common/components/third-party/mermaid/state.styl +130 -130
- package/source/css/_common/components/third-party/pace.styl +18 -18
- package/source/css/_common/components/third-party/search.styl +167 -167
- package/source/css/_common/components/third-party/theme.styl +151 -151
- package/source/css/_common/components/third-party/third-party.styl +22 -22
- package/source/css/_common/components/third-party/widgets.styl +57 -57
- package/source/css/_common/outline/footer/footer.styl +67 -67
- package/source/css/_common/outline/header/brand.styl +77 -77
- package/source/css/_common/outline/header/header.styl +20 -20
- package/source/css/_common/outline/header/image.styl +85 -85
- package/source/css/_common/outline/header/menu.styl +117 -117
- package/source/css/_common/outline/header/nav.styl +81 -81
- package/source/css/_common/outline/header/right.styl +15 -15
- package/source/css/_common/outline/header/tool.styl +207 -207
- package/source/css/_common/outline/header/waves.styl +57 -57
- package/source/css/_common/outline/mobile.styl +46 -46
- package/source/css/_common/outline/outline.styl +78 -78
- package/source/css/_common/outline/sidebar/author.styl +59 -59
- package/source/css/_common/outline/sidebar/dimmer.styl +23 -23
- package/source/css/_common/outline/sidebar/menu.styl +63 -63
- package/source/css/_common/outline/sidebar/quick.styl +43 -43
- package/source/css/_common/outline/sidebar/related.styl +56 -56
- package/source/css/_common/outline/sidebar/sidebar.styl +80 -80
- package/source/css/_common/outline/sidebar/social.styl +69 -69
- package/source/css/_common/outline/sidebar/state.styl +37 -37
- package/source/css/_common/outline/sidebar/tab.styl +71 -71
- package/source/css/_common/outline/sidebar/toc.styl +47 -47
- package/source/css/_common/scaffolding/animate.styl +322 -322
- package/source/css/_common/scaffolding/base.styl +190 -190
- package/source/css/_common/scaffolding/buttons.styl +48 -48
- package/source/css/_common/scaffolding/divider.styl +36 -36
- package/source/css/_common/scaffolding/iconfont.styl +443 -443
- package/source/css/_common/scaffolding/normalize.styl +273 -273
- package/source/css/_common/scaffolding/pagination.styl +81 -81
- package/source/css/_common/scaffolding/ribbon.styl +38 -38
- package/source/css/_common/scaffolding/scaffolding.styl +14 -14
- package/source/css/_common/scaffolding/scrollbar.styl +37 -37
- package/source/css/_common/scaffolding/tables.styl +50 -50
- package/source/css/_common/scaffolding/tip.styl +19 -19
- package/source/css/_common/scaffolding/toggles.styl +59 -59
- package/source/css/_iconfont.styl +455 -455
- package/source/css/_mixins.styl +148 -148
- package/source/css/_variables.styl +89 -89
- package/source/css/app.styl +41 -41
- package/source/css/mermaid.styl +5 -5
- package/source/css/optimize.styl +5 -5
- package/source/js/_app/components/comments.ts +88 -88
- package/source/js/_app/components/sidebar.ts +239 -239
- package/source/js/_app/components/tcomments.ts +54 -54
- package/source/js/_app/globals/globalVars.ts +99 -99
- package/source/js/_app/globals/handles.ts +124 -124
- package/source/js/_app/globals/themeColor.ts +63 -63
- package/source/js/_app/globals/thirdparty.ts +63 -63
- package/source/js/_app/globals/tools.ts +75 -75
- package/source/js/_app/library/anime.ts +110 -110
- package/source/js/_app/library/declare.d.ts +128 -128
- package/source/js/_app/library/dom.ts +28 -28
- package/source/js/_app/library/loadFile.ts +47 -47
- package/source/js/_app/library/proto.ts +137 -137
- package/source/js/_app/library/scriptPjax.ts +72 -72
- package/source/js/_app/library/storage.ts +12 -12
- package/source/js/_app/library/vue.ts +49 -49
- package/source/js/_app/page/common.ts +43 -43
- package/source/js/_app/page/fancybox.ts +72 -72
- package/source/js/_app/page/post.ts +266 -266
- package/source/js/_app/page/search.ts +115 -115
- package/source/js/_app/page/tab.ts +60 -60
- package/source/js/_app/pjax/domInit.ts +97 -97
- package/source/js/_app/pjax/refresh.ts +140 -140
- package/source/js/_app/pjax/siteInit.ts +106 -106
- package/source/js/_app/player.ts +798 -798
- package/toolbox/compiler.mjs +10 -6
- package/toolbox/hoistdep.mjs +5 -5
- package/toolbox/lib.mjs +63 -63
- package/index.html +0 -231
- package/meta.json +0 -6431
package/toolbox/compiler.mjs
CHANGED
@@ -46,12 +46,16 @@ if (CONFIG.legacyScript) {
|
|
46
46
|
} else if (sPath.startsWith('file:\\')) {
|
47
47
|
sPath = sPath.slice(8); // 去除 'file:\'
|
48
48
|
}
|
49
|
-
child_process.exec('pnpm
|
50
|
-
cwd: sPath
|
51
|
-
},
|
52
|
-
|
53
|
-
|
54
|
-
|
49
|
+
child_process.exec('pnpm install',{
|
50
|
+
cwd: path.join(sPath,'./../')
|
51
|
+
}, (code, stdout, stderr) => {
|
52
|
+
child_process.exec('pnpm --package=typescript dlx tsc --build'.trim(), {
|
53
|
+
cwd: sPath
|
54
|
+
}, async (code, stdout, stderr) => {
|
55
|
+
console.log('Deleting typescript files...')
|
56
|
+
await deleteFileRecursive(sPath)
|
57
|
+
console.log('Finished compiling.')
|
58
|
+
})
|
55
59
|
})
|
56
60
|
} else {
|
57
61
|
throw Error('Not implemented yet.')
|
package/toolbox/hoistdep.mjs
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
import { hoistDeps } from "./lib.mjs";
|
2
|
-
|
3
|
-
console.log('ShokaX ToolBox - Hoist Dependencies')
|
4
|
-
console.log('Hoisting dependencies...')
|
5
|
-
await hoistDeps()
|
1
|
+
import { hoistDeps } from "./lib.mjs";
|
2
|
+
|
3
|
+
console.log('ShokaX ToolBox - Hoist Dependencies')
|
4
|
+
console.log('Hoisting dependencies...')
|
5
|
+
await hoistDeps()
|
6
6
|
console.log('Finished hoisting dependencies.')
|
package/toolbox/lib.mjs
CHANGED
@@ -1,64 +1,64 @@
|
|
1
|
-
import fs from "fs/promises";
|
2
|
-
import child_process from "child_process";
|
3
|
-
import { dirname, resolve, join } from 'path';
|
4
|
-
|
5
|
-
async function findScaffoldsDir(startPath) {
|
6
|
-
let currentPath = resolve(startPath);
|
7
|
-
|
8
|
-
while (currentPath !== dirname(currentPath)) {
|
9
|
-
const scaffoldsPath = resolve(currentPath, 'scaffolds');
|
10
|
-
|
11
|
-
try {
|
12
|
-
const stat = await fs.stat(scaffoldsPath);
|
13
|
-
if (stat.isDirectory()) {
|
14
|
-
return currentPath;
|
15
|
-
}
|
16
|
-
} catch (err) {
|
17
|
-
// If the error is because the file/directory does not exist, continue to the parent directory
|
18
|
-
if (err.code !== 'ENOENT') {
|
19
|
-
throw err;
|
20
|
-
}
|
21
|
-
}
|
22
|
-
|
23
|
-
currentPath = dirname(currentPath);
|
24
|
-
}
|
25
|
-
|
26
|
-
return null;
|
27
|
-
}
|
28
|
-
|
29
|
-
const hexoRoot = await findScaffoldsDir(process.cwd())
|
30
|
-
|
31
|
-
async function checkFileAccessible(file) {
|
32
|
-
try {
|
33
|
-
await fs.access(join((hexoRoot || ''),file))
|
34
|
-
} catch {
|
35
|
-
return false
|
36
|
-
}
|
37
|
-
return true
|
38
|
-
}
|
39
|
-
|
40
|
-
export async function hoistDeps() {
|
41
|
-
let pm
|
42
|
-
if (await checkFileAccessible('pnpm-lock.yml') || await checkFileAccessible('pnpm-lock.yaml') || await checkFileAccessible('enable_pnpm')) {
|
43
|
-
pm = "pnpm add"
|
44
|
-
} else if (await checkFileAccessible('yarn.lock') || await checkFileAccessible('.yarnrc.yml')) {
|
45
|
-
pm = "yarn add"
|
46
|
-
} else {
|
47
|
-
pm = "npm install"
|
48
|
-
}
|
49
|
-
console.log(`Using ${pm} to hoist dependencies.`)
|
50
|
-
// TODO 使用本地 package.json 解析
|
51
|
-
const res = await (await fetch('https://registry.npmmirror.com/hexo-theme-shokax')).json()
|
52
|
-
const latestV = res['dist-tags'].latest
|
53
|
-
const deps = res.versions[latestV].dependencies
|
54
|
-
const depsList = Object.keys(deps).map(d => `${d}@${deps[d]}`)
|
55
|
-
child_process.exec(`${pm} ${depsList.join(' ')}`.trim(), {
|
56
|
-
cwd: hexoRoot
|
57
|
-
}, (code, stdout, stderr) => {
|
58
|
-
if (stderr) {
|
59
|
-
console.error(stderr)
|
60
|
-
} else {
|
61
|
-
console.log(stdout)
|
62
|
-
}
|
63
|
-
})
|
1
|
+
import fs from "fs/promises";
|
2
|
+
import child_process from "child_process";
|
3
|
+
import { dirname, resolve, join } from 'path';
|
4
|
+
|
5
|
+
async function findScaffoldsDir(startPath) {
|
6
|
+
let currentPath = resolve(startPath);
|
7
|
+
|
8
|
+
while (currentPath !== dirname(currentPath)) {
|
9
|
+
const scaffoldsPath = resolve(currentPath, 'scaffolds');
|
10
|
+
|
11
|
+
try {
|
12
|
+
const stat = await fs.stat(scaffoldsPath);
|
13
|
+
if (stat.isDirectory()) {
|
14
|
+
return currentPath;
|
15
|
+
}
|
16
|
+
} catch (err) {
|
17
|
+
// If the error is because the file/directory does not exist, continue to the parent directory
|
18
|
+
if (err.code !== 'ENOENT') {
|
19
|
+
throw err;
|
20
|
+
}
|
21
|
+
}
|
22
|
+
|
23
|
+
currentPath = dirname(currentPath);
|
24
|
+
}
|
25
|
+
|
26
|
+
return null;
|
27
|
+
}
|
28
|
+
|
29
|
+
const hexoRoot = await findScaffoldsDir(process.cwd())
|
30
|
+
|
31
|
+
async function checkFileAccessible(file) {
|
32
|
+
try {
|
33
|
+
await fs.access(join((hexoRoot || ''),file))
|
34
|
+
} catch {
|
35
|
+
return false
|
36
|
+
}
|
37
|
+
return true
|
38
|
+
}
|
39
|
+
|
40
|
+
export async function hoistDeps() {
|
41
|
+
let pm
|
42
|
+
if (await checkFileAccessible('pnpm-lock.yml') || await checkFileAccessible('pnpm-lock.yaml') || await checkFileAccessible('enable_pnpm')) {
|
43
|
+
pm = "pnpm add"
|
44
|
+
} else if (await checkFileAccessible('yarn.lock') || await checkFileAccessible('.yarnrc.yml')) {
|
45
|
+
pm = "yarn add"
|
46
|
+
} else {
|
47
|
+
pm = "npm install"
|
48
|
+
}
|
49
|
+
console.log(`Using ${pm} to hoist dependencies.`)
|
50
|
+
// TODO 使用本地 package.json 解析
|
51
|
+
const res = await (await fetch('https://registry.npmmirror.com/hexo-theme-shokax')).json()
|
52
|
+
const latestV = res['dist-tags'].latest
|
53
|
+
const deps = res.versions[latestV].dependencies
|
54
|
+
const depsList = Object.keys(deps).map(d => `${d}@${deps[d]}`)
|
55
|
+
child_process.exec(`${pm} ${depsList.join(' ')}`.trim(), {
|
56
|
+
cwd: hexoRoot
|
57
|
+
}, (code, stdout, stderr) => {
|
58
|
+
if (stderr) {
|
59
|
+
console.error(stderr)
|
60
|
+
} else {
|
61
|
+
console.log(stdout)
|
62
|
+
}
|
63
|
+
})
|
64
64
|
}
|
package/index.html
DELETED
@@ -1,231 +0,0 @@
|
|
1
|
-
<!doctype html>
|
2
|
-
<html lang=zh-CN>
|
3
|
-
<meta charset=UTF-8>
|
4
|
-
<meta content=width=device-width,initial-scale=1,maximum-scale=2 name=viewport>
|
5
|
-
<meta content=#222 name=theme-color>
|
6
|
-
<meta content=IE=edge,chrome=1 http-equiv=X-UA-COMPATIBLE>
|
7
|
-
<meta content=webkit name=renderer>
|
8
|
-
<link href=/assets/favicon.ico rel=icon sizes=32x32 type=image/ico>
|
9
|
-
<link href=/assets/apple-touch-icon.png rel=apple-touch-icon sizes=180x180>
|
10
|
-
<link href=/rss.xml rel=alternate title=GreyFlowers type=application/rss+xml>
|
11
|
-
<link href=/atom.xml rel=alternate title=GreyFlowers type=application/atom+xml>
|
12
|
-
<link href=https://nonhana.xyz/feed.json rel=alternate title=GreyFlowers type=application/json>
|
13
|
-
<link href=https://lf9-cdn-tos.bytecdntp.com rel=preconnect>
|
14
|
-
<link href=https://at.alicdn.com rel=preconnect>
|
15
|
-
<link href=https://cdn.jsdelivr.net rel=dns-prefetch>
|
16
|
-
<link href=https://unpkg.com rel=dns-prefetch>
|
17
|
-
<link
|
18
|
-
href=https://fonts.googleapis.com/css?family=Mulish:400,400italic,700,700italic%7CFredericka%20the%20Great:400,400italic,700,700italic%7CNoto%20Serif%20JP:400,400italic,700,700italic%7CNoto%20Serif%20SC:400,400italic,700,700italic%7CInconsolata:400,400italic,700,700italic&display=swap&subset=latin,latin-ext
|
19
|
-
media=none onload=this.media='all' rel=stylesheet>
|
20
|
-
<link href=/css/app.css?v=0.4.2 rel=stylesheet>
|
21
|
-
<link href=/js/chunk-3TKMULNZ.js rel=modulepreload>
|
22
|
-
<link href=/js/chunk-ALTFCWXU.js rel=modulepreload>
|
23
|
-
<link href=/js/chunk-HUVUXQZN.js rel=modulepreload>
|
24
|
-
<link href=/js/chunk-O2BCNOI6.js rel=modulepreload>
|
25
|
-
<link href=/js/index.esm-AYEYICKY.js rel=modulepreload>
|
26
|
-
<link href=/js/post-S7W6Y2IZ.js rel=modulepreload>
|
27
|
-
<link href=/js/quicklink-FI56VDOX.js rel=modulepreload>
|
28
|
-
<link href=/js/search-TIKH35P2.js rel=modulepreload>
|
29
|
-
<link href=/js/siteInit.js rel=modulepreload>
|
30
|
-
<link as=image fetchpriority=high
|
31
|
-
href=https://common-1319721118.cos.ap-shanghai.myqcloud.com/grey-flowers/1%20%283%29.png rel=preload>
|
32
|
-
<link as=image fetchpriority=high href=https://common-1319721118.cos.ap-shanghai.myqcloud.com/grey-flowers/115011844.jpg
|
33
|
-
rel=preload>
|
34
|
-
<link as=image fetchpriority=high
|
35
|
-
href=https://common-1319721118.cos.ap-shanghai.myqcloud.com/grey-flowers/1%20%282%29.jpg rel=preload>
|
36
|
-
<link as=image fetchpriority=high href=https://common-1319721118.cos.ap-shanghai.myqcloud.com/grey-flowers/115495470.png
|
37
|
-
rel=preload>
|
38
|
-
<link as=image fetchpriority=high
|
39
|
-
href=https://common-1319721118.cos.ap-shanghai.myqcloud.com/grey-flowers/1%20%287%29.png rel=preload>
|
40
|
-
<link as=image fetchpriority=high
|
41
|
-
href=https://common-1319721118.cos.ap-shanghai.myqcloud.com/grey-flowers/0%20%284%29.png rel=preload>
|
42
|
-
<meta content=前端,Vite-SSG,SSG, name=keywords>
|
43
|
-
<meta content=不要为每一件事都赋予意义。 name=description>
|
44
|
-
<link
|
45
|
-
href=https://nonhana.xyz/2024/01/31/daily-developing/%E6%80%8E%E4%B9%88%E5%9C%A8Vue3%E4%B8%AD%E5%BC%95%E5%85%A5Vite-SSG%E6%89%93%E5%8C%85/ rel=canonical>
|
46
|
-
<title>怎么在Vue3中引入Vite-SSG打包</title>
|
47
|
-
<meta content="Hexo 7.0.0" name=generator>
|
48
|
-
<body itemscope itemtype=http://schema.org/WebPage>
|
49
|
-
<div id=loading>
|
50
|
-
<div class=cat>
|
51
|
-
<div class=body></div>
|
52
|
-
<div class=head>
|
53
|
-
<div class=face></div>
|
54
|
-
</div>
|
55
|
-
<div class=foot>
|
56
|
-
<div class=tummy-end></div>
|
57
|
-
<div class=bottom></div>
|
58
|
-
<div class="legs left"></div>
|
59
|
-
<div class="legs right"></div>
|
60
|
-
</div>
|
61
|
-
<div class=paw>
|
62
|
-
<div class="hands left"></div>
|
63
|
-
<div class="hands right"></div>
|
64
|
-
</div>
|
65
|
-
</div>
|
66
|
-
</div>
|
67
|
-
<div id=container>
|
68
|
-
<header id=header itemscope itemtype=http://schema.org/WPHeader>
|
69
|
-
<div class=inner>
|
70
|
-
<div id=brand>
|
71
|
-
<div class=pjax><h1 itemprop="name headline">怎么在Vue3中引入Vite-SSG打包</h1>
|
72
|
-
<div class=meta><span title="创建时间:2024-01-31 14:22:42" class=item><span class=icon><i
|
73
|
-
class="ic i-calendar"></i></span><span class=text>发表于</span><time itemprop="dateCreated datePublished"
|
74
|
-
datetime=2024-01-31T14:22:42+08:00>2024-01-31</time></span><span
|
75
|
-
class=item title=本文字数><span class=icon><i class="ic i-pen"></i></span><span
|
76
|
-
class=text>本文字数</span><span>14k</span><span class=text>字</span></span><span class=item
|
77
|
-
title=阅读时长><span
|
78
|
-
class=icon><i class="ic i-clock"></i></span><span class=text>阅读时长</span><span>13 分钟</span></span>
|
79
|
-
</div>
|
80
|
-
</div>
|
81
|
-
</div>
|
82
|
-
<nav id=nav>
|
83
|
-
<div class=inner>
|
84
|
-
<div class=toggle>
|
85
|
-
<div aria-label=切换导航栏 class=lines><span class=line></span><span class=line></span><span
|
86
|
-
class=line></span></div>
|
87
|
-
</div>
|
88
|
-
<ul class=menu>
|
89
|
-
<li class="item title"><a href=/ rel=start>hana's blog</a>
|
90
|
-
</ul>
|
91
|
-
<ul class=right id=rightNav>
|
92
|
-
<li class="item theme"><i class="ic i-sun"></i>
|
93
|
-
<li class="item search"><i class="ic i-search"></i>
|
94
|
-
</ul>
|
95
|
-
</div>
|
96
|
-
</nav>
|
97
|
-
</div>
|
98
|
-
<div class=pjax id=imgs>
|
99
|
-
<ul>
|
100
|
-
<li
|
101
|
-
style='background-image: url("https://common-1319721118.cos.ap-shanghai.myqcloud.com/grey-flowers/1%20%283%29.png");'
|
102
|
-
class=item>
|
103
|
-
<li
|
104
|
-
style='background-image: url("https://common-1319721118.cos.ap-shanghai.myqcloud.com/grey-flowers/115011844.jpg");'
|
105
|
-
class=item>
|
106
|
-
<li
|
107
|
-
style='background-image: url("https://common-1319721118.cos.ap-shanghai.myqcloud.com/grey-flowers/1%20%282%29.jpg");'
|
108
|
-
class=item>
|
109
|
-
<li
|
110
|
-
style='background-image: url("https://common-1319721118.cos.ap-shanghai.myqcloud.com/grey-flowers/115495470.png");'
|
111
|
-
class=item>
|
112
|
-
<li
|
113
|
-
style='background-image: url("https://common-1319721118.cos.ap-shanghai.myqcloud.com/grey-flowers/1%20%287%29.png");'
|
114
|
-
class=item>
|
115
|
-
<li
|
116
|
-
style='background-image: url("https://common-1319721118.cos.ap-shanghai.myqcloud.com/grey-flowers/0%20%284%29.png");'
|
117
|
-
class=item>
|
118
|
-
</ul>
|
119
|
-
</div>
|
120
|
-
</header>
|
121
|
-
<div id=waves>
|
122
|
-
<svg viewbox="0 24 150 28" class=waves preserveaspectratio=none shape-rendering=auto
|
123
|
-
xmlns=http://www.w3.org/2000/svg xmlns:xlink=http://www.w3.org/1999/xlink>
|
124
|
-
<defs>
|
125
|
-
<path d="M-160 44c30 0 58-18 88-18s 58 18 88 18 58-18 88-18 58 18 88 18 v44h-352z" id=gentle-wave></path>
|
126
|
-
</defs>
|
127
|
-
<g class=parallax>
|
128
|
-
<use x=48 xlink:href=#gentle-wave y=0></use>
|
129
|
-
<use x=48 xlink:href=#gentle-wave y=3></use>
|
130
|
-
<use x=48 xlink:href=#gentle-wave y=5></use>
|
131
|
-
<use x=48 xlink:href=#gentle-wave y=7></use>
|
132
|
-
</g>
|
133
|
-
</svg>
|
134
|
-
</div>
|
135
|
-
<main>
|
136
|
-
<div class=inner>
|
137
|
-
<div class=pjax id=main>
|
138
|
-
<div class="article wrap">
|
139
|
-
<div class=breadcrumb itemlistelement itemscope itemtype=https://schema.org/BreadcrumbList><i
|
140
|
-
class="ic i-home"></i><span></span><i class="ic i-angle-right"></i><span class=current
|
141
|
-
itemprop=itemListElement
|
142
|
-
itemscope
|
143
|
-
itemtype=https://schema.org/ListItem><a
|
144
|
-
href=/categories/daily-developing/ itemprop=item rel=index title=分类于一些日常开发积累><span itemprop=name>一些日常开发积累<meta
|
145
|
-
content=0 itemprop=position></span></a></span></div>
|
146
|
-
<article class="post block" itemscope itemtype=http://schema.org/Article lang=zh-CN>
|
147
|
-
<link
|
148
|
-
href=https://nonhana.xyz/2024/01/31/daily-developing/%E6%80%8E%E4%B9%88%E5%9C%A8Vue3%E4%B8%AD%E5%BC%95%E5%85%A5Vite-SSG%E6%89%93%E5%8C%85/ itemprop=mainEntityOfPage>
|
149
|
-
<span hidden itemprop=author itemscope itemtype=http://schema.org/Person><meta content=/assets/avatar.jpg
|
150
|
-
itemprop=image><meta
|
151
|
-
content=non_hana itemprop=name><meta content="『灰色的花终会绽放。』, 不要为每一件事都赋予意义。"
|
152
|
-
itemprop=description></span><span hidden itemprop=publisher itemscope
|
153
|
-
itemtype=http://schema.org/Organization><meta
|
154
|
-
content=GreyFlowers itemprop=name></span>
|
155
|
-
<div class="body md" itemprop=articleBody><h1 id=一-前言><a class=anchor href=#一-前言>#</a> 一、前言</h1>
|
156
|
-
<p>公司目前由我负责的主要有两个网页项目:
|
157
|
-
<ol>
|
158
|
-
<li>一个官网首页,纯做数据展示的;
|
159
|
-
<li>一个官网课程资源页,用户能够点击进入课程页面,并能够阅读课程的 md 文档教程。
|
160
|
-
</ol>
|
161
|
-
<p>这两个项目都是非常单纯的通过 <code>npm init vite@latest</code> 创建的 Vue3+TS 项目,并且其中也都引入了目前非常流行的
|
162
|
-
ElementPlus 作为组件库。
|
163
|
-
<p>目前多了一个新的需求:要交给我进行 <strong>SEO</strong> ,也就是 <strong>搜索引擎优化</strong>
|
164
|
-
。在这边先暂且列一些给 Vue+Vite 项目做 SEO 的一些常见方式吧:
|
165
|
-
<ol>
|
166
|
-
<li><strong>服务器端渲染 (SSR)</strong>: 由于 Vue 是一个客户端渲染的 JavaScript 框架,搜索引擎在抓取页面时可能不会执行
|
167
|
-
JavaScript,导致内容无法被索引。通过服务器端渲染,可以提前在服务器上生成页面的 HTML,确保搜索引擎能够抓取到页面的内容。
|
168
|
-
<li><strong>预渲染 (Pre-rendering)</strong>: 对于静态内容较多的站点,可以使用预渲染。这意味着在构建过程中为每个路由生成静态的
|
169
|
-
HTML 文件。这可以通过像 <code>vite-plugin-ssr</code> 这样的插件来实现。
|
170
|
-
<li><strong>使用合适的元标签 (Meta tags)</strong>: 确保每个页面都有恰当的 <code><title></code> 和
|
171
|
-
<code><meta></code> 描述标签,这些都是搜索引擎用来了解页面内容的重要信息。可以使用像
|
172
|
-
<code>vue-meta</code> 这样的库来在 Vue 组件中管理这些标签。
|
173
|
-
<li><strong>路由优化</strong>:使用基于历史的路由( <code>history mode</code> )而不是哈希路由( <code>hash
|
174
|
-
mode</code> )。这样可以确保每个页面都有一个干净且易于索引的 URL。
|
175
|
-
<li><strong>生成网站地图 (Sitemap)</strong>: 为网站生成一个 sitemap.xml,帮助搜索引擎更好地索引网站内容。
|
176
|
-
<li><strong>使用无障碍标准 (Accessibility)</strong>: 确保网站符合无障碍标准,这不仅对用户友好,也有助于提高
|
177
|
-
SEO 排名。
|
178
|
-
</ol>
|
179
|
-
<p>当然,上面的这几种方式都是报菜名罢了。我们公司的技术负责人和我经过一些调研和讨论之后,最终选定了 <strong>静态站点生成(SSG,
|
180
|
-
Static Site Generation)</strong> 来对我们的项目进行 SEO。为什么选择 SSG 呢?因为我们目前的项目都是偏向于
|
181
|
-
<strong>数据呈现</strong> 而与用于在实际应用层面上的交互相对比较少,也就是比较偏向于
|
182
|
-
<strong>静态页面</strong> 。
|
183
|
-
<p>再次基础上,我们选择了 <code>Vite-SSG</code> 这个插件作为我们进行 SSG 打包的工具。
|
184
|
-
<h1 id=二-vite-ssg-是什么><a class=anchor href=#二-vite-ssg-是什么>#</a> 二、Vite-SSG 是什么?</h1>
|
185
|
-
<p>Vite-SSG(Static Site Generation)是一个基于 Vite 的工具,用于生成静态站点。它专门为 Vue.js
|
186
|
-
应用程序设计,提供了一个高效的方式来构建静态生成的网站。 Vite-SSG 有几个主要关键特点:
|
187
|
-
<ol>
|
188
|
-
<li><strong>静态站点生成</strong>:Vite-SSG 生成的是静态 HTML 文件。这意味着的网站可以作为静态文件部署在任何标准的
|
189
|
-
web 服务器或静态文件托管服务上。
|
190
|
-
<li><strong>基于 Vite</strong>:作为 Vite 的一个扩展,Vite-SSG 充分利用了 Vite
|
191
|
-
的快速冷启动和即时模块热更新(HMR)等特性,提供了快速的开发体验。
|
192
|
-
<li><strong>Vue.js 支持</strong>:Vite-SSG 是为 Vue.js 应用程序设计的。它支持 Vue 3,允许利用 Vue.js
|
193
|
-
的全功能集,包括组件、路由、状态管理等,也可以让在原本已经开发完成的 Vue 项目中引入。
|
194
|
-
<li><strong>服务器端渲染(SSR)友好</strong>:虽然 Vite-SSG 重点是静态站点生成,但它也支持和优化了服务器端渲染的相关特性,使得生成的站点可以更好地支持
|
195
|
-
SEO 和首次加载性能。
|
196
|
-
<li><strong>客户端激活</strong>:生成的静态页面在客户端被 Vue.js
|
197
|
-
“激活”,从而变成一个完全功能的单页面应用(SPA)。这使得在初始的快速加载和后续的丰富交互之间取得了很好的平衡。
|
198
|
-
<li><strong>灵活性和可扩展性</strong>:Vite-SSG 允许自定义配置,包括路由、预渲染行为、插件等,使得可以根据项目需求调整和优化。
|
199
|
-
</ol>
|
200
|
-
<p>Vite-SSG 适用于需要快速静态内容加载,同时在客户端提供丰富交互的网站。这包括博客、企业官网、产品展示网站、文档站点等。同时,对于需要良好搜索引擎优化(SEO)的站点,Vite-SSG
|
201
|
-
也是一个很好的选择。
|
202
|
-
<h1 id=三-在开发完成的项目中进行配置><a class=anchor href=#三-在开发完成的项目中进行配置>#</a>
|
203
|
-
三、在开发完成的项目中进行配置</h1>
|
204
|
-
<p>按照一般的开发流程开发完成之后,就需要先引入 Vite-SSG 的插件,并对整个项目的关键配置项进行修改,最后运行打包,逐一排查错误并修复。
|
205
|
-
<h2 id=安装插件><a class=anchor href=#安装插件>#</a> 安装插件</h2>
|
206
|
-
<p>先安装 Vite-SSG 插件:
|
207
|
-
<figure class="highlight bash">
|
208
|
-
<figcaption data-lang=bash></figcaption>
|
209
|
-
<table>
|
210
|
-
<tr>
|
211
|
-
<td data-num=1>
|
212
|
-
<td>
|
213
|
-
<pre><span class="token function">npm</span> i <span class="token parameter variable">-D</span> vite-ssg</pre>
|
214
|
-
</table>
|
215
|
-
</figure>
|
216
|
-
<h2 id=修改配置文件><a class=anchor href=#修改配置文件>#</a> 修改配置文件</h2>
|
217
|
-
<h3 id=packagejson><a class=anchor href=#packagejson>#</a> package.json</h3>
|
218
|
-
<p>安装完成后,修改 <code>package.json</code> 中的 build 指令:
|
219
|
-
<figure class="highlight diff">
|
220
|
-
<figcaption data-lang=diff></figcaption>
|
221
|
-
<table>
|
222
|
-
<tr>
|
223
|
-
<td data-num=1>
|
224
|
-
<td>
|
225
|
-
<pre>{</pre>
|
226
|
-
<tr>
|
227
|
-
<td data-num=2>
|
228
|
-
<td><pre><span class="token unchanged"><span class="token prefix unchanged"> </span> "scripts": {<tr><td
|
229
|
-
data-num=3><td><pre><span class="token prefix unchanged"> </span> "dev": "vite",</pre><tr><td
|
230
|
-
data-num=4><td><pre><span class="token deleted-sign deleted"><span
|
231
|
-
class="token prefix deleted">-</span></span></pre></td></tr></span></pre></td>
|