Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
5f0e382
add zh_cn localization
frto027 Jun 27, 2025
c5f9cd4
add sidebar for zh_cn
frto027 Jun 27, 2025
2407fb6
ignore check for zh_cn
frto027 Jun 27, 2025
7d9db11
Add zh_cn localization and improve readability
loas1 Jun 27, 2025
3ab9465
Add zh_cn localization and improve readability
loas1 Jun 27, 2025
28e2dd3
Add zh_cn localization and improve readability
loas1 Jun 27, 2025
12c27ec
Merge pull request #2 from loas1/master
loas1 Jun 27, 2025
bf8b33b
fix the Last Update timestamp
frto027 Jun 28, 2025
254b067
add localize outdated hint
frto027 Jun 28, 2025
d9b3430
update zh_cn
frto027 Jun 28, 2025
de4496d
fix zh_cn
frto027 Jun 28, 2025
f6f1ff3
fix shared.ts
frto027 Jun 28, 2025
73b1942
update component and zh_cn
frto027 Jun 28, 2025
971e7dd
run prettier
frto027 Jun 28, 2025
cd59167
update zh_cn and search things
frto027 Jun 28, 2025
268e091
fix zh_cn
frto027 Jun 28, 2025
9768db3
Refactor logic and enhance layout
loas1 Jun 28, 2025
64a3958
Merge pull request #3 from loas1/master
loas1 Jun 28, 2025
435dd95
add pc-modding.md for zh_cn
frto027 Jun 29, 2025
34138a2
pc-modding.md translate to zh-cn
illc4621 Jun 29, 2025
95eecb0
Update pc-modding.md
illc4621 Jun 30, 2025
e2e55cb
Update pc-modding.md
illc4621 Jun 30, 2025
a5da072
Merge branch 'illc4621-master'
frto027 Jul 10, 2025
6f29fe0
update pc-modding.md
frto027 Jul 10, 2025
7819395
fix dead link
frto027 Jul 10, 2025
cc8b051
fix fmt
frto027 Jul 10, 2025
73c9a51
update zh_cn/pc-modding.md
frto027 Jul 10, 2025
3e80d3f
Merge branch 'bsmg:master' into master
frto027 Jul 10, 2025
16a687b
add fixSidebarForLocalization to use localized .md file automatically…
frto027 Jul 10, 2025
862e2c8
Merge branch 'master' of github.com:frto027/wiki
frto027 Jul 10, 2025
858e879
update zh_cn translate
frto027 Jul 10, 2025
cfb202c
clean code
frto027 Jul 17, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/wiki.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v4
with:
Expand Down Expand Up @@ -87,6 +89,8 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v4
with:
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
"build": "vitepress build wiki",
"lint:images": "node ./scripts/checkImages.mjs",
"lint:prettier": "prettier --check .",
"lint": "npm run lint:prettier && markdownlint-cli2 \"wiki/**/*.md\" \"#wiki/{de,fr,ja,nl}/**/*.md\"",
"fmt": "prettier --write . && markdownlint-cli2 --fix \"wiki/**/*.md\" \"#wiki/{de,fr,ja,nl}/**/*.md\""
"lint": "npm run lint:prettier && markdownlint-cli2 \"wiki/**/*.md\" \"#wiki/{de,fr,ja,nl,zh_cn}/**/*.md\"",
"fmt": "prettier --write . && markdownlint-cli2 --fix \"wiki/**/*.md\" \"#wiki/{de,fr,ja,nl,zh_cn}/**/*.md\""
},
"devDependencies": {
"@types/markdown-it-container": "^2.0.10",
Expand Down
12 changes: 11 additions & 1 deletion wiki/.vitepress/components/HomeLinks.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
<script setup>
import { computed } from 'vue'
import { useData } from 'vitepress'
const { theme } = useData()

const title = computed(
() => theme.value.bsmg?.external_links ?? 'External Links',
)
</script>

<template>
<div class="container">
<div class="vp-doc">
<h2>External Links</h2>
<h2>{{ title }}</h2>
<slot />
</div>
</div>
Expand Down
49 changes: 49 additions & 0 deletions wiki/.vitepress/components/LocalizedOutdateHint.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<script setup>
import { computed } from 'vue'
import { useData } from 'vitepress'
const { page, theme, lang } = useData()

const date = computed(() => new Date(page.value.lastUpdated))

const originalFileLink = computed(() => {
let url = page.value.frontmatter.originalFile
if (!url.endsWith('.md')) {
return '/' + url
}
return '/' + url.substr(0, url.length - 3)
})

const originalFileDate = computed(
() => new Date(page.value.frontmatter.originalFileTimestamp),
)

const originalFileTimeStr = computed(() =>
new Intl.DateTimeFormat(
theme.value.lastUpdated?.formatOptions?.forceLocale
? lang.value
: undefined,
theme.value.lastUpdated?.formatOptions ?? {
dateStyle: 'short',
timeStyle: 'short',
},
).format(originalFileDate.value),
)

const hintText = computed(
() =>
theme.value.bsmg?.original_page_updated ??
'The original page has been updated at ',
)
const gotoOriginalPage = computed(
() => theme.value.bsmg?.to_original_page ?? 'Click to original page.',
)
</script>

<template>
<div class="container" v-if="date < originalFileDate">
<div class="warning custom-block">
{{ hintText }} {{ originalFileTimeStr }}
<a :href="originalFileLink">{{ gotoOriginalPage }}</a>
</div>
</div>
</template>
2 changes: 2 additions & 0 deletions wiki/.vitepress/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { fr } from './fr'
import { de } from './de'
import { nl } from './nl'
import { ja } from './ja'
import { zh_cn } from './zh_cn'

export default defineConfig({
...shared,
Expand All @@ -14,5 +15,6 @@ export default defineConfig({
de: { label: 'Deutsch', ...de },
nl: { label: 'Nederlands', ...nl },
ja: { label: '日本語', ...ja },
zh_cn: { label: '简体中文', ...zh_cn },
},
})
137 changes: 131 additions & 6 deletions wiki/.vitepress/config/shared.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,39 @@
import container from 'markdown-it-container'
import { spawn } from 'node:child_process'
import { existsSync, glob } from 'node:fs'
import path, { basename } from 'node:path'
import { env } from 'node:process'
import type { DefaultTheme } from 'vitepress'
import { defineConfig } from 'vitepress'
import type { DefaultTheme, PageData, TransformPageContext } from 'vitepress'
import { defineConfigWithTheme } from 'vitepress'
import { tabsMarkdownPlugin } from 'vitepress-plugin-tabs'

const IS_DEV = env.NODE_ENV === 'production'

const search = (): DefaultTheme.Config['search'] => {
if (IS_DEV) return { provider: 'local' }
const wiki_root_folder = path.join(__dirname, '..', '..')

export const search = (
algoliaTranslation:
| undefined
| DefaultTheme.AlgoliaSearchOptions['translations'] = undefined,
localTranslation:
| undefined
| DefaultTheme.LocalSearchOptions['translations'] = undefined,
): DefaultTheme.Config['search'] => {
if (IS_DEV)
return {
provider: 'local',
options: {
translations: localTranslation || algoliaTranslation,
},
}

return {
provider: 'algolia',
options: {
appId: 'MDQBBYI18P',
apiKey: '0f36f096b83770eae78115f2d88bd394',
indexName: 'bsmg',
translations: algoliaTranslation,
},
}
}
Expand All @@ -23,7 +42,7 @@ type Route =
| readonly [name: string, path: string, routes?: Route[]]
| readonly [name: string, routes: Route[]]

interface SidebarItem {
export interface SidebarItem {
name: string
path: string
routes: Route[]
Expand Down Expand Up @@ -58,9 +77,114 @@ export const sidebar = (...items: SidebarItem[]): DefaultTheme.SidebarMulti => {
]),
)
}
/**
* use localized path for sidebar item if possible, and comment the untranslated titles.
* @param items the sidebar arrays
* @param prefix a folder name in the wiki root
* @param decorate_no_translated_text a function that add a comment 'untranslated' to title
*/
export function fixSidebarForLocalization(
items: SidebarItem[],
prefix: string,
decorate_no_translated_text?: (text: string) => string,
) {
const wiki_root_folder = path.join(__dirname, '..', '..')

function GetLocalizedPath(_path: string) {
let localized_path = '/' + prefix
if (_path.startsWith('/')) localized_path += _path
else localized_path += '/' + _path

let file_exists = false

if (localized_path.endsWith('/')) {
//this is a folder
file_exists = existsSync(path.join(wiki_root_folder, localized_path))
} else {
file_exists = existsSync(
path.join(wiki_root_folder, localized_path + '.md'),
)
}
if (file_exists) return localized_path
return undefined
}

function HandleRoute(route: Route) {
const [text, link, routes] = route
if (typeof link == 'string') {
let localizedPath = GetLocalizedPath(link)
if (localizedPath) {
let mutable_route = route as any
mutable_route[1] = localizedPath
} else if (decorate_no_translated_text) {
let mutable_route = route as any
mutable_route[0] = decorate_no_translated_text(text)
}

routes?.forEach(HandleRoute)
return
}

;(link ?? routes)?.forEach(HandleRoute)
}
items.forEach(item => {
let localized_path = GetLocalizedPath(item.path)
if (localized_path == undefined) {
if (decorate_no_translated_text) {
item.name = decorate_no_translated_text(item.name)
}
return
}
item.routes.forEach(HandleRoute)
})
}
export interface BSMGConfig {
external_links?: string
original_page_updated?: string
to_original_page?: string
}

export interface BSMGThemeConfig extends DefaultTheme.Config {
bsmg?: BSMGConfig
}

export async function transformPageDataForLocalize(
pageData: PageData,
context: TransformPageContext,
) {
let file_path = pageData.relativePath // zh_cn/foo/bar/quest-modding.md
let m = new RegExp('^[a-z_]+?/(.*)$').exec(file_path)
if (m) {
let path_without_prefix = m[1] // foo/bar/quest-modding.md
let original_full_path = path.join(
context.siteConfig.srcDir,
path_without_prefix,
)
if (existsSync(original_full_path)) {
function getGitTimestamp(file) {
return new Promise((resolve, reject) => {
let child = spawn('git', ['log', '-1', '--pretty="%ai"', file])
child.stdout.setEncoding('utf-8')
let output = ''
child.stdout.on('data', data => (output += String(data)))
child.on('close', () => resolve(+new Date(output)))
child.on('error', err => reject(err))
})
}

try {
let timestamp = await getGitTimestamp(original_full_path)
pageData.frontmatter.originalFile = path_without_prefix
pageData.frontmatter.originalFileTimestamp = timestamp
} catch (e) {
pageData.frontmatter.originalFileTimestamp = 0
}
}
}
}

// https://vitepress.dev/reference/site-config
export const shared = defineConfig({
export const shared = defineConfigWithTheme<BSMGThemeConfig>({
title: 'BSMG Wiki',

lastUpdated: true,
Expand All @@ -82,4 +206,5 @@ export const shared = defineConfig({
md.use(container, 'center'), md.use(tabsMarkdownPlugin)
},
},
transformPageData: transformPageDataForLocalize,
})
Loading