hugo搭建博客
Featured image of post hugo搭建博客

hugo搭建博客

利用hugo生成静态博客托管到github

Avatar 😎

# 目录

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
# Deploy Your Site Step By Step
By LinSnow.

## 在GitHub和Vercel部署你的博客

### 🍕利用Github Page和Github Action部署你的Hugo博客

#### 🍔注册GitHub
打开 `https://github.com/`, 注册一个GitHub账号。

#### 🧀创建Github仓库
为了使用 `GitHub Action` 自动部署,创建两个仓库。

1. 创建一个名字为 `blog` 的仓库。
2. 创建一个名为 `blog-file` 的仓库。

#### 🍦获取SSH Key密钥
生成SSH密钥,配置邮箱和用户名。

```bash
git config --global user.email "you@example.com"
git config --global user.name "Your Name"

生成SSH key。

1
ssh-keygen -t rsa

将公钥配置到 GitHub 账户中。

# 🍚部署hugo博客

在博客根目录下创建 .github/workflows/deploy.yml 文件,并填写相应内容。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
name: GitHub Page

on:
    push:
        branches:
            - main

jobs:
    deploy:
        runs-on: ubuntu-latest
        steps:
            - uses: actions/checkout@v3
            - name: Setup Hugo
              uses: peaceiris/actions-hugo@v2
            - name: Cache resources
              uses: actions/cache@v3
            - name: Build
              run: hugo --minify --gc
            - name: Deploy
              uses: peaceiris/actions-gh-pages@v3

创建 deploy.sh 文件用于一键部署博客。

1
2
3
4
5
hugo
git init
git add -A
git commit -m 'deploy'
git push -f git@github.com:lin-snow/blog-file.git main

运行 deploy.sh 推送文件到仓库。

# 🍺开启Github Page

进入 blog 仓库,打开设置,找到 page 项。

# 🥝利用Vercel部署你的Hugo博客

# 🍖登录Vercel

使用GitHub登录Vercel。

# 🎈导入博客

登录后,选择 Add New ... -> Project,导入GitHub上的 Blog 项目。

# 自定义域名

在Vercel中设置自定义域名,并在域名服务商添加解析。

完成博客在Vercel的部署。

似水年华 - Licensed under CC BY-NC-SA 4.0

正在加载一言...

使用 Hugo 构建
主题 StackJimmy 设计
本博客已稳定运行