1- import { createWriteStream } from 'node:fs' ;
2- import { resolve } from 'node:path' ;
3- import { SitemapStream } from 'sitemap' ;
41import { defineConfig } from 'vitepress' ;
52
6- const links : { url : string ; lastmod : number } [ ] = [ ] ;
3+ const SITE_URL = 'https://www.spiritlhl.net' ;
4+
5+ function toSitePath ( relativePath : string ) {
6+ return `/${ relativePath } `
7+ . replace ( / \/ i n d e x \. m d $ / , '/' )
8+ . replace ( / \. m d $ / , '.html' ) ;
9+ }
10+
11+ function toCanonicalUrl ( relativePath : string ) {
12+ return new URL ( toSitePath ( relativePath ) , `${ SITE_URL } /` ) . toString ( ) ;
13+ }
14+
15+ function getDefaultTitle ( relativePath : string ) {
16+ return relativePath . startsWith ( 'en/' )
17+ ? 'OneClickVirt'
18+ : '一键虚拟化项目' ;
19+ }
20+
21+ function getLocaleCode ( relativePath : string ) {
22+ return relativePath . startsWith ( 'en/' ) ? 'en_US' : 'zh_CN' ;
23+ }
724
825export default defineConfig ( {
926 lastUpdated : true ,
1027 lang : 'zh-CN' ,
28+ sitemap : {
29+ hostname : SITE_URL ,
30+ transformItems ( items ) {
31+ return items . filter ( ( item ) => ! / \/ 4 0 4 (?: \. h t m l ) ? $ / . test ( item . url ) ) ;
32+ } ,
33+ } ,
1134 markdown : {
1235 lineNumbers : true ,
1336 image : {
1437 lazyLoading : true ,
1538 } ,
1639 } ,
17- transformHtml : ( _ , id , { pageData } ) => {
18- if ( ! / [ \\ / ] 4 0 4 \. h t m l $ / . test ( id ) ) {
19- links . push ( {
20- url : pageData . relativePath . replace ( / \/ i n d e x \. m d $ / , '/' ) . replace ( / \. m d $ / , '.html' ) ,
21- lastmod : pageData . lastUpdated ?? Date . now ( ) ,
22- } ) ;
40+ transformPageData ( pageData ) {
41+ if ( pageData . relativePath === '404.md' ) {
42+ return ;
43+ }
44+
45+ const canonicalUrl = toCanonicalUrl ( pageData . relativePath ) ;
46+ const title = pageData . title || getDefaultTitle ( pageData . relativePath ) ;
47+ const description = pageData . description || '' ;
48+
49+ pageData . frontmatter . head ??= [ ] ;
50+ pageData . frontmatter . head . push (
51+ [ 'link' , { rel : 'canonical' , href : canonicalUrl } ] ,
52+ [ 'meta' , { property : 'og:type' , content : 'article' } ] ,
53+ [ 'meta' , { property : 'og:site_name' , content : getDefaultTitle ( pageData . relativePath ) } ] ,
54+ [ 'meta' , { property : 'og:locale' , content : getLocaleCode ( pageData . relativePath ) } ] ,
55+ [ 'meta' , { property : 'og:title' , content : title } ] ,
56+ [ 'meta' , { property : 'og:url' , content : canonicalUrl } ] ,
57+ [ 'meta' , { name : 'twitter:card' , content : 'summary_large_image' } ] ,
58+ [ 'meta' , { name : 'twitter:title' , content : title } ] ,
59+ ) ;
60+
61+ if ( description ) {
62+ pageData . frontmatter . head . push (
63+ [ 'meta' , { property : 'og:description' , content : description } ] ,
64+ [ 'meta' , { name : 'twitter:description' , content : description } ] ,
65+ ) ;
2366 }
24- } ,
25- buildEnd : async ( { outDir } ) => {
26- const sitemap = new SitemapStream ( {
27- hostname : 'https://www.spiritlhl.net/'
28- } ) ;
29- const writeStream = createWriteStream ( resolve ( outDir , 'sitemap.xml' ) ) ;
30- sitemap . pipe ( writeStream ) ;
31- links . forEach ( ( link ) => sitemap . write ( link ) ) ;
32- sitemap . end ( ) ;
33- await new Promise ( ( r ) => writeStream . on ( 'finish' , r ) ) ;
3467 } ,
3568 head : [
3669 [ 'link' , { rel : 'icon' , href : 'https://cdn.spiritlhl.net/https://raw.githubusercontent.com/spiritlhls/pages/main/logo.png' } ] ,
@@ -125,7 +158,7 @@ export default defineConfig({
125158 en : {
126159 lang : 'en-US' ,
127160 label : 'English' ,
128- title : 'One Click Virtualization ' ,
161+ title : 'OneClickVirt ' ,
129162 description : 'Open source, easy to use server virtualization project' ,
130163 link : '/en/' ,
131164 themeConfig : {
@@ -142,7 +175,7 @@ export default defineConfig({
142175 externalLinkIcon : true ,
143176 nav : [
144177 {
145- text : 'Virtualization Platforms' ,
178+ text : 'Platforms' ,
146179 activeMatch : '^/en/guide/' ,
147180 items : [
148181 { text : 'OneClickVirt' , link : '/en/guide/oneclickvirt/oneclickvirt_precheck.html' } ,
@@ -158,7 +191,7 @@ export default defineConfig({
158191 ]
159192 } ,
160193 {
161- text : 'Other Virtualization Projects' ,
194+ text : 'Other Projects' ,
162195 activeMatch : '^/en/incomplete/' ,
163196 items : [
164197 { text : 'webvirtcloud' , link : '/en/incomplete/webvirtcloud.html' } ,
@@ -173,7 +206,7 @@ export default defineConfig({
173206 ]
174207 } ,
175208 {
176- text : 'Utility Projects ' ,
209+ text : 'Utilities ' ,
177210 activeMatch : '^/en/case/' ,
178211 items : [
179212 { text : '1. ECS benchmark script for VPS' , link : '/en/case/case1.html' } ,
@@ -207,14 +240,17 @@ export default defineConfig({
207240 } ,
208241 themeConfig : {
209242 outline : 'deep' ,
243+ search : {
244+ provider : 'algolia' ,
245+ options : {
246+ appId : 'K1R85MDU0C' ,
247+ apiKey : '9375787ec1c00e2b813683fbbde25ae2' ,
248+ indexName : 'virt-spiritlhl'
249+ }
250+ } ,
210251 socialLinks : [
211252 { icon : 'github' , link : 'https://github.com/oneclickvirt' }
212253 ] ,
213- algolia : {
214- appId : 'K1R85MDU0C' ,
215- apiKey : '9375787ec1c00e2b813683fbbde25ae2' ,
216- indexName : 'virt-spiritlhl'
217- } ,
218254 footer : {
219255 message : 'Under <a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/4.0/">(CC BY-NC-SA 4.0) License.</a><br>Also thanks to <a href="https://www.cloudflare.com/">Cloudflare</a> and <a href="https://blog.tanglu.me/">tanglu.me</a> for the CDN.' ,
220256 copyright : 'Copyright © 2022-present oneclickvirt'
@@ -282,7 +318,7 @@ function getGuideSidebarZhCN() {
282318 { text : 'Docker主体安装' , link : '/guide/docker/docker_install.html' } ,
283319 { text : 'Linux容器(LXC)' , link : '/guide/docker/docker_build.html' } ,
284320 { text : 'Windows虚拟机(KVM/QEMU)' , link : '/guide/docker/docker_windows.html' } ,
285- { text : 'Macos虚拟机 (KVM)' , link : '/guide/docker/docker_macos.html' } ,
321+ { text : 'macOS虚拟机 (KVM)' , link : '/guide/docker/docker_macos.html' } ,
286322 { text : 'Android虚拟机(KVM/QEMU)' , link : '/guide/docker/docker_android.html' } ,
287323 { text : '自定义' , link : '/guide/docker/docker_custom.html' } ,
288324 { text : '致谢' , link : '/guide/docker/docker_thanks.html' } ,
@@ -479,7 +515,7 @@ function getGuideSidebarEnUS() {
479515 { text : 'Docker main installation' , link : '/en/guide/docker/docker_install.html' } ,
480516 { text : 'Linux Container(LXC)' , link : '/en/guide/docker/docker_build.html' } ,
481517 { text : 'Windows Virtual Machine(KVM/QEMU)' , link : '/en/guide/docker/docker_windows.html' } ,
482- { text : 'Macos Virtual Machine(KVM)' , link : '/en/guide/docker/docker_macos.html' } ,
518+ { text : 'macOS Virtual Machine(KVM)' , link : '/en/guide/docker/docker_macos.html' } ,
483519 { text : 'Android Virtual Machine(KVM/QEMU)' , link : '/en/guide/docker/docker_android.html' } ,
484520 { text : 'Custom' , link : '/en/guide/docker/docker_custom.html' } ,
485521 { text : 'Acknowledgements' , link : '/en/guide/docker/docker_thanks.html' } ,
@@ -551,9 +587,9 @@ function getGuideSidebarEnUS() {
551587 items : [
552588 { text : 'via iptables' , link : '/en/guide/block/block_iptables.html' } ,
553589 { text : 'In PVE' , link : '/en/guide/block/block_pve.html' } ,
554- { text : 'In INCUS ' , link : '/en/guide/block/block_incus.html' } ,
590+ { text : 'In Incus ' , link : '/en/guide/block/block_incus.html' } ,
555591 { text : 'In LXD' , link : '/en/guide/block/block_lxd.html' } ,
556- { text : 'In DOCKER ' , link : '/en/guide/block/block_docker.html' } ,
592+ { text : 'In Docker ' , link : '/en/guide/block/block_docker.html' } ,
557593 ]
558594 } ,
559595 {
0 commit comments