用 Hugo 搭建个人博客
Quick Start
本文是在 macOS 系统环境上安装 Hugo 的教程
Step 1: 安装 Hugo
使用 Homebrew macOS 下的包管理工具下载安装
brew install hugo
安装完成后,进行验证
hogo version
Step 2: 新建网站
这一步去你的 GitHub 下新建一个名为 yourname.github.io 形式的 repo,yourname 是你 Git 账号的名称。
hugo new site yourname.github.io-creator
执行完后,会将网站下载下载到本地目录。
Step 3: 添加主题
cd yourname.github.io-creator
git init
git submodule add https://github.com/budparr/gohugo-theme-ananke.git themes/ananke
然后,将主题加入站点配置文件中
echo 'theme = "ananke"' >> config.toml
Step 4: 添加博客文章
hugo new posts/my-first-post.md
默认会在 content/posts
下生成博客草稿,像这样:
将要发布时将 draft
设置为 false
---
title: "My First Post"
date: 2019-03-26T08:47:11+01:00
draft: true
---
Step 5: 本地起一个 Hugo server
可以在本地服务器 http://localhost:1313/
上预览写好的博客
hugo server -D
Step 6: 个性化博客主题
用文本编辑器打开 config.toml
baseURL = "https://example.org/"
languageCode = "en-us"
title = "My New Hugo Site"
theme = "ananke
Step 7: 生成博客网站
博客网站会输出到 ./public
目录下。最后将 ./public
的文件上传到刚刚创建的 yourname.github.io
仓库中,上传完成后配置仓库的 GitHub Pages,是在 Settings > Options > GitHub Pages
中。
hugo -D