');mask-image:url('data:image/svg+xml;utf8,');content:'';margin:0 .4rem;display:inline-block;vertical-align:middle;line-height:1}.breadcrumb-trail .trail-items li:last-child:after{display:none}.bloghash-breadcrumbs{font-size:1.4rem;border-width:0}#page .page-header .bloghash-breadcrumbs a>span{color:inherit}#bloghash-copyright .bloghash-flex-row>div:empty{display:none}#bloghash-copyright>.bloghash-container>.bloghash-flex-row>div{width:auto;padding-top:.6rem;padding-bottom:.6rem}.bloghash-copyright-layout-1 #bloghash-copyright>.bloghash-container>.bloghash-flex-row>div{-ms-flex-preferred-size:100%;flex-basis:100%;-ms-flex-negative:0;flex-shrink:0;-webkit-box-pack:center;-ms-flex-pack:center;justify-content:center}#bloghash-scroll-top{-webkit-box-align:center;-ms-flex-align:center;align-items:center;-webkit-box-pack:center;-ms-flex-pack:center;justify-content:center;position:fixed;bottom:2.5rem;right:2rem;z-index:997;width:4rem;height:4rem;opacity:0;-webkit-transform:translate3d(0,3rem,0);transform:translate3d(0,3rem,0)}#bloghash-scroll-top .bloghash-scroll-icon{overflow:hidden;z-index:2}#bloghash-scroll-top .bloghash-icon{-webkit-box-align:center;-ms-flex-align:center;align-items:center;-webkit-box-pack:center;-ms-flex-pack:center;justify-content:center;height:2rem;color:var(--bloghash-white);-webkit-transform:translateY(1.1rem);-ms-transform:translateY(1.1rem);transform:translateY(1.1rem)}#bloghash-scroll-top:before{content:'';z-index:1;border-radius:10rem;background-color:var(--bloghash-primary);-webkit-transform:scale(1);-ms-transform:scale(1);transform:scale(1);border:.1rem solid rgba(185,185,185,.4)}#bloghash-scroll-top svg{fill:var(--bloghash-white)}.bloghash-widget.widget:not(.widget_text):not(.hester-core-custom-list-widget) ul{list-style:none;margin-left:0;margin-right:0}.bloghash-widget.widget:not(.widget_text):not(.hester-core-custom-list-widget) ul ul{margin:1.6rem 0 1.6rem 1.968rem}.bloghash-widget.widget:not(.widget_text):not(.hester-core-custom-list-widget) ul ul:last-child{margin-bottom:0}#main .bloghash-widget{overflow:hidden}#main .bloghash-widget{margin-bottom:4rem}.widget-title,.wp-block-heading{margin-top:0;position:relative;display:block;margin-bottom:2.5rem}.widget ul{line-height:1.5}.widget ul:last-child{margin-bottom:0}.widget ul:not(.wp-block-social-links) li{margin-bottom:1rem}.widget ul:not(.wp-block-social-links) li:last-child{margin-bottom:0}.widget.widget_block li a{position:relative;z-index:0}.bloghash-entry>:first-child,.wp-block-group__inner-container>:first-child{margin-top:0}.bloghash-entry>:last-child,.wp-block-group__inner-container>:last-child{margin-bottom:0}.bloghash-entry ul:not(.wp-block-latest-posts){list-style:disc}.bloghash-entry ul ul{list-style:circle}.bloghash-entry ul:not(.wp-block-latest-posts){margin-left:4rem}.bloghash-entry ul:not(.wp-block-social-links) li:not(.blocks-gallery-item):last-child{margin-bottom:0}.bloghash-entry ul ul{margin-top:.64rem;margin-bottom:0}.bloghash-entry ul:not(.wp-block-latest-posts){margin-bottom:2rem;margin-top:2rem}.bloghash-entry p{margin-bottom:1.5rem;margin-top:1.5rem}.author-avatar img{border-radius:var(--bloghash-full-radius);width:3rem;vertical-align:middle;margin-right:.8rem;display:inline-block;outline:1px solid rgba(185,185,185,.4)}#main .content-area .entry-meta a{color:inherit}.entry-meta{font-size:1.3rem;font-weight:600;margin-top:1.2rem}.entry-meta .bloghash-icon{height:1.827rem;margin-right:.7rem;vertical-align:text-bottom}.entry-meta .entry-meta-elements>span{padding:0 1rem;line-height:1.2}.entry-meta .entry-meta-elements>span.posted-on{line-height:1.5}.entry-meta .entry-meta-elements>span,.entry-meta .entry-meta-elements>span .posted-by{-js-display:inline-flex;display:-webkit-inline-box;display:-ms-inline-flexbox;display:inline-flex;-webkit-box-align:center;-ms-flex-align:center;align-items:center}.entry-meta .entry-meta-elements>span:first-child{padding-left:0}.entry-meta .entry-meta-elements>span:last-child{margin-right:0;padding-right:0}.entry-meta .entry-meta-elements>span:before{content:'';position:relative;left:-1.1rem;width:4px;height:4px;border-radius:100%;background-color:var(--bloghash-primary)}.entry-meta .entry-meta-elements>span:first-child:before{display:none}.single-post .entry-content{margin-top:4rem}.single .post-category{margin-bottom:.3rem;font-size:1.4rem}.single .post-category a{-js-display:inline-flex;display:-webkit-inline-box;display:-ms-inline-flexbox;display:inline-flex;margin:0 .4rem .8rem}.single .entry-header{text-align:start;margin-bottom:1rem}.single .entry-meta{text-align:start;margin-top:1.6rem}.single .entry-content{margin-bottom:5rem}.single .entry-content>:last-child{margin-bottom:0!important}.single.bloghash-page-title-align-left .bloghash-article>.entry-header,.single.bloghash-page-title-align-left .bloghash-article>.post-category{text-align:start}.single.bloghash-page-title-align-left .bloghash-article>.entry-meta>.entry-meta-elements{-webkit-box-pack:start;-ms-flex-pack:start;justify-content:flex-start}button.bloghash-animate-arrow{-webkit-appearance:none;border:none;-webkit-box-shadow:none;box-shadow:none;background:0 0;outline:none}.bloghash-animate-arrow .arrow-bar{-webkit-transform:scaleX(0);-ms-transform:scaleX(0);transform:scaleX(0)}.bloghash-animate-arrow svg{vertical-align:middle}.bloghash-animate-arrow.right-arrow svg{-webkit-transform:rotate(180deg);-ms-transform:rotate(180deg);transform:rotate(180deg)}.bloghash-animate-arrow.right-arrow .arrow-bar{-webkit-transform-origin:100% 0;-ms-transform-origin:100% 0;transform-origin:100% 0}.bloghash-animate-arrow.right-arrow .arrow-handle{-webkit-transform:translateX(.6rem);-ms-transform:translateX(.6rem);transform:translateX(.6rem)}.bloghash-hamburger{padding:0;display:inline-block;font:inherit;color:inherit;text-transform:none;background-color:transparent;border:0;margin:0;overflow:visible}.hamburger-box{width:2.5rem;height:1.4rem;display:inline-block;position:relative}.hamburger-inner{display:block;top:50%;margin-top:-.1rem}.hamburger-inner,.hamburger-inner:before,.hamburger-inner:after{width:2.8rem;height:2px;background-color:#111827;border-radius:var(--bloghash-normal-radius);position:absolute}.hamburger-inner:before,.hamburger-inner:after{content:"";display:block}.hamburger-inner:before{top:-5px}.hamburger-inner:after{bottom:-5px}.bloghash-mobile-nav{order:1;display:none;margin-left:2.4rem}.bloghash-hamburger,.bloghash-mobile-nav{-webkit-box-align:center;-ms-flex-align:center;align-items:center}body:not(.is-mobile-menu-active) .bloghash-hamburger .hamburger-box .hamburger-inner:before{width:1.5rem}.bloghash-hamburger{-js-display:inline-flex;display:-webkit-inline-box;display:-ms-inline-flexbox;display:inline-flex;border-radius:var(--bloghash-normal-radius)}.bloghash-hamburger .hamburger-inner,.bloghash-hamburger .hamburger-inner:before,.bloghash-hamburger .hamburger-inner:after{background-color:currentColor}#bloghash-header:after{content:'';position:fixed;top:100%;left:0;right:0;height:100vh;background-color:rgba(255,255,255,.85);z-index:991;opacity:0;visibility:hidden;will-change:opacity,visibility;-webkit-transform:translate3d(0,0,0);transform:translate3d(0,0,0)}@media only screen and (min-width:782px){.site .bloghash-flex-row .col-md{-webkit-box-flex:1;-ms-flex-positive:1;flex-grow:1;-ms-flex-negative:1;flex-shrink:1;max-width:100%;-ms-flex-preferred-size:0;flex-basis:0}.site .bloghash-flex-row .col-md.flex-basis-auto{-ms-flex-preferred-size:auto;flex-basis:auto}.site .bloghash-flex-row .end-md{-webkit-box-pack:end;-ms-flex-pack:end;justify-content:flex-end;text-align:end;margin-left:auto}}@media only screen and (max-width:868px){.bloghash-hide-mobile-tablet{display:none!important}.bloghash-container{padding:0 3rem}.bloghash-header-widgets .bloghash-header-widget,.bloghash-header-widgets .bloghash-header-widget.bloghash-header-widget__button{padding-left:1rem;padding-right:1rem}.bloghash-mobile-nav{margin-left:1.6rem}}@media only screen and (max-width:599px){#bloghash-header-inner .bloghash-widget-wrapper,.bloghash-header-element,.bloghash-header-widgets .bloghash-header-widget{position:static}.bloghash-header-widgets .dropdown-item:after{display:none}.page-header>.bloghash-container{-webkit-box-align:start;-ms-flex-align:start;align-items:flex-start;-webkit-box-orient:vertical;-webkit-box-direction:normal;-ms-flex-direction:column;flex-direction:column}.author-avatar img{display:none}}@media only screen and (max-width:480px){#page{min-height:-webkit-fill-available}}@media only screen and (max-width:960px){#main>.bloghash-container{display:block}#primary{max-width:100%!important;padding-left:0!important;padding-right:0!important;margin-top:4rem}.site-main #secondary{width:100%;margin-top:4rem}}@media all and (-ms-high-contrast:none),(-ms-high-contrast:active){.bloghash-btn,body:not(.wp-customizer) input[type=submit]{height:1rem}#main>.bloghash-container #primary{-ms-flex-preferred-size:0%;flex-basis:0%}}.bloghash-btn,input[type=submit]{background-color:var(--bloghash-primary)}.bloghash-social-nav>ul>li>a .bloghash-icon.bottom-icon{color:var(--bloghash-primary)}#masthead .bloghash-header-widgets .dropdown-item:after{border-bottom-color:var(--bloghash-primary);outline:none!important}.bloghash-header-widgets .dropdown-item{border-top-color:var(--bloghash-primary)}::-webkit-selection{background-color:var(--bloghash-primary);color:var(--bloghash-white)}::-webkit-scrollbar-thumb{background:rgba(0,0,0,.2)}::-webkit-scrollbar-thumb:hover{background:rgba(0,0,0,.4)}.mr-1{margin-right:.4rem}a.bloghash-btn i{font-size:105%;vertical-align:baseline}a.bloghash-btn i:before{display:inline-block;vertical-align:middle}a.bloghash-btn span{vertical-align:baseline;line-height:normal}@media (prefers-reduced-motion:reduce){*{animation-duration:0s!important}}.bloghash-cursor{visibility:hidden;position:fixed;z-index:10000;display:flex;justify-content:center;align-items:center;top:0;left:0}.bloghash-cursor .bloghash-cursor-wrapper{display:flex;justify-content:center;align-items:center}.bloghash-cursor .bloghash-cursor--follower{position:absolute;background-color:var(--bloghash-primary);opacity:.35;border-radius:100%;width:2.4rem;height:2.4rem}.bloghash-cursor .bloghash-cursor--label{position:absolute;display:flex;justify-content:center;align-items:center;color:var(--bloghash-white);letter-spacing:.08em;transform:scale(0);will-change:transform,opacity}.bloghash-cursor .bloghash-cursor--icon{position:absolute;display:flex;justify-content:center;align-items:center;color:var(--bloghash-white);transform:scale(0);will-change:transform,opacity;color:rgba(255,255,255,.76)}.bloghash-cursor .bloghash-cursor--icon:before{content:"\f061";font-family:var(--bloghash-font-awesome);font-size:2.4rem}.wp-block-latest-posts.wp-block-latest-posts__list li{margin-bottom:1.6rem}.wp-block-latest-posts__post-title{margin:1rem 0 0;display:block;font-weight:600}.post-category .cat-links a.cat-1{--bloghash-primary:#59ce10;--bloghash-primary_80:#def6d0}:root{--bloghash-primary:#343aef;--bloghash-primary_80:#d7d8fc;--bloghash-primary_15:#5358f2;--bloghash-primary_27:rgba(52,58,239,.27);--bloghash-primary_10:rgba(52,58,239,.1)}#bloghash-header-inner{background:#fff}#bloghash-header,.bloghash-header-widgets a:not(.bloghash-btn),.bloghash-logo a,.bloghash-hamburger{color:#131315}#bloghash-header-inner{border-color:rgba(185,185,185,.4);border-bottom-width:1px}.bloghash-header-widget:after{background-color:#ccc}@media screen and (max-width:960px){#bloghash-header-inner .bloghash-nav{display:none;color:#000}.bloghash-mobile-nav{display:inline-flex}#bloghash-header-inner{position:relative}#bloghash-header-inner .bloghash-nav>ul>li>a{color:inherit}#bloghash-header-inner .site-navigation{display:none;position:absolute;top:100%;width:100%;height:100%;min-height:100vh;left:0;right:0;margin:-1px 0 0;background:#fff;border-top:1px solid #eaeaea;box-shadow:0 15px 25px -10px rgba(50,52,54,.125);z-index:999;font-size:1.7rem;padding:0}#bloghash-header-inner .site-navigation>ul{overflow-y:auto;max-height:68vh;display:block}#bloghash-header-inner .site-navigation>ul>li>a{padding:0!important}#bloghash-header-inner .site-navigation>ul li{display:block;width:100%;padding:0;margin:0;margin-left:0!important}#bloghash-header-inner .site-navigation>ul a{padding:0;position:relative;background:0 0}#bloghash-header-inner .site-navigation>ul li{border-bottom:1px solid #eaeaea}#bloghash-header-inner .site-navigation>ul>li:last-child{border-bottom:0}#bloghash-header-inner .site-navigation>ul a>span{padding:10px 30px!important;width:100%;display:block}#bloghash-header-inner .site-navigation>ul a>span:after,#bloghash-header-inner .site-navigation>ul a>span:before{display:none!important}}.bloghash-nav.bloghash-header-element,.bloghash-header-layout-1 .bloghash-header-widgets{font-weight:600;font-family:"Inter Tight",Helvetica,Arial,sans-serif;font-size:1.7rem;line-height:1.5}#secondary{width:30%}body:not(.bloghash-no-sidebar) #primary{max-width:70%}.bloghash-layout__boxed-separated #content>article,.bloghash-layout__boxed-separated.bloghash-sidebar-style-2 #secondary .bloghash-widget{background-color:#fff}body{color:#002050}h1,h2,h3,h4,h5,.h4,a,.entry-meta,.bloghash-logo .site-title,.wp-block-heading{color:#302d55}:root{--bloghash-secondary:#302d55}.bloghash-container{max-width:1480px}.bloghash-logo .logo-inner{margin-top:27px;margin-right:10px;margin-bottom:27px;margin-left:10px}@media only screen and (max-width:768px){.bloghash-logo .logo-inner{margin-top:25px;margin-right:1px;margin-bottom:25px}}.page-header{background:rgba(244,54,118,.1)}.page-header{border-color:rgba(0,0,0,.062);border-style:solid;border-bottom-width:1px}.bloghash-breadcrumbs{padding-top:15px;padding-bottom:15px}html{font-size:62.5%}@media only screen and (max-width:768px){html{font-size:53%}}@media only screen and (max-width:480px){html{font-size:50%}}*{-moz-osx-font-smoothing:grayscale;-webkit-font-smoothing:antialiased}body{font-weight:400;font-family:"Be Vietnam Pro",Helvetica,Arial,sans-serif;font-size:1.7rem;line-height:1.75}h1,.bloghash-logo .site-title,h2,h3,h4,.h4,h5{font-weight:700;font-style:normal;text-transform:none;text-decoration:none;font-family:"Be Vietnam Pro",Helvetica,Arial,sans-serif}h1,.bloghash-logo .site-title{font-weight:700;font-size:4rem;line-height:1.4}h2{font-weight:700;font-size:3.6rem;line-height:1.4}h3{font-weight:700;font-size:2.8rem;line-height:1.4}h4,.h4{font-weight:700;font-size:2.4rem;line-height:1.4}h5{font-weight:700;font-size:2rem;line-height:1.4}#bloghash-header .bloghash-logo .site-title{font-size:3rem}#main .widget-title,#secondary .bloghash-widget .wp-block-heading{font-size:2.4rem}.single-post .entry-content{font-size:1.6rem}.bloghash-btn,body:not(.wp-customizer) input[type=submit]{color:#fff;border-color:rgba(0,0,0,.12);border-width:.1rem;border-top-left-radius:.8rem;border-top-right-radius:.8rem;border-bottom-right-radius:.8rem;border-bottom-left-radius:.8rem}.bloghash-btn,body:not(.wp-customizer) input[type=submit]{font-weight:500;font-family:"Be Vietnam Pro",Helvetica,Arial,sans-serif;font-size:1.8rem}:root{--bloghash-radius:.5rem}
从零开始使用Docusaurus构建文档型网站 - xixiknow
Skip to content
为什么突然又来研究文档类网站了呢?
哈哈哈哈,博主也反思了自己是不是太过喜欢折腾了。文章没写几篇,网站弄了几个了。
稍作解释,博主也是基于自己想要输出的内容类型考虑的。博客类网站比较适合输出一些比较零散的内容,要篇章与篇章之间有关联,博客类网站虽然也可以做到,但是总感觉很别扭。
所以略做思索,决定后续内容进行分流,比较适合规范化、模块化、系列化学习的内容将会移到我的新网站 xixiknow docs上做,一些偏重零散化、单点技能化的放在本网站做(比如本篇文章),后续还计划做一个工具类网站(规划中…)
1. 本地安装必要环境
Docusuarus 强依赖于 Node.js 版本在 18.0 以上
首先进入 Nodejs 官网的下载地址,根据自己的系统、想要下载的版本下载安装包即可

安装过程不进行细说,一步一步安装即可,安装完成后,打开命令窗口输入node -v
,能看到版本号输出即可
2. 安装 Docusaurus
找到一个心仪的空目录,打开终端,执行如下命令
| npx create-docusaurus@latest my-website classic |
2.1 项目结构说明
上述命令它将会创建一个包含模板文件的新目录 my-website
,该目录的目录结构如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | |-- my-website | |-- README.md | |-- blog | | |-- 2019-05-28-first-blog-post.md | | |-- 2019-05-29-long-blog-post.md | | |-- 2021-08-01-mdx-blog-post.mdx | | |-- 2021-08-26-welcome | | |-- authors.yml | | `-- tags.yml | |-- docs | | |-- intro.md | | |-- tutorial-basics | | `-- tutorial-extras | |-- docusaurus.config.js | |-- package-lock.json | |-- package.json | |-- sidebars.js | |-- src | | |-- components | | |-- css | | `-- pages | `-- static | `-- img |
Docusaurus 是基于 markdown 进行渲染的。通常 Docusaurus 支持文件以 .md
或 .mdx
结尾。mdx 文章可以允许嵌入 React 和 Javascript,更加的灵活。
目录中文件的详细说明
Docusaurus 可以支持两类网站内容(1)博客类(2)文档类,并为此规划了两个大目录 docs
和 blog
blog
目录是 Docusaurus 用来支持博客内容的,需要可以使用,不需要则可以通过配置禁用- 通常
blog
目录下的文章命名会以日期开头,经过解析后则是以日期进行归档分类 tags.yml
用来定义文章标签
docs
目录是用来存放文档类文件
Docusaurus 比较重要的配置文件:
docusaurus.config.js
:项目的核心配置文件,用于配置 Docusaurus 站点的各种参数和设置。通过该文件,我们可以自定义站点的外观、功能、插件等内容sidebars.js
: 定义网站文档的侧边栏,可以为不同的内容定义不同的侧边栏static
:静态资源的目录,如:网站logo
Docusaurus src
目录:非文档类文件,如页面、自定义的组件
2.2 常用命令
本地运行调试
通常运行完以下命令后,将会自动在默认浏览器上打开一个链接为 http://localhost:3000/
的页面。启动完成后,大部分修改都是即刻生效的
编译for生产
运行此命令后,将会在 my-website
目录下生成名为 build
的目录,该目录是编译后可用于生产部署的制品
3. 部署到云服务器
Docusaurus 的官方文档里列举 N 多的部署说明,具体可参见:官方部署说明,因为我的是腾讯云服务器,在官方部署说明中并没有提及,所以自行摸索了下。最终选择 Git + Github Action
做为解决方案。
3.1 创建一个 Git 仓库
该 Git 仓库的作用是用来管理前面创建的项目
1. 打开 Git 并登录,如果没有账号需要注册账号
2. 创建 Git repository,注意选择 Private 类型,保护自己的文档财富


3. 本地的项目上传 git
以下命令执行过程中,若提示没有 git 命令,需要先安装 git
| git add . git commit -a -m "init mywebsite" |
- 将本地的库与远程的库进行关联,以下命令可以从上面创建的库中获取

| git remote add origin https://github.com/xixiknow/my-website.git git branch -M main git push -u origin main |
以上命令执行完成后,本地的工程即上传成功

3.2 自动化部署
因为我要部署到自己的腾讯服务器上,从步骤上来说,总共分为三步
- 将本地新增或修改的文档提交到 git 上
- 将项目构建成制品
- 将制品上传到服务器的指定目录下
除了第一步必须要手动之外,剩下的两步都手动做,事不难,但人懒。
那有没有更好的解决方式呢?有的,我们可以利用自动化能力,解决掉第2、3步。
我选择了 Github Action去完成项目构建和自动发布
懒,是促进个人进步的~
3.2.1 生成 ssh 密钥
此步骤将会生成公钥和私钥、私钥配置到 Github Action 中,公钥配置到云服务器中,配置完成后 Github Action 可以无密码登录云服务器,以便将项目制品部署到服务器上
运行以下命令,一直回车即可,公私钥文件可以在目录 ~/.ssh
下找到
- 公钥文件为
~/.ssh/id_rsa.pub
- 私钥文件为
~/.ssh/id_rsa

3.2.2 使用公钥和私钥
公钥需要配置在云服务器中,私钥需要配置到 Git 中
云服务器配置
需要将 ~/.ssh/id_rsa.pub
文件中的内容配置到 ~/.ssh/authorized_keys
中。
可以用以下命令:
| cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys |
Git 配置
创建两个 Secrets,分别用于存储 SSH 私钥和公钥
- SSH_PRIVATE_KEY:将
id_rsa
(私钥)内容粘贴到此字段 - SSH_PUBLIC_KEY:将
id_rsa.pub
(公钥)内容粘贴到此字段
注意:私钥的内容必须完全复制,并且不应该泄露或与其他人共享

3.2.3 创建工作流
在以下的位置,可以创建一个工作流,该工作流的的主要目的是为了,在我们推送变更以后,会自动触发并将我们的修改发布到网站上

以下代码可以考虑粘贴直接使用,简单解释以下代码的执行步骤
- 监听
main
分支的变化 - 设置任务的运行环境
actions/checkout@v2
用于拉取到你的更改到任务的运行环境actions/setup-node@v2
设置 nodejs
按照你指定的版本npm install
安装项目依赖npm run build
编译项目webfactory/ssh-agent@v0.5.3
通过将 SSH 私钥加载到 GitHub Actions 中的 SSH agent,从而允许你在后续的步骤中使用 SSH 进行连接和操作- 设置密钥的权限
ssh-keyscan -H yourIP >> ~/.ssh/known_hosts
有助于避免首次连接时的安全警告- 将编译后的制品发布到指定目录
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | name: Deploy to Server on: push: branches: - main # 监听 main 分支的推送事件 jobs: deploy: runs-on: ubuntu-latest # 使用 GitHub Actions 提供的 Ubuntu 环境 steps: - name: Checkout code uses: actions/checkout@v2 - name: Set up Node.js uses: actions/setup-node@v2 with: node-version: '18.x' # 根据需要修改 Node.js 版本 - name: Install dependencies run: | npm install - name: Build Docusaurus run: | npm run build - name: Set up SSH key uses: webfactory/ssh-agent@v0.5.3 with: ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }} - name: Set SSH key permissions run: | mkdir -p ~/.ssh echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa chmod 600 ~/.ssh/id_rsa # 设置权限为 600,确保私钥安全 - name: Add Server to know hosts run: | mkdir -p ~/.ssh ssh-keyscan -H yourIP >> ~/.ssh/known_hosts - name: Deploy to server run: | cd build rsync -av ./ username@yourip:yourpath # 这里配置你的用户名、主机ip,会将内容上传到云服务器上(也可以使用 git 变量的方式) env: SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }} |
Scroll to Top
wpDiscuz