Skip to content

Commit

Permalink
refactor: manual update (#250)
Browse files Browse the repository at this point in the history
About #244
  • Loading branch information
jiazengp authored May 9, 2024
2 parents 87c1c88 + 3b3ba5f commit 4afcd5f
Show file tree
Hide file tree
Showing 229 changed files with 794 additions and 3,282 deletions.
5 changes: 0 additions & 5 deletions .github/translation-guide.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
---
layout: doc
titleTemplate: Kongying Tavern
---

# Genshin Interactive Map Community Translation Guidelines

If you are here, you are likely interested in contributing to the translation of the Genshin Interactive Map documentation. Thank you! Before you start, make sure to read the following guidelines to get an understanding of the workflow.
Expand Down
232 changes: 124 additions & 108 deletions .vitepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,18 @@ import Unocss from 'unocss/vite'
import MarkdownItFootnote from 'markdown-it-footnote'
import MarkdownItKbd from 'markdown-it-kbd-better'
import { fileURLToPath, URL } from 'node:url'
import { defineConfig, HeadConfig } from 'vitepress'
import { defineConfig } from 'vitepress'
import type {
DefaultTheme,
HeadConfig,
PageData,
SiteConfig,
UserConfig,
LocaleSpecificConfig,
TransformContext,
TransformPageContext,
} from 'vitepress'
import type { CustomConfig } from './locales/types'
import { colorPreviewPlugin } from './theme/markdown/colorPreview'
import { cardPlugin } from './theme/markdown/card'
import { figure } from '@mdit/plugin-figure'
Expand All @@ -15,11 +26,10 @@ import { timeline } from './theme/markdown/timeline'
import { enConfig } from './locales/en'
import { zhConfig } from './locales/zh'
import { jaConfig } from './locales/ja'
import { frConfig } from './locales/fr'

export const isProd = process.env.NODE_ENV === 'production'
export const commitRef = process.env.COMMIT_REF?.slice(0, 8) || 'dev'
export const productionHead: HeadConfig[] = [
const isProd = process.env.NODE_ENV === 'production'
const commitRef = process.env.COMMIT_REF?.slice(0, 8) || 'dev'
const productionHead: HeadConfig[] = [
[
'script',
{
Expand All @@ -43,6 +53,114 @@ export const productionHead: HeadConfig[] = [
],
]

type ConfigureFuncType = Pick<
UserConfig<DefaultTheme.Config>,
'transformHead' | 'transformPageData'
>
type LocaleConfigVal = LocaleSpecificConfig<DefaultTheme.Config & CustomConfig>

const cfgGetPageUrl = (pageData: PageData, siteConfig: SiteConfig): string =>
`https://yuanshen.site/${siteConfig.site.base}${pageData.relativePath.replace('.md', '')}`
const cfgGetPageTitle = (pageData: PageData, siteConfig: SiteConfig): string =>
pageData.frontmatter.title ? pageData.frontmatter.title : 'Kongying Tavern'
const cfgGetPageDesc = (pageData: PageData, siteConfig: SiteConfig): string =>
pageData.frontmatter.description
? pageData.frontmatter.description
: `Genshin Interactive Map\nA Completionist's Interactive Map by Kongying Tavern`
const cfgGetPageKeywords = (
pageData: PageData,
siteConfig: SiteConfig,
): string =>
pageData.frontmatter.keywords
? pageData.frontmatter.keywords
: '空荧酒馆,空荧地图,空荧酒馆原神地图,原神全资源攻略地图,原神攻略地图,原神地图,原神电子地图,原神互动地图,Genshin,Genshin_map,Genshin_Treasure,Genshin Map,Genshin Impact Map,Genshin Impact Interactive Map'
const cfgGetPageCover = (pageData: PageData, siteConfig: SiteConfig): string =>
pageData.frontmatter.image
? pageData.frontmatter.image
: 'https://yuanshen.site/docs/imgs/common/cover.jpg'

const cfgDynamicHead = (pageData: PageData, siteConfig: SiteConfig): void => {
if (!isProd) return

const pageUrl = cfgGetPageUrl(pageData, siteConfig)
const pageTitle = cfgGetPageTitle(pageData, siteConfig)
const pageDesc = cfgGetPageDesc(pageData, siteConfig)
const pageKeywords = cfgGetPageKeywords(pageData, siteConfig)
const pageCover = cfgGetPageCover(pageData, siteConfig)

const head: any = [
['meta', { name: 'og:url', content: pageUrl }],
['meta', { name: 'twitter:url', content: pageUrl }],
['meta', { name: 'og:title', content: pageTitle }],
['meta', { name: 'twitter:title', content: pageTitle }],
['meta', { name: 'og:description', content: pageDesc }],
['meta', { name: 'twitter:description', content: pageDesc }],
['meta', { name: 'description', content: pageDesc }],
['meta', { name: 'keywords', content: pageKeywords }],
['meta', { name: 'og:image', content: pageCover }],
['meta', { name: 'twitter:image', content: pageCover }],
]

pageData.frontmatter.head ??= []
pageData.frontmatter.head.splice(Infinity, 0, ...head)
}
const cfgDynamicTitleTemplate = (
pageData: PageData,
siteConfig: SiteConfig,
): void => {
let titleTemplate: string | boolean =
pageData.frontmatter.titleTemplate ?? siteConfig.userConfig.titleTemplate
if (titleTemplate === null || titleTemplate === undefined) {
const localeKey: string =
pageData.relativePath === pageData.filePath
? pageData.relativePath.split('/', 1)[0]
: 'root'
const localeConfig: LocaleConfigVal =
siteConfig.userConfig.locales![localeKey] ?? {}
const templateMappings: CustomConfig['ui']['title']['templateMappings'] =
localeConfig.themeConfig?.ui.title.templateMappings ?? []
for (let templateMapping of templateMappings) {
if (
templateMapping.test &&
templateMapping.test.test(pageData.relativePath)
) {
titleTemplate = templateMapping.template
break
}
}
}
pageData.titleTemplate = titleTemplate
}

const createConfigureFunction = (): ConfigureFuncType => {
if (isProd) {
return {
transformHead: (context: TransformContext) => {
const { pageData, siteConfig } = context
cfgDynamicHead(pageData, siteConfig)
},
transformPageData: (
pageData: PageData,
context: TransformPageContext,
) => {
const { siteConfig } = context
cfgDynamicTitleTemplate(pageData, siteConfig)
},
}
} else {
return {
transformPageData: (
pageData: PageData,
context: TransformPageContext,
) => {
const { siteConfig } = context
cfgDynamicHead(pageData, siteConfig)
cfgDynamicTitleTemplate(pageData, siteConfig)
},
}
}
}

export default defineConfig({
srcDir: 'src',
outDir: './dist',
Expand Down Expand Up @@ -146,12 +264,6 @@ export default defineConfig({
link: '/ja/',
...jaConfig,
},
fr: {
label: 'Français',
lang: 'fr',
link: '/fr/',
...frConfig,
},
},
head: [
[
Expand Down Expand Up @@ -293,103 +405,7 @@ export default defineConfig({
stringify: true,
},
},
transformHead(content) {
const { pageData, siteConfig } = content
pageData.frontmatter.head ??= []
pageData.frontmatter.head.push([
'meta',
{
name: 'og:url',
content: `https://yuanshen.site/${
siteConfig.site.base
}${pageData.relativePath.replace('.md', '')}`,
},
])
pageData.frontmatter.head.push([
'meta',
{
name: 'twitter:url',
content: `https://yuanshen.site/${
siteConfig.site.base
}${pageData.relativePath.replace('.md', '')}`,
},
])
pageData.frontmatter.head.push([
'meta',
{
name: 'og:title',
content: pageData.frontmatter.title
? pageData.frontmatter.title
: 'Kongying Tavern',
},
])
pageData.frontmatter.head.push([
'meta',
{
name: 'twitter:title',
content: pageData.frontmatter.title
? pageData.frontmatter.title
: 'Kongying Tavern',
},
])
pageData.frontmatter.head.push([
'meta',
{
name: 'og:description',
content: pageData.frontmatter.description
? pageData.frontmatter.description
: `Genshin Interactive Map
A Completionist's Interactive Map by Kongying Tavern`,
},
])
pageData.frontmatter.head.push([
'meta',
{
name: 'twitter:description',
content: pageData.frontmatter.description
? pageData.frontmatter.description
: `Genshin Interactive Map
A Completionist's Interactive Map by Kongying Tavern`,
},
])
pageData.frontmatter.head.push([
'meta',
{
name: 'description',
content: pageData.frontmatter.description
? pageData.frontmatter.description
: `Genshin Interactive Map
A Completionist's Interactive Map by Kongying Tavern`,
},
])
pageData.frontmatter.head.push([
'meta',
{
name: 'keywords',
content: pageData.frontmatter.keywords
? pageData.frontmatter.keywords
: '空荧酒馆,空荧地图,空荧酒馆原神地图,原神全资源攻略地图,原神攻略地图,原神地图,原神电子地图,原神互动地图,Genshin,Genshin_map,Genshin_Treasure,Genshin Map,Genshin Impact Map,Genshin Impact Interactive Map',
},
])
pageData.frontmatter.head.push([
'meta',
{
name: 'og:image',
content: pageData.frontmatter.image
? pageData.frontmatter.image
: 'https://yuanshen.site/docs/imgs/common/cover.jpg',
},
])
pageData.frontmatter.head.push([
'meta',
{
name: 'twitter:image',
content: pageData.frontmatter.image
? pageData.frontmatter.image
: 'https://yuanshen.site/docs/imgs/common/cover.jpg',
},
])
},
...createConfigureFunction(),
markdown: {
image: {
lazyLoading: true,
Expand Down
2 changes: 1 addition & 1 deletion .vitepress/locales/en/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const constants: CustomConstant = {
'A Genshin interactive map by Kongying Tavern for completionists',
META_IMAGE: 'https://yuanshen.site/docs/imgs/common/cover.jpg',
LOCAL_CODE: 'en-US',
LOCAL_BASE: 'en',
LOCAL_BASE: '/en',
}

export default constants
2 changes: 1 addition & 1 deletion .vitepress/locales/en/footer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const footer: CustomConfig['footer'] = {
items: [
{
text: 'Client User Manual',
link: '/manual/client-user-manual',
link: '/manual/client',
},
{
text: 'Feedback',
Expand Down
2 changes: 1 addition & 1 deletion .vitepress/locales/en/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import Payment from './payment'
export const enConfig: LocaleSpecificConfig<
DefaultTheme.Config & CustomConfig
> = {
titleTemplate: 'Kongying Tavern',
titleTemplate: ':title | Kongying Tavern',
description: C.META_DESCRIPTION,
head: Head,
themeConfig: {
Expand Down
Loading

0 comments on commit 4afcd5f

Please sign in to comment.