一、环境准备
1.安装go
https://go.dev/doc/install
2.安装Git
https://git-scm.com/downloads
3.下载Hugo最新版
hugo_extended_withdeploy_0.150.0_windows-amd64.zip
#注意下载extended_withdeploy版本
4.配置Git绑定github
1
2
|
git config --global user.name "Github用户名"
git config --global user.email "Github邮箱"
|
5.生成rsa密钥
1
|
ssh-keygen -t rsa -C "Github邮箱"
|
6.进入Github后台ssh绑定rsa密钥并验证
7.临时代理
1
|
export ALL_PROXY="socks5://127.0.0.1:10808"
|
二、开始安装
1. 进入hugo.exe目录,新建网站blog2
2.进入blog2目录
3.在当前目录中初始化一个空的 Git 仓库
4.将 [PaperMod] 主题克隆到 themes
目录中,将其作为 Git 子模块添加到您的项目中
1
|
git submodule add https://github.com/adityatelange/hugo-PaperMod.git themes/PaperMod
|
5.向网站配置文件中添加一行,指明当前主题。
1
|
echo "theme = 'PaperMod'" >> hugo.toml
|
6.启动 Hugo 的开发服务器以查看网站
三、添加内容
1.添加新页面到您的网站
1
|
hugo new content content/posts/my-first-post.md
|
2.Hugo 在 content/posts
目录中创建了文件。用您的编辑器打开该文件
1
2
3
4
5
6
7
8
9
10
|
---
title: 中文测试
description: 这是一篇杂谈
date: 2025-09-26
slug: Vercel部署Hugo
image: helena-hertz-wWZzXlDpMog-unsplash.jpg
categories:
- 中文
- 随笔
---
|
请注意 draft
中的值在 front matter 中是 true
。默认情况下,Hugo 在构建网站时不会发布草稿内容。了解更多关于 草稿、未来和过期内容 的信息。
3.在帖子的正文中添加一些 Markdown,但不要更改 draft
的值。
1
2
3
4
5
6
7
8
9
10
|
+++
title = 'My First Post'
date = 2024-01-14T07:07:07+01:00
draft = true
+++
## Introduction
This is **bold** text, and this is *emphasized* text.
这是**粗体**文本,这是*强调*文本。
Visit the [Hugo](https://gohugo.io) website!
|
4.保存文件,然后启动Hugo的开发服务器以查看网站。您可以使用以下任一命令来包含草稿内容。
1
2
|
hugo server --buildDrafts
hugo server -D
|
四、部署到Github
1.发布网站(-D带草稿发布)
2.进入public目录
3.此目录新建git仓库
4.将所有修改过的和新创建的文件全部添加到暂存区
5.提交暂存区中的文件,并附上提交信息。这是将更改永久保存到历史记录中的操作。
1
|
git commit -m "[message]"
|
6.关联一个远程仓库,并将其命名为 origin
1
|
git remote add origin [url]
|
7.将本地分支推送到远程仓库,并建立跟踪关系。
1
|
git push -u origin [branch-name]
|
快速推送已追踪关系