Autohugo

Github配置ssh并验证

利用SSH登录vps的流程

1
2
3
4
5
6
客户端向vps发起一个登录请求
    vps生成一串随机数,利用之前配置好的公钥(authorized_keys)进行加密,将加密后字符串传给客户端
    客户端利用私钥(id_rsa)进行解密,将解密后的字符串外加一些别的(sessionKey之类的、我也不知道是啥)字符串;将整合得到的新的“摘要”用私钥加密,发给vps
    vps对“摘要”用公钥解密,通过解密得到的文本判断是否认证该客户端登录

可以看到整个过程充分利用了公钥和私钥可以互相加密与解密的特点,通常说公钥加密、私钥解密

本地创建ssh

RSA4096 ssh-keygen -t rsa -b 4096 -C "add164@gmail.com"

ed25519 ssh-keygen -t ed25519 -C "ne@x.com" 查看fingerprint ssh-keygen -l -f .\id_ed25519

在C:\Users\Administrator\.ssh生成private和public key

github添加key

在github setting里添加ssh公钥

本地验证

SSH -T git@github.com

git ssh验证出现/d/SPB_Data/.ssh 不存在

生成public key的默认目录为D:\SPB_Data是什么原因, 这是因为SPB软件会生成$home system variable,需要删除home variable

1:Hugo本地搭建

hugo new site name

hugo server 开启服务

访问站点 http://localhost:1313/

下载主题Stack

将主题下载完成后并解压至 themes 文件夹中,将 exampleSite 文件夹中的 content 和hugo.yaml 复制到主文件夹中,并删掉原来的 hugo.toml 和 Content/post/rich-content 修改 hugo.yaml 中的 theme 选项,将其修改为与主题文件夹同名。 再次在命令行输入 hugo server启动服务,可以看到正常的页面

hugo文章如果要展示,

draft必须是false

2:创建Repository上传到Github

新建一个 GitHub 仓库,仓库名为 ==name.github.io==,权限设置为 public.

==进入hugo生成的public目录下==

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
git config --global user.name "B"
git config --global user.email  "b@outlook.com"
git init

git add . 

git commit -m "My first commit"

git branch -M main

git remote add origin git@github.com:he/he.git
git push -u origin main

前往 Setting/Pages/Branch 选择 main 分支,并保存。

3:部署流水线CICD

持续集成(Continuous Integration)、持续交付(Continuous Delivery) 、持续部署(Continuous Deployment)

在 GitHub 上创建一个新的仓库,

权限建议设置为“Private”.它将被用来用于存放 Hugo 的源文件,自定义的仓库名为“Hugo”

token生成

前往github的 Settings/Developer Settings/Personal access tokens , 点击 “Generate new token (classic)” 创建一个 token. “Expiration” 为 token 过期时间,可自定义。记得选择下方的 “repo” 和 “workflow” 选项。

==生成的token prefix == ghp_RW

配置Token

前往本仓库的 Settings/Secrets and variables/Actions 将生成的 Token 保存在仓库的环境变量中。 【这个名字很重要,在后面配置中会用】

新建site\.github\workflows\deploy.yml

返回本地的 “你的博客名” 文件夹,在其中新建 “.GitHub” 文件夹,在该文件夹中创建 “workflows” 文件夹,在该文件夹中新建 “deploy.yaml” 文件。

 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
name: deploy

# 代码提交到main分支时触发GitHub action
on:
  push:
    branches:
      - main

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
        - name: Checkout
          uses: actions/checkout@v4
          with:
              fetch-depth: 0

        - name: Setup Hugo
          uses: peaceiris/actions-hugo@v3
          with:
              hugo-version: "latest"
              extended: true

        - name: Build Web
          run: hugo -D

        - name: Deploy Web
          uses: peaceiris/actions-gh-pages@v4
          with:
              PERSONAL_TOKEN: ${{ secrets.token的名字 }}
              EXTERNAL_REPOSITORY: hea/hea.github.io
              PUBLISH_BRANCH: main
              PUBLISH_DIR: ./public
              commit_message: auto deploy

新建.gitignore

在 “你的博客名” 文件夹中新建 “.gitignore” 文件,用来忽略提交不必要的文件或文件夹。在其中输入:

1
2
3
4
public
resources
.hugo_build.lock
hugo.exe

查看Action

提交完成之后前往 “Actions” 页面查看部署情况

Licensed under CC BY-NC-SA 4.0
comments powered by Disqus
Load Days...Load HMS...
Built with Hugo