Skip to content

Commit 72f42e5

Browse files
committed
feat: update readme
1 parent 6e10340 commit 72f42e5

2 files changed

Lines changed: 41 additions & 7 deletions

File tree

README.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
11
# PicGo-Doc
22

3-
PicGo 的官方文档 -> https://picgo.github.io/PicGo-Doc/
4-
5-
## 贡献指南
6-
7-
非常欢迎你为 PicGo-Doc 做出贡献!发起贡献之前,请确保阅读了[贡献指南](/CONTRIBUTING.md)
3+
Archived repository for PicGo documentation. The latest documentation can be found at [https://docs.picgo.app/gui/](https://docs.picgo.app/gui/).

docs/.vitepress/config.mts

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,37 @@
1+
import { defineConfig } from 'vitepress'
12
import type { DefaultTheme } from 'vitepress'
23
import { getNestedSidebarItems } from './utils/sidebar'
34

45
const EDIT_LINK_PATTERN = 'https://github.com/PicGo/PicGo-Doc/edit/master/docs/:path'
6+
const NEW_SITE_ORIGIN = 'https://docs.picgo.app'
7+
const NEW_SECTION_BASE = '/gui/'
8+
const LEGACY_BASE = '/PicGo-Doc/'
9+
10+
const normalizeRelativePath = (relativePath: string): { localePrefix: string; path: string } => {
11+
const withoutExt = relativePath.replace(/\.md$/, '')
12+
const isZh = withoutExt.startsWith('zh/')
13+
const localePrefix = isZh ? '/zh' : ''
14+
const localizedPath = isZh ? withoutExt.slice(3) : withoutExt
15+
16+
if (!localizedPath || localizedPath === 'index') {
17+
return { localePrefix, path: '' }
18+
}
19+
20+
if (localizedPath.endsWith('/index')) {
21+
return { localePrefix, path: `${localizedPath.slice(0, -'/index'.length)}/` }
22+
}
23+
24+
return { localePrefix, path: localizedPath }
25+
}
26+
27+
const buildCanonicalUrl = (relativePath: string): string => {
28+
const { localePrefix, path } = normalizeRelativePath(relativePath)
29+
const base = `${NEW_SITE_ORIGIN}${localePrefix}${NEW_SECTION_BASE}`
30+
const normalizedPath = path.replace(/^\/+/, '')
31+
return `${base}${normalizedPath}`
32+
}
33+
34+
const buildRedirectScript = (): string => `\n(function() {\n var newHost = '${NEW_SITE_ORIGIN}';\n var sectionBase = '${NEW_SECTION_BASE}';\n var oldBase = '${LEGACY_BASE}';\n var path = window.location.pathname || '/';\n\n if (path.startsWith(oldBase)) {\n path = path.slice(oldBase.length);\n } else {\n path = path.replace(/^\\/+/, '');\n }\n\n var isZh = path.startsWith('zh/');\n if (isZh) {\n path = path.slice(3);\n }\n\n if (path === '' || path === 'index.html') {\n path = '';\n } else if (path.endsWith('/index.html')) {\n path = path.slice(0, -'/index.html'.length) + '/';\n } else if (path.endsWith('.html')) {\n path = path.slice(0, -'.html'.length);\n }\n\n if (path.startsWith('/')) {\n path = path.slice(1);\n }\n\n var newUrl = newHost + (isZh ? '/zh' : '') + sectionBase + path + window.location.search + window.location.hash;\n if (newUrl !== window.location.href) {\n window.location.replace(newUrl);\n }\n})();\n`
535

636
const commonNavList = [
737
{
@@ -83,7 +113,7 @@ const enThemeConfig = {
83113
}
84114
} as const
85115

86-
export default {
116+
export default defineConfig({
87117
title: 'PicGo',
88118
description: 'New Experience of Pictures Uploading and Management',
89119
base: '/PicGo-Doc/',
@@ -97,6 +127,14 @@ export default {
97127
}
98128
],
99129
],
130+
transformHead: ({ pageData }) => {
131+
const canonicalUrl = buildCanonicalUrl(pageData.relativePath)
132+
return [
133+
['link', { rel: 'canonical', href: canonicalUrl }],
134+
['meta', { 'http-equiv': 'refresh', content: `0;url=${canonicalUrl}` }],
135+
['script', {}, buildRedirectScript()]
136+
]
137+
},
100138
sitemap: {
101139
hostname: 'https://picgo.github.io/PicGo-Doc/'
102140
},
@@ -177,4 +215,4 @@ export default {
177215
themeConfig: zhThemeConfig
178216
}
179217
}
180-
}
218+
})

0 commit comments

Comments
 (0)