Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
62 changes: 62 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# 构建 VitePress 站点并将其部署到 GitHub Pages 的示例工作流程
#
name: Deploy VitePress site to Pages

on:
# 在针对 `main` 分支的推送上运行。如果你
# 使用 `master` 分支作为默认分支,请将其更改为 `master`
push:
branches: [main, vitepress]

# 允许你从 Actions 选项卡手动运行此工作流程
workflow_dispatch:

# 设置 GITHUB_TOKEN 的权限,以允许部署到 GitHub Pages
permissions:
contents: read
pages: write
id-token: write

# 只允许同时进行一次部署,跳过正在运行和最新队列之间的运行队列
# 但是,不要取消正在进行的运行,因为我们希望允许这些生产部署完成
concurrency:
group: pages
cancel-in-progress: false

jobs:
# 构建工作
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0 # 启用 lastUpdated 需要开启这项
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 20
# cache: npm 难道开启缓存,需要 lock 文件?没错!
- name: Setup Pages
uses: actions/configure-pages@v4
- name: Install dependencies
run: npm install # 不使用 ci,因为我没有上传 lock 文件
- name: Build with VitePress
run: npm run docs:build -- --base /note/
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
path: .vitepress/dist

# 部署工作
deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
needs: build
runs-on: ubuntu-latest
name: Deploy
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
pnpm-lock.yaml
node_modules
.vitepress/cache
.vitepress/dist
86 changes: 86 additions & 0 deletions .vitepress/config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import { defineConfig } from 'vitepress'
import fs from 'node:fs'
import { join, extname, basename } from 'node:path'

const nav = [
// { pathPrefix: '/web/', dir: 'web/', text: 'web 相关', link: '/web/README' },
// { pathPrefix: '/vscode/', dir: 'vscode/', text: 'vscode', link: '/vscode/README' },
{ pathPrefix: '/DSA/', dir: 'DSA/', text: '数据结构与算法', link: '/DSA/README' },
// { pathPrefix: '/CLI/', dir: 'CLI/', text: '命令行', link: '/CLI/README' },
// { pathPrefix: '/interview/', dir: 'interview/', text: '面试相关', link: '/interview/css' },
]
const getNav = () => nav.map(item => ({ text: item.text, link: item.link }))

function dfsReadme(dir) {
const ans = []
const subFiles = fs.readdirSync(dir)
subFiles.sort((a,b) => {
// 我要让以 _ 开头的排在前面
if (a.startsWith('_') && !b.startsWith('_')) return -1
else if (!a.startsWith('_') && b.startsWith('_')) return 1
return a-b
})

for (const child of subFiles) {
const childPath = join(dir, child)
if (isDir(childPath)) {
const items = dfsReadme(childPath)
if (items.length > 0) {
ans.push({
text: basename(childPath, '.md'),
items
})

}
} else if (extname(childPath) === '.md') {
ans.push({
text: basename(childPath, '.md'),
link: childPath
})
}
}
return ans
}
/**
* 不同页面路径,输出不同的侧边栏
*/
function getOneSidebar(pathPrefix) {
const sidebar = dfsReadme(pathPrefix)

return sidebar
.filter(v => !(v.text === 'README.md' || v.text === 'README'))
.map(v => ({ ...v, collapsed: true }))
}
function getSideBar() {
const sidebar = {}
nav.forEach(item => {
sidebar[item.pathPrefix] = getOneSidebar(item.dir)
})
return sidebar
}
function isDir(url) {
return !fs.statSync(url).isFile()
}

// https://vitepress.dev/reference/site-config
export default defineConfig({
title: "我的笔记",
description: "A VitePress Site",
markdown: {
math: true
},

themeConfig: {
nav: getNav(),
sidebar: getSideBar(),
lastUpdated: true,

editLink: {
text: '在 Github 上查看此页',
pattern: 'https://github.com/linhieng/note/tree/main/:path'
},
socialLinks: [
{ icon: 'github', link: 'https://github.com/linhieng/note' }
]
}
})
27 changes: 27 additions & 0 deletions index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
layout: home

title: Note
titleTemplate: Linhieng

hero:
name: Linhieng 的笔记
actions:
- theme: brand
text: 首页
link: /README
- theme: alt
text: 个人网站
link: https://oonoo.cn

features:
- icon: 📝
title: 长期更新
details: 相信我,我能做到!如果做不到,我肯定会关掉这个网站的😂
- icon: 🚀
title: 速度超快
details: 本笔记基于 <a href="https://vitepress.dev/" target="_blank" style="text-decoration:underline;">VitePress</a> 进行部署,速度嘎嘎快。
- icon: <svg t="1712927174937" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="6658" width="200" height="200"><path d="M512 0C229.283787 0 0.142041 234.942803 0.142041 524.867683c0 231.829001 146.647305 428.553077 350.068189 497.952484 25.592898 4.819996 34.976961-11.38884 34.976961-25.294314 0-12.45521-0.469203-45.470049-0.725133-89.276559-142.381822 31.735193-172.453477-70.380469-172.453477-70.380469-23.246882-60.569859-56.816233-76.693384-56.816234-76.693385-46.493765-32.58829 3.540351-31.948468 3.540351-31.948467 51.356415 3.71097 78.356923 54.086324 78.356923 54.086324 45.683323 80.19108 119.817417 57.072162 148.993321 43.593236 4.649376-33.91059 17.915029-57.029508 32.50298-70.167195-113.675122-13.222997-233.151301-58.223843-233.1513-259.341366 0-57.285437 19.919806-104.163095 52.678715-140.846248-5.246544-13.265652-22.820334-66.626844 4.990615-138.884127 0 0 42.996069-14.076094 140.760939 53.787741 40.863327-11.644769 84.627183-17.445825 128.177764-17.6591 43.465272 0.213274 87.271782 6.014331 128.135109 17.6591 97.679561-67.906489 140.59032-53.787741 140.59032-53.787741 27.938914 72.257282 10.407779 125.618474 5.118579 138.884127 32.844219 36.683154 52.593405 83.560812 52.593405 140.846248 0 201.586726-119.646798 245.990404-233.663158 258.957473 18.341577 16.208835 34.721032 48.199958 34.721032 97.210357 0 70.167195-0.639822 126.7275-0.639823 143.960051 0 14.033439 9.213443 30.370239 35.190235 25.209005 203.250265-69.527373 349.769606-266.123484 349.769605-497.867175C1023.857959 234.942803 794.673558 0 512 0" fill="#3E75C3" p-id="6659"></path></svg>
title: 开源
details: 你可以直接在 Github 上查看笔记,同时指出相关错误。
---
11 changes: 11 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"devDependencies": {
"markdown-it-mathjax3": "^4.3.2",
"vitepress": "^1.1.0"
},
"scripts": {
"docs:dev": "vitepress dev",
"docs:build": "vitepress build",
"docs:preview": "vitepress preview"
}
}