From 2e93b6f1d12235718a5444e58bc2bdf5d9b6676b Mon Sep 17 00:00:00 2001 From: Linc <762699299@qq.com> Date: Sun, 20 Apr 2025 19:24:26 +0800 Subject: [PATCH 01/10] ci: add webpage.yml, fix html tag --- .github/workflows/webpage.yml | 129 ++++++++++++++++++++++++++++++++++ src/SUMMARY.md | 2 +- 2 files changed, 130 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/webpage.yml diff --git a/.github/workflows/webpage.yml b/.github/workflows/webpage.yml new file mode 100644 index 00000000..8d6cc29a --- /dev/null +++ b/.github/workflows/webpage.yml @@ -0,0 +1,129 @@ +# take from https://github.com/LincDocs/Workflow + +name: 部署文档 + +on: + push: + branches: ["main"] # 确保这是你正在使用的分支名称 + schedule: + # 定时任务。建议多个仓库错开,避免多个仓库同一时间一起坏掉。我个人用键盘阵列映射周1~5。特别是代理仓库比较需要这个 + - cron: '42 15 * * 6' # 每周六15:42触发工作流 + workflow_dispatch: + +permissions: + contents: write + +# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued. +# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete. +concurrency: + group: "pages" + cancel-in-progress: false + +jobs: + deploy-gh-pages: + runs-on: ubuntu-latest + steps: + - name: 环境 - 构建库 + uses: actions/checkout@v4 + with: + fetch-depth: 1 + repository: LincZero/LincZero.github.io + ref: 'main' # 分支,旧raw + + - name: 环境 - 安装 pnpm + uses: pnpm/action-setup@v4 + with: + run_install: true + version: 9 + + - name: 环境 - 设置 Node.js + uses: actions/setup-node@v4 + with: + node-version: 22 + cache: pnpm + + # 获取仓库的相关配置 + # https://docs.github.com/zh/actions/writing-workflows/choosing-what-your-workflow-does/store-information-in-variables#default-environment-variables + # TODO:若 “仓库无前缀名” 是.github.io结尾,则设置为"/" + - name: 配置 - 获取仓库配置 + id: config1 # 用于给其他步骤引用 + working-directory: ./scripts/ + run: | + > git_config.json # 先清空 + echo "{" >> git_config.json + echo " \"GITHUB_WORKSPACE\": \"${GITHUB_WORKSPACE}\"," >> git_config.json # 工作路径 + echo " \"GITHUB_ACTION_PATH\": \"${GITHUB_ACTION_PATH}\"," >> git_config.json # action路径 + echo " \"GITHUB_ACTION_REPOSITORY\": \"${GITHUB_ACTION_REPOSITORY}\"," >> git_config.json # action仓库 + echo " \"GITHUB_REPOSITORY_OWNER\": \"${GITHUB_REPOSITORY_OWNER}\"," >> git_config.json # 仓库所属(格式: 可以是组织) + echo " \"GITHUB_ACTOR\": \"${GITHUB_ACTOR}\"," >> git_config.json # 仓库作者(格式: 不会是组织) + echo " \"GITHUB_REPOSITORY\": \"${GITHUB_REPOSITORY}\"," >> git_config.json # 仓库标识(格式: 个人或组织/仓库名) + echo " \"CALC_URL\": \"${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/\"," >> git_config.json # 仓库url + REPO_NAME=$(echo "${GITHUB_REPOSITORY}" | cut -d"/" -f2) + echo " \"CALC_REPO_NAME\": \"${REPO_NAME}\"" >> git_config.json # 仓库无前缀名 + echo "}" >> git_config.json + echo "::set-output name=REPO_NAME::$REPO_NAME" + + - name: 文档 - 文档克隆1 # 文档的克隆、构建、部署。注意 `clone --depth 1` 只拉最近一次提交,减少时间 + working-directory: ./src/ + run: | + rm README.md + + # git clone --depth 1 https://github.com/${GITHUB_REPOSITORY}.git # 如果有多个clone项则替换成这个,避免冲突 + git clone --depth 1 https://github.com/${GITHUB_REPOSITORY}.git temp_repo + + - name: 文档 - 文档克隆2, 允许使用代理仓库/指定文件夹 + working-directory: ./src/ + run: | + # step1. 克隆被代理仓库 + # 该仓库为代理仓库时,使用链接仓库而非此仓库 + # TODO 支持agency多个仓库。如果想更通用,干脆支持直接运行agency里的命令组 + if [ -f temp_repo/agency ]; then + echo "with agency" + GIT_LINK=$(sed -n '1p' temp_repo/agency | tr -d '\r') + DIR=$(sed -n '2p' temp_repo/agency | tr -d '\r') + rm -rf temp_repo + git clone --depth 1 $GIT_LINK temp_repo + else + echo "without agency" + DIR="docs/" + fi + + # 使用指定文件夹 + if [ -d "temp_repo/${DIR}" ]; then + echo "with docs folder: temp_repo/${DIR}" + # find temp_repo/* -maxdepth 0 -name docs -prune -o -exec rm -rf {} \; + # ls -l temp_repo/website/docs/ # debug + mv "temp_repo/${DIR}"/* . + rm -rf temp_repo + else + echo "without docs folder: temp_repo/${DIR}" + rsync -a temp_repo/ . + rm -rf temp_repo + fi + echo "---" + ls + + # [!code] 根据实际情况修改 (需要在仓库配置写入以及和文档仓库clone这两个步骤的后面) + - name: 配置 - 设置 + working-directory: ./ + run: | + # sed -i 's/base: \"\/\"/base: \"\/${{steps.config1.outputs.REPO_NAME}}\/\"/g' ./src/.vuepress/config.ts + cat ./scripts/git_config.json + rm -f ./src/.vuepress/config_cover.js + rm -f ./src/.vuepress/theme_cover.js + pnpm run gen-config + + - name: 文档 - 构建 + env: + NODE_OPTIONS: --max_old_space_size=20480 + run: |- + node -e 'console.log(v8.getHeapStatistics())' + pnpm run docs:build + > src/.vuepress/dist/.nojekyll + + - name: 文档 - 部署 + uses: JamesIves/github-pages-deploy-action@v4 + with: + # 这是文档部署到的分支名称 + branch: gh-pages + folder: src/.vuepress/dist diff --git a/src/SUMMARY.md b/src/SUMMARY.md index 5b14b3de..b65e3517 100644 --- a/src/SUMMARY.md +++ b/src/SUMMARY.md @@ -93,7 +93,7 @@ - [Sized 和不定长类型 DST](advance/into-types/sized.md) - [枚举和整数](advance/into-types/enum-int.md) - [智能指针](advance/smart-pointer/intro.md) - - [Box堆对象分配](advance/smart-pointer/box.md) + - [`Box` 堆对象分配](advance/smart-pointer/box.md) - [Deref 解引用](advance/smart-pointer/deref.md) - [Drop 释放资源](advance/smart-pointer/drop.md) - [Rc 与 Arc 实现 1vN 所有权机制](advance/smart-pointer/rc-arc.md) From f79f7e03094490a397713d665ce4fa62b88d65bc Mon Sep 17 00:00:00 2001 From: Linc <762699299@qq.com> Date: Sun, 20 Apr 2025 20:13:59 +0800 Subject: [PATCH 02/10] docs: fix some syntax errors --- README.md | 4 ++++ src/SUMMARY.md | 2 +- src/about-book.md | 4 ++++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 71bca93d..a987c118 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,7 @@ 🏆 + +
@@ -61,6 +62,7 @@

@@ -68,6 +70,7 @@ 🏅 + +
@@ -98,6 +101,7 @@
## 创作感悟 diff --git a/src/SUMMARY.md b/src/SUMMARY.md index b65e3517..27f52801 100644 --- a/src/SUMMARY.md +++ b/src/SUMMARY.md @@ -93,7 +93,7 @@ - [Sized 和不定长类型 DST](advance/into-types/sized.md) - [枚举和整数](advance/into-types/enum-int.md) - [智能指针](advance/smart-pointer/intro.md) - - [`Box` 堆对象分配](advance/smart-pointer/box.md) + - [Box\ 堆对象分配](advance/smart-pointer/box.md) - [Deref 解引用](advance/smart-pointer/deref.md) - [Drop 释放资源](advance/smart-pointer/drop.md) - [Rc 与 Arc 实现 1vN 所有权机制](advance/smart-pointer/rc-arc.md) diff --git a/src/about-book.md b/src/about-book.md index bdde03b1..c70147e7 100644 --- a/src/about-book.md +++ b/src/about-book.md @@ -41,6 +41,7 @@ Rust 语言真的好:连续八年成为全世界最受欢迎的语言、没有 🏆 + +
@@ -57,6 +58,7 @@ Rust 语言真的好:连续八年成为全世界最受欢迎的语言、没有

@@ -64,6 +66,7 @@ Rust 语言真的好:连续八年成为全世界最受欢迎的语言、没有 🏅 + +
@@ -94,4 +97,5 @@ Rust 语言真的好:连续八年成为全世界最受欢迎的语言、没有
From e09b2a1db41e97482018e9a09c2092cf369b9399 Mon Sep 17 00:00:00 2001 From: Linc <762699299@qq.com> Date: Sun, 20 Apr 2025 21:30:18 +0800 Subject: [PATCH 03/10] docs: fix some syntax errors2 --- src/index-list.md | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/src/index-list.md b/src/index-list.md index bc028f42..c9b01bd5 100644 --- a/src/index-list.md +++ b/src/index-list.md @@ -31,31 +31,31 @@ | 名称 | 关键字 | 简介 | | --------------------------------- | -------------- | ------------------------------------------------------------------------------------ | -| [?] | 错误传播 | 用于简化错误传播 | -| [()] | 单元类型 | 单元类型,无返回值 | +| `[?]` | 错误传播 | 用于简化错误传播 | +| `[()]` | 单元类型 | 单元类型,无返回值 | | `!` : 1. [函数] 2. [类型] | 永不返回 | 永不返回 | -| [&] | 引用 | 常规引用是一个指针类型,指向了对象存储的内存地址 | -| [\*] | 解引用 | 解出引用所指向的值 | -| [@] | 变量绑定 | 为一个字段绑定另外一个变量 | +| `[&]` | 引用 | 常规引用是一个指针类型,指向了对象存储的内存地址 | +| `[\*]` | 解引用 | 解出引用所指向的值 | +| `[@]` | 变量绑定 | 为一个字段绑定另外一个变量 | | `_` : 1. [忽略变量] 2. [模式匹配] | 忽略 | 1. 忽略该值或者类型,否则编译器会给你一个 `变量未使用的` 的警告
2. 模式匹配通配符 | -| ['a: 'b] | 生命周期约束 | 用来说明两个生命周期的长短 | -| [{:?}] {:#?} | 打印结构体信息 | 使用 `#[derive(Debug)]` 派生实现 `Debug` 特征,另见 [格式化输出] | -| [::] | 关联函数 | 定义在 `impl` 中且没有 `self` 的函数 | +| `['a: 'b]` | 生命周期约束 | 用来说明两个生命周期的长短 | +| `[{:?}] {:#?}` | 打印结构体信息 | 使用 `#[derive(Debug)]` 派生实现 `Debug` 特征,另见 [格式化输出] | +| `[::]` | 关联函数 | 定义在 `impl` 中且没有 `self` 的函数 | | | | -[?]: https://course.rs/basic/result-error/result.html#传播界的大明星- -[()]: https://course.rs/basic/base-type/function.html#无返回值 -[函数]: https://course.rs/basic/base-type/function.html#永不返回的发散函数- -[类型]: https://course.rs/advance/into-types/custom-type.html#永不返回类型 -[&]: https://course.rs/basic/ownership/borrowing.html#引用与解引用 -[\*]: https://course.rs/basic/ownership/borrowing.html#引用与解引用 -[@]: https://course.rs/basic/match-pattern/all-patterns.html#绑定 -['a: 'b]: https://course.rs/advance/lifetime/advance.html#生命周期约束-hrtb -[{:?}]: https://course.rs/basic/compound-type/struct.html#使用-derivedebug-来打印结构体的信息 -[忽略变量]: https://course.rs/basic/variable.html#使用下划线开头忽略未使用的变量 -[模式匹配]: https://course.rs/basic/match-pattern/match-if-let.html#_-通配符 -[::]: https://course.rs/basic/method.html#关联函数 -[格式化输出]: https://course.rs/basic/formatted-output.html#-与- +`[?]`: https://course.rs/basic/result-error/result.html#传播界的大明星- +`[()]`: https://course.rs/basic/base-type/function.html#无返回值 +`[函数]`: https://course.rs/basic/base-type/function.html#永不返回的发散函数- +`[类型]`: https://course.rs/advance/into-types/custom-type.html#永不返回类型 +`[&]`: https://course.rs/basic/ownership/borrowing.html#引用与解引用 +`[\*]`: https://course.rs/basic/ownership/borrowing.html#引用与解引用 +`[@]`: https://course.rs/basic/match-pattern/all-patterns.html#绑定 +`['a: 'b]`: https://course.rs/advance/lifetime/advance.html#生命周期约束-hrtb +`[{:?}]`: https://course.rs/basic/compound-type/struct.html#使用-derivedebug-来打印结构体的信息 +`[忽略变量]`: https://course.rs/basic/variable.html#使用下划线开头忽略未使用的变量 +`[模式匹配]`: https://course.rs/basic/match-pattern/match-if-let.html#_-通配符 +`[::]`: https://course.rs/basic/method.html#关联函数 +`[格式化输出]`: https://course.rs/basic/formatted-output.html#-与- [back](#head) From c8e56831bde95c6957500851d62fd8ccab2b10c3 Mon Sep 17 00:00:00 2001 From: Linc <762699299@qq.com> Date: Sun, 20 Apr 2025 21:37:39 +0800 Subject: [PATCH 04/10] docs: fix some syntax errors3 --- src/basic/formatted-output.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/basic/formatted-output.md b/src/basic/formatted-output.md index 77f14026..b1e3e585 100644 --- a/src/basic/formatted-output.md +++ b/src/basic/formatted-output.md @@ -55,7 +55,7 @@ eprintln!("Error: Could not complete task") 它们仅应该被用于输出错误信息和进度信息,其它场景都应该使用 `print!` 系列。 -## {} 与 {:?} +## `{}` 与 `{:?}` 与其它语言常用的 `%d`,`%s` 不同,Rust 特立独行地选择了 `{}` 作为格式化占位符(说到这个,有点想吐槽下,Rust 中自创的概念其实还挺多的,真不知道该夸奖还是该吐槽-,-),事实证明,这种选择非常正确,它帮助用户减少了很多使用成本,你无需再为特定的类型选择特定的占位符,统一用 `{}` 来替代即可,剩下的类型推导等细节只要交给 Rust 去做。 @@ -111,7 +111,7 @@ println!("{}, {}, {}, {}", i, s, v, p); 下面来一一看看这三种方式。 -#### {:#?} +#### `{:#?}` `{:#?}` 与 `{:?}` 几乎一样,唯一的区别在于它能更优美地输出内容: From f101927a63e20b0d2764b3b02efa05206851730e Mon Sep 17 00:00:00 2001 From: Linc <762699299@qq.com> Date: Sun, 20 Apr 2025 21:40:37 +0800 Subject: [PATCH 05/10] docs: fix some syntax errors4 --- .github/workflows/{ci.yml => ci.yml.backup} | 0 assets/writing-material/posts/hashmap.md | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename .github/workflows/{ci.yml => ci.yml.backup} (100%) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml.backup similarity index 100% rename from .github/workflows/ci.yml rename to .github/workflows/ci.yml.backup diff --git a/assets/writing-material/posts/hashmap.md b/assets/writing-material/posts/hashmap.md index 7fada8ee..80cf7d2a 100644 --- a/assets/writing-material/posts/hashmap.md +++ b/assets/writing-material/posts/hashmap.md @@ -3,4 +3,4 @@ Any type that implements the Eq and Hash traits can be a key in HashMap. Note that f32 and f64 do not implement Hash, likely because floating-point precision errors would make using them as hashmap keys horribly error-prone. -All collection classes implement Eq and Hash if their contained type also respectively implements Eq and Hash. For example, Vec will implement Hash if T implements Hash. +All collection classes implement Eq and Hash if their contained type also respectively implements Eq and Hash. For example, `Vec` will implement Hash if T implements Hash. From c369ef869dd718f485d0775540731f6263f17dbd Mon Sep 17 00:00:00 2001 From: Linc <762699299@qq.com> Date: Sun, 20 Apr 2025 21:42:41 +0800 Subject: [PATCH 06/10] docs: fix some syntax errors5 --- src/profiling/compiler/phantom-data.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/profiling/compiler/phantom-data.md b/src/profiling/compiler/phantom-data.md index 8b14c0cf..3a21ea6c 100644 --- a/src/profiling/compiler/phantom-data.md +++ b/src/profiling/compiler/phantom-data.md @@ -59,7 +59,7 @@ struct Vec { 让裸指针拥有数据是一个很普遍的设计,以至于标准库为它自己创造了一个叫`Unique`的组件,它可以: - 封装一个`*const T`处理变性 -- 包含一个PhantomData +- 包含一个 `PhantomData` - 自动实现`Send`/`Sync`,模拟和包含T时一样的行为 - 将指针标记为`NonZero`以便空指针优化 From 7754cf978034ef40a16fa2ad0a38cf9344fb36bf Mon Sep 17 00:00:00 2001 From: Linc <762699299@qq.com> Date: Sun, 20 Apr 2025 21:46:39 +0800 Subject: [PATCH 07/10] docs: fix some syntax errors6 --- src/too-many-lists/production-unsafe-deque/basics.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/too-many-lists/production-unsafe-deque/basics.md b/src/too-many-lists/production-unsafe-deque/basics.md index b5116b2e..80d9292f 100644 --- a/src/too-many-lists/production-unsafe-deque/basics.md +++ b/src/too-many-lists/production-unsafe-deque/basics.md @@ -1,6 +1,6 @@ # Basics -好了,这就是本书最烂的部分,也是我花了 7 年时间才写完这一章的原因!是时候把我们已经做过 5 次的枯燥乏味的东西再写一遍了,但因为我们必须使用 Option> 把每件事都做两遍,所以显得格外冗长! +好了,这就是本书最烂的部分,也是我花了 7 年时间才写完这一章的原因!是时候把我们已经做过 5 次的枯燥乏味的东西再写一遍了,但因为我们必须使用 `Option>` 把每件事都做两遍,所以显得格外冗长! ```rust impl LinkedList { From 3ab77b8af27d706bbe69793a49a9966aaccba58a Mon Sep 17 00:00:00 2001 From: Linc <762699299@qq.com> Date: Sun, 20 Apr 2025 21:54:20 +0800 Subject: [PATCH 08/10] docs: fix some syntax errors7 --- .../production-unsafe-deque/implementing-cursors.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/too-many-lists/production-unsafe-deque/implementing-cursors.md b/src/too-many-lists/production-unsafe-deque/implementing-cursors.md index fc1e2717..86f6d5af 100644 --- a/src/too-many-lists/production-unsafe-deque/implementing-cursors.md +++ b/src/too-many-lists/production-unsafe-deque/implementing-cursors.md @@ -216,7 +216,7 @@ pub fn split_before(&mut self) -> LinkedList { } ``` -你可能注意到,我们没有处理 prev 是幽灵节点的情况。但据我所知,其他一切都只是顺便做了正确的事。等我们写测试的时候就知道了!(复制粘贴完成 split_after)。 +你可能注意到,我们没有处理 prev 是幽灵节点的情况。但据我所知,其他一切都只是顺便做了正确的事。等我们写测试的时候就知道了!(复制粘贴完成 split_after)。 # [Splice](https://rust-unofficial.github.io/too-many-lists/sixth-cursors-impl.html#splice) @@ -297,7 +297,7 @@ list.front -> A <-> 1 <-> 2 <-> B <-> C <- list.back } ``` -好吧,这个程序真的很可怕,现在真的感觉到 Option 的痛苦了。但我们可以做很多清理工作。首先,我们可以把这段代码拖到最后。 +好吧,这个程序真的很可怕,现在真的感觉到 `Option` 的痛苦了。但我们可以做很多清理工作。首先,我们可以把这段代码拖到最后。 ```rust self.list.len += input.len; From e9e1d6f26087277fc9fc9eb230405ed448cdfb53 Mon Sep 17 00:00:00 2001 From: Linc <762699299@qq.com> Date: Sun, 20 Apr 2025 22:07:43 +0800 Subject: [PATCH 09/10] docs: fix some syntax errors8 --- .../production-unsafe-deque/variance-and-phantomData.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/too-many-lists/production-unsafe-deque/variance-and-phantomData.md b/src/too-many-lists/production-unsafe-deque/variance-and-phantomData.md index 40133f32..56be663c 100644 --- a/src/too-many-lists/production-unsafe-deque/variance-and-phantomData.md +++ b/src/too-many-lists/production-unsafe-deque/variance-and-phantomData.md @@ -120,7 +120,7 @@ Rust 中的裸指针其实就是让你可以做任何事情,但它们只有一 作为一个花了大量时间在 Rust 中编写集合的人,这让我感到厌烦。这就是为什么我在制作 [std::ptr::NonNull](https://doc.rust-lang.org/std/ptr/struct.NonNull.html), 时添加了这个小魔法: -> 与 *mut T 不同,NonNull 在 T 上是 *covariant(协变的)*。这使得使用 NonNull 构建*covariant(协变的)*类型成为可能,但如果在不应该是 *covariant(协变的)* 的地方中使用,则会带来不健全的风险。 +> 与 *mut T 不同,`NonNull` 在 T 上是 *covariant(协变的)*。这使得使用 `NonNull` 构建*covariant(协变的)*类型成为可能,但如果在不应该是 *covariant(协变的)* 的地方中使用,则会带来不健全的风险。 这是一个围绕着 `*mut T` 构建的类型。真的是魔法吗?让我们来看一下: @@ -140,7 +140,7 @@ impl NonNull { 不,这里没有魔法!NonNull 只是滥用了 *const T 是 *covariant(协变的)* 这一事实,并将其存储起来。这就是 Rust 中集合的协变方式!这可真是惨不忍睹!所以我为你做了这个 Good Pointer Type !不客气好好享受子类型吧 -解决你所有问题的办法就是使用 NonNull,然后如果你想再次使用可空指针,就使用 Option>。我们真的要这么做吗? +解决你所有问题的办法就是使用 NonNull,然后如果你想再次使用可空指针,就使用 `Option>`。我们真的要这么做吗? 是的!这很糟糕,但我们要做的是生产级的链表,所以我们要吃尽千辛万苦(我们可以直接使用裸*const T,然后在任何地方都进行转换,但我真的想看看这样做有多痛苦......为了人体工程学科学)。 From b308b6ef27a06049140bf826d3d81ea31b3a1142 Mon Sep 17 00:00:00 2001 From: Linc <762699299@qq.com> Date: Sun, 20 Apr 2025 22:12:08 +0800 Subject: [PATCH 10/10] chore revert some thing --- .github/workflows/{ci.yml.backup => ci.yml} | 0 .github/workflows/webpage.yml | 129 -------------------- 2 files changed, 129 deletions(-) rename .github/workflows/{ci.yml.backup => ci.yml} (100%) delete mode 100644 .github/workflows/webpage.yml diff --git a/.github/workflows/ci.yml.backup b/.github/workflows/ci.yml similarity index 100% rename from .github/workflows/ci.yml.backup rename to .github/workflows/ci.yml diff --git a/.github/workflows/webpage.yml b/.github/workflows/webpage.yml deleted file mode 100644 index 8d6cc29a..00000000 --- a/.github/workflows/webpage.yml +++ /dev/null @@ -1,129 +0,0 @@ -# take from https://github.com/LincDocs/Workflow - -name: 部署文档 - -on: - push: - branches: ["main"] # 确保这是你正在使用的分支名称 - schedule: - # 定时任务。建议多个仓库错开,避免多个仓库同一时间一起坏掉。我个人用键盘阵列映射周1~5。特别是代理仓库比较需要这个 - - cron: '42 15 * * 6' # 每周六15:42触发工作流 - workflow_dispatch: - -permissions: - contents: write - -# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued. -# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete. -concurrency: - group: "pages" - cancel-in-progress: false - -jobs: - deploy-gh-pages: - runs-on: ubuntu-latest - steps: - - name: 环境 - 构建库 - uses: actions/checkout@v4 - with: - fetch-depth: 1 - repository: LincZero/LincZero.github.io - ref: 'main' # 分支,旧raw - - - name: 环境 - 安装 pnpm - uses: pnpm/action-setup@v4 - with: - run_install: true - version: 9 - - - name: 环境 - 设置 Node.js - uses: actions/setup-node@v4 - with: - node-version: 22 - cache: pnpm - - # 获取仓库的相关配置 - # https://docs.github.com/zh/actions/writing-workflows/choosing-what-your-workflow-does/store-information-in-variables#default-environment-variables - # TODO:若 “仓库无前缀名” 是.github.io结尾,则设置为"/" - - name: 配置 - 获取仓库配置 - id: config1 # 用于给其他步骤引用 - working-directory: ./scripts/ - run: | - > git_config.json # 先清空 - echo "{" >> git_config.json - echo " \"GITHUB_WORKSPACE\": \"${GITHUB_WORKSPACE}\"," >> git_config.json # 工作路径 - echo " \"GITHUB_ACTION_PATH\": \"${GITHUB_ACTION_PATH}\"," >> git_config.json # action路径 - echo " \"GITHUB_ACTION_REPOSITORY\": \"${GITHUB_ACTION_REPOSITORY}\"," >> git_config.json # action仓库 - echo " \"GITHUB_REPOSITORY_OWNER\": \"${GITHUB_REPOSITORY_OWNER}\"," >> git_config.json # 仓库所属(格式: 可以是组织) - echo " \"GITHUB_ACTOR\": \"${GITHUB_ACTOR}\"," >> git_config.json # 仓库作者(格式: 不会是组织) - echo " \"GITHUB_REPOSITORY\": \"${GITHUB_REPOSITORY}\"," >> git_config.json # 仓库标识(格式: 个人或组织/仓库名) - echo " \"CALC_URL\": \"${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/\"," >> git_config.json # 仓库url - REPO_NAME=$(echo "${GITHUB_REPOSITORY}" | cut -d"/" -f2) - echo " \"CALC_REPO_NAME\": \"${REPO_NAME}\"" >> git_config.json # 仓库无前缀名 - echo "}" >> git_config.json - echo "::set-output name=REPO_NAME::$REPO_NAME" - - - name: 文档 - 文档克隆1 # 文档的克隆、构建、部署。注意 `clone --depth 1` 只拉最近一次提交,减少时间 - working-directory: ./src/ - run: | - rm README.md - - # git clone --depth 1 https://github.com/${GITHUB_REPOSITORY}.git # 如果有多个clone项则替换成这个,避免冲突 - git clone --depth 1 https://github.com/${GITHUB_REPOSITORY}.git temp_repo - - - name: 文档 - 文档克隆2, 允许使用代理仓库/指定文件夹 - working-directory: ./src/ - run: | - # step1. 克隆被代理仓库 - # 该仓库为代理仓库时,使用链接仓库而非此仓库 - # TODO 支持agency多个仓库。如果想更通用,干脆支持直接运行agency里的命令组 - if [ -f temp_repo/agency ]; then - echo "with agency" - GIT_LINK=$(sed -n '1p' temp_repo/agency | tr -d '\r') - DIR=$(sed -n '2p' temp_repo/agency | tr -d '\r') - rm -rf temp_repo - git clone --depth 1 $GIT_LINK temp_repo - else - echo "without agency" - DIR="docs/" - fi - - # 使用指定文件夹 - if [ -d "temp_repo/${DIR}" ]; then - echo "with docs folder: temp_repo/${DIR}" - # find temp_repo/* -maxdepth 0 -name docs -prune -o -exec rm -rf {} \; - # ls -l temp_repo/website/docs/ # debug - mv "temp_repo/${DIR}"/* . - rm -rf temp_repo - else - echo "without docs folder: temp_repo/${DIR}" - rsync -a temp_repo/ . - rm -rf temp_repo - fi - echo "---" - ls - - # [!code] 根据实际情况修改 (需要在仓库配置写入以及和文档仓库clone这两个步骤的后面) - - name: 配置 - 设置 - working-directory: ./ - run: | - # sed -i 's/base: \"\/\"/base: \"\/${{steps.config1.outputs.REPO_NAME}}\/\"/g' ./src/.vuepress/config.ts - cat ./scripts/git_config.json - rm -f ./src/.vuepress/config_cover.js - rm -f ./src/.vuepress/theme_cover.js - pnpm run gen-config - - - name: 文档 - 构建 - env: - NODE_OPTIONS: --max_old_space_size=20480 - run: |- - node -e 'console.log(v8.getHeapStatistics())' - pnpm run docs:build - > src/.vuepress/dist/.nojekyll - - - name: 文档 - 部署 - uses: JamesIves/github-pages-deploy-action@v4 - with: - # 这是文档部署到的分支名称 - branch: gh-pages - folder: src/.vuepress/dist