Skip to content

Commit

Permalink
docs: update to 2.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
lauset committed Dec 10, 2022
1 parent ecf084f commit c037120
Show file tree
Hide file tree
Showing 235 changed files with 2,197 additions and 17,287 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import fs from 'fs'
import path from 'path'
import chalk from 'chalk'

import { docRoot } from './paths'
import { errorAndExit } from './log'
import consola from 'consola'
import { docRoot } from '../utils/paths'
import { errorAndExit } from '../utils/log'

// NB: this file is only for generating files that enables developers to develop the website.
const componentLocaleRoot = path.resolve(docRoot, '.vitepress/crowdin')
Expand All @@ -15,66 +15,67 @@ async function main() {
if (fs.existsSync(localeOutput)) {
throw new Error(exists)
}
console.log(chalk.cyan('Starting for build doc for developing'))

consola.trace(chalk.cyan('Starting for build doc for developing'))

// all language should be identical since it is mirrored from crowdin.
const dirs = await fs.promises.readdir(componentLocaleRoot, {
withFileTypes: true,
withFileTypes: true
})
const languages = dirs.map((dir) => dir.name)
const langWithoutEn = languages.filter((l) => l !== 'zh-CN')
const langWithoutEn = languages.filter((l) => l !== '.DS_Store')

await fs.promises.mkdir(localeOutput)

// build lang.json for telling `header>language-select` how many languages are there
await fs.promises.writeFile(
path.resolve(localeOutput, 'lang.json'),
JSON.stringify(languages),
{
encoding: 'utf-8',
}
'utf-8'
)

// loop through en-US

const enUS = path.resolve(componentLocaleRoot, 'zh-CN')
const enUS = path.resolve(componentLocaleRoot, 'en-US')

// we do not include en-US since we are currently using it as template
const languagePaths = langWithoutEn.map((l) => {
return {
name: l,
pathname: path.resolve(componentLocaleRoot, l),
}
})
const languagePaths = langWithoutEn.map((l) => ({
name: l,
pathname: path.resolve(componentLocaleRoot, l)
}))

console.log(languagePaths)
consola.debug(languagePaths)
await traverseDir(enUS, languagePaths, localeOutput)
}

async function traverseDir(dir, paths, targetPath) {
async function traverseDir(
dir: string,
paths: { name: string; pathname: string }[],
targetPath: string
) {
const contents = await fs.promises.readdir(dir, { withFileTypes: true })

await Promise.all(
contents.map(async (c) => {
if (c.isDirectory()) {
await fs.promises.mkdir(path.resolve(targetPath, c.name), {
recursive: true,
recursive: true
})

return traverseDir(
path.resolve(dir, c.name),
paths.map((p) => {
return {
...p,
pathname: path.resolve(p.pathname, c.name),
}
}),
paths.map((p) => ({
...p,
pathname: path.resolve(p.pathname, c.name)
})),
path.resolve(targetPath, c.name)
)
} else if (c.isFile()) {
} if (c.isFile()) {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const content = require(path.resolve(dir, c.name))

const contentToWrite = {
'zh-CN': content,
'en-US': content
}

await Promise.all(
Expand All @@ -90,7 +91,7 @@ async function traverseDir(dir, paths, targetPath) {
path.resolve(targetPath, c.name),
JSON.stringify(contentToWrite, null, 2),
{
encoding: 'utf-8',
encoding: 'utf-8'
}
)
}
Expand All @@ -100,7 +101,7 @@ async function traverseDir(dir, paths, targetPath) {

main()
.then(() => {
console.log(chalk.green('Locale for website development generated'))
consola.success(chalk.green('Locale for website development generated'))
})
.catch((err) => {
if (err.message === exists) {
Expand Down
67 changes: 36 additions & 31 deletions docs/.vitepress/config.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,32 @@
import { defineConfigWithTheme } from 'vitepress'
import { build, defineConfigWithTheme, useData } from 'vitepress'
import { VuetomThemeConfig } from 'vitepress-theme-vuetom'
import { mdPlugin } from './utils/plugins'

// import head from './config/head'
import pkg from '../package.json'
import { nav, sidebarGuide, sidebarMdShow } from './menus'
import { getNav, getSidebar, head, locales } from './menus'

export default defineConfigWithTheme<VuetomThemeConfig>({
lang: 'en-US',
base: '/vt',
title: 'Vuetom Theme',
description: 'Theme For Vitepress',
const nav = getNav('zh-CN')
const sidebar = getSidebar('zh-CN')

// head,
export default defineConfigWithTheme<VuetomThemeConfig>({
base: `/vt/`,
ignoreDeadLinks: true,
lastUpdated: true,
head,
locales: locales.vitepressConfig,
themeConfig: {
nav: nav(),
sidebar: {
'zh-CN/guide/': sidebarGuide(),
'zh-CN/mdshow/': sidebarMdShow()
nav,
sidebar,
localeLinks: {
text: '',
items: [
{
text: '中文',
link: '/lang/zhcn'
},
{
text: 'English',
link: '/lang/enus'
}
]
},
socialLinks: [
{ icon: 'github', link: pkg.repository }
Expand All @@ -26,8 +35,12 @@ export default defineConfigWithTheme<VuetomThemeConfig>({
message: 'Released under the MIT License.',
copyright: 'Copyright © 2021-present Lauset'
},
algolia: {
appId: '8Q3CNX0EF2',
apiKey: 'd44e3c8ec76aff9c758ef34f2cefe24d',
indexName: 'dev_vuetom'
},

// docsDir: 'docs',
logoImg: '/logo/vuetom-logo-m.png',
bgImg: '/imgs/homg-bg01.jpg',
bgColor: '0,0,0',
Expand All @@ -41,21 +54,13 @@ export default defineConfigWithTheme<VuetomThemeConfig>({

},

// locales: {
// '/zh-CN/': {
// lang: 'zh-CN',
// title: 'Vuetom 主题',
// description: '为 Vitepress 提供的一款主题'
// },
// '/en-US/': {
// lang: 'en-US',
// title: 'Vuetom Theme',
// description: 'Theme For Vitepress'
// }
// },
markdown: {
lineNumbers: false,
config: (md) => mdPlugin(md)
lineNumbers: true
},
lastUpdated: false
appearance: true,
vite: {
ssr: {
noExternal: ["vitepress-theme-vuetom"]
}
}
})
52 changes: 0 additions & 52 deletions docs/.vitepress/config/head.ts

This file was deleted.

24 changes: 0 additions & 24 deletions docs/.vitepress/config/nav.ts

This file was deleted.

64 changes: 0 additions & 64 deletions docs/.vitepress/config/sidebars.ts

This file was deleted.

File renamed without changes.
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ features:
</div>
</div>


<script setup>
import { onMounted } from 'vue'

Expand Down Expand Up @@ -78,14 +77,13 @@ function fetchReleaseTag() {
fetch('https://api.github.com/repos/vitejs/docs-cn/releases/latest')
.then((res) => res.json())
.then((json) => {
const mainTitle = document.getElementById('main-title')
const dom = document.getElementsByClassName('name')
const mainTitle = dom[0]
mainTitle.style.position = 'relative'

const docsReleaseTag = document.createElement('span')
docsReleaseTag.classList.add('release-tag')
const releaseTagName = json.tag_name
docsReleaseTag.innerText = releaseTagName

if (releaseTagName !== undefined) {
mainTitle.appendChild(docsReleaseTag)
}
Expand Down Expand Up @@ -148,9 +146,4 @@ fetchReleaseTag()
align-items: center;
}

/* special cases */
#sponsor-mux {
padding: 5px 0;
min-height: 36px;
}
</style>
</style>
Loading

0 comments on commit c037120

Please sign in to comment.