Skip to content

Commit

Permalink
Change vitepress source directory with locale route
Browse files Browse the repository at this point in the history
  • Loading branch information
ihavecoke committed Nov 1, 2023
1 parent 0ff3d96 commit a39e614
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 25 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/canary.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@ jobs:
- uses: oven-sh/setup-bun@v1
- name: Build Pages
run: |
cp -r dist/docs/* docs/
cp dist/docs.json docs/
bun install
./scripts/cp_feishu_to_vitepress.sh
bun autocorrect --fix docs/
bun translate
bun run build
Expand Down
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.env
dist/
feishu-pages/
node_modules/
docs/**/*
locales/**/*
!docs/index.md
.vitepress/cache/
.vitepress/dist/
.vitepress/dist/
14 changes: 9 additions & 5 deletions .vitepress/config.mts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { DefaultTheme, defineConfig } from 'vitepress';
// @ts-ignore
import docs from '../docs/docs.json';
import docs from '../locales/docs.json';

const convertDocsToZhHK = (docs: Record<string, any>[]) => {};

Expand All @@ -19,10 +19,13 @@ const convertDocsToSidebars = (
// Go to root slug
docs = docs.find((doc) => doc.slug === rootSlug)?.children || docs;


// zh-HK/guides/crm/dashboards
// -> zh-HK/docs/guides/crm/dashboards
for (const doc of docs) {
let sidebar: DefaultTheme.SidebarItem = {
text: doc.title,
link: '/' + doc.slug,
link: '/' + doc.slug.replace(/^zh-HK\//, 'zh-HK/docs/'),
};
if (doc.children.length > 0) {
sidebar.items = convertDocsToSidebars(doc.children);
Expand All @@ -40,7 +43,8 @@ const docsSidebarZHHK = convertDocsToSidebars(docs, 'zh-HK');
// https://vitepress.dev/reference/site-config
export default defineConfig({
title: 'Longbridge Whale Docs',
base: '/docs/',
base: '/',
description: 'Longbridge Whale Docs',
ignoreDeadLinks: true,
locales: {
en: {
Expand All @@ -58,12 +62,12 @@ export default defineConfig({
},
cleanUrls: true,
srcExclude: ['SUMMARY.md'],
srcDir: 'docs',
srcDir: 'locales',
themeConfig: {
// https://vitepress.dev/reference/default-theme-config
nav: [
{ text: 'Whale Home', link: 'https://longbridgewhale.com' },
{ text: 'Docs', link: '/en' },
{ text: 'Docs', link: '/zh-HK/docs/guides' },
],

sidebar: {
Expand Down
5 changes: 0 additions & 5 deletions docs/index.md

This file was deleted.

5 changes: 5 additions & 0 deletions locales/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Welcome to Whale Docs.

- [简体中文](zh-CN/docs/guides.md)
- [繁体中文](zh-HK/docs/guides.md)
- [English](en/docs/guides.md)
5 changes: 5 additions & 0 deletions scripts/cp_feishu_to_vitepress.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash
mkdir -p locales/en/docs locales/zh-HK/docs
cp -r feishu-pages/docs/en/* locales/en/docs/
cp -r feishu-pages/docs/zh-HK/* locales/zh-HK/docs/
cp feishu-pages/docs.json locales/
5 changes: 3 additions & 2 deletions scripts/export
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
bun feishu-pages
cp -r dist/docs/* docs/
cp dist/docs.json docs/
cp -r feishu-pages/docs/en/* locales/en/docs/
cp -r feishu-pages/docs/zh-HK/* locales/zh-HK/docs/
cp feishu-pages/docs.json locales/
17 changes: 9 additions & 8 deletions scripts/hk2cn.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ function isFile(filePath) {
* Iterator all .md file in docs/zh-CN/ and convert to docs/zh-HK/
*/
const convert = () => {
if(!fs.existsSync(path.resolve(__dirname,'../docs/zh-HK.md'))) return
let content = fs.readFileSync(path.resolve(__dirname,'../docs/zh-HK.md'), 'utf8');
let newContent = converter(content);
fs.writeFileSync(path.resolve(__dirname,'../docs/zh-CN.md'), newContent);
// if(!fs.existsSync(path.resolve(__dirname,'../docs/zh-HK.md'))) return
// let content = fs.readFileSync(path.resolve(__dirname,'../docs/zh-HK.md'), 'utf8');
// let newContent = converter(content);
// fs.writeFileSync(path.resolve(__dirname,'../docs/zh-CN.md'), newContent);

// 翻译 CN to HK
let files = glob.sync(path.resolve(__dirname,'../docs/zh-HK/**/*.md'));
let files = glob.sync(path.resolve(__dirname,'../locales/zh-HK/**/*.md'));
files.forEach((file) => {
let content = fs.readFileSync(file, 'utf8');
let newContent = converter(content);
Expand All @@ -38,7 +38,7 @@ const convert = () => {
});

// 复制非 md 文件
let assetsFiles = glob.sync(path.join(__dirname, '..', 'docs', 'zh-HK', '**', '!(*.md)'));
let assetsFiles = glob.sync(path.join(__dirname, '..', 'locales', 'zh-HK', '**', '!(*.md)'));
assetsFiles.forEach((file) => {
if(isFile(file)){
console.log('copy file:', file)
Expand Down Expand Up @@ -69,11 +69,12 @@ const deepConvertDocIntoZhCN = (doc) => {
* Parse docs.json and duplicate zh-HK to zh-CN by use OpenCC to convert
*/
const convertDocsJSON = () => {
let docs = require('../docs/docs.json');
let docs = require('../locales/docs.json');
let newDocs = [];
let found = false;

docs.forEach((doc) => {
doc.slug = doc.slug.replace('zh-HK', 'zh-CN');
if (doc.slug === 'zh-HK' && !found) {
newDocs.push(doc);
let newDoc = Object.assign({}, doc);
Expand All @@ -89,7 +90,7 @@ const convertDocsJSON = () => {
}
});

fs.writeFileSync('docs/docs.json', JSON.stringify(newDocs, null, 2));
fs.writeFileSync('locales/docs.json', JSON.stringify(newDocs, null, 2));
};

convert();
Expand Down

0 comments on commit a39e614

Please sign in to comment.