Skip to content

Commit

Permalink
vuepress & workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
moyechen committed Dec 7, 2023
1 parent ab34673 commit 757403f
Show file tree
Hide file tree
Showing 5 changed files with 213 additions and 0 deletions.
51 changes: 51 additions & 0 deletions .github/workflows/vuepress-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: docs

on:
# 每当 push 到 master 分支时触发部署
push:
branches: [master]
# 手动触发部署
workflow_dispatch:

jobs:
docs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
with:
# “最近更新时间” 等 git 日志相关信息,需要拉取全部提交记录
fetch-depth: 0

- name: Setup pnpm
uses: pnpm/action-setup@v2
with:
# 选择要使用的 pnpm 版本
version: 8
# 使用 pnpm 安装依赖
run_install: true

- name: Setup Node.js
uses: actions/setup-node@v4
with:
# 选择要使用的 node 版本
node-version: 18
# 缓存 pnpm 依赖
cache: pnpm

# 运行构建脚本
- name: Build VuePress site
run: pnpm docs:build

# 查看 workflow 的文档来获取更多信息
# @see https://github.com/crazy-max/ghaction-github-pages
- name: Deploy to GitHub Pages
uses: crazy-max/ghaction-github-pages@v4
with:
# 部署到 gh-pages 分支
target_branch: gh-pages
# 部署目录为 VuePress 的默认输出目录
build_dir: docs/.vuepress/dist
env:
# @see https://docs.github.com/cn/actions/reference/authentication-in-a-workflow#about-the-github_token-secret
GITHUB_TOKEN: ${{ secrets.PERSON_KEY }}
86 changes: 86 additions & 0 deletions auto_readme.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import json
import os

def generate_readme(tpath):
print("->>>>>>>>>>", tpath)
with open(tpath+"vx.json", 'r') as f:
content = f.read()

j = json.loads(content)

folders = j["folders"]

files = j["files"]

readme_txt = "# 这里是"+tpath.split("docs/")[1].rstrip("/") + "\n\n\n"
for folder in folders:
name = folder["name"]
generate_readme(tpath+name+"/")


print("generate ",tpath+"README.md")
with open(tpath+"README.md", 'w') as f:
f.write(readme_txt)

return readme_txt

def auto_sidebar(tpath, f_path=None) -> dict:
print("-->>", tpath, f_path)
l = []

with open(tpath+"vx.json", 'r') as f:
content = f.read()

j = json.loads(content)

folders = j["folders"]

files = j["files"]

for folder in folders:
name = folder["name"]

children = auto_sidebar(tpath+name+'/', f_path=f"{f_path}/{name}" if f_path else name)
l.append({
"text": name,
"link": f"/{f_path}/{name}/" if f_path else name+'/',
"collapsible": True,
"children":children ,
})


for file in files:
name = file["name"]
l.append({
"text":name.replace(".md",'',1),
"link": f"/{f_path}/{name}" if f_path else name,
})

return l

def readme_main():
for n in ["notebook","ops","python","router","video", "web"]:
os.system(f"mv {n} docs/{n}")

generate_readme("docs/notebook/")
generate_readme("docs/ops/")
generate_readme("docs/python/")
generate_readme("docs/router/")
generate_readme("docs/video/")
generate_readme("docs/web/")


def sidebar_main():
sidebar_obj = {}
for n in ["notebook","ops","python","router","video", "web"]:
sidebar_obj[f"/{n}/"] = auto_sidebar(f"docs/{n}/", n)

code = f"""
let sidebarConfig = {json.dumps(sidebar_obj)}
"""+"export {sidebarConfig}"

with open("docs/.vuepress/mysidebar.js", 'w', encoding='utf8') as f:
f.write(code)

readme_main()
sidebar_main()
54 changes: 54 additions & 0 deletions docs/.vuepress/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { defaultTheme } from '@vuepress/theme-default'
import { searchPlugin } from '@vuepress/plugin-search'
import { prismjsPlugin } from '@vuepress/plugin-prismjs'
import { mediumZoomPlugin } from '@vuepress/plugin-medium-zoom'
import { sidebarConfig } from './mysidebar.js'

import { createPage } from '@vuepress/core'



export default {
theme: defaultTheme({
sidebar: sidebarConfig,
navbar: [
// NavbarItem
{
text: 'web',
link: '/web/',
},
{
text: 'notebook',
link: '/notebook/',
},
{
text: 'ops',
link: '/ops/',
},
{
text: 'router',
link: '/router/',
},
{
text: 'video',
link: '/video/',
},
{
text: 'python',
link: '/python/',
},
],
}),
plugins: [
searchPlugin({
// 配置项
}),
prismjsPlugin({
// 配置项
}),
mediumZoomPlugin({
// 配置项
}),
],

}
3 changes: 3 additions & 0 deletions docs/.vuepress/mysidebar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

let sidebarConfig = {}
export {sidebarConfig}
19 changes: 19 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "moyechen.github.io",
"version": "1.0.0",
"main": "index.js",
"repository": "[email protected]:moyechen/moyechen.github.io.git",
"author": "moyechen <[email protected]>",
"license": "MIT",
"devDependencies": {
"@vuepress/plugin-docsearch": "^2.0.0-rc.0",
"@vuepress/plugin-medium-zoom": "^2.0.0-rc.0",
"@vuepress/plugin-prismjs": "^2.0.0-rc.0",
"@vuepress/plugin-search": "^2.0.0-rc.0",
"vuepress": "^2.0.0-rc.0"
},
"scripts": {
"docs:dev": "python3 auto_readme.py && vuepress dev docs",
"docs:build": "python3 auto_readme.py && vuepress build docs"
}
}

0 comments on commit 757403f

Please sign in to comment.