基于Hugo的本站安装过程
By S.F.
本文链接 https://www.kyfws.com/post/install-blog-hugo/
版权声明 本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
- 2 分钟阅读 - 585 个词 阅读量 0本站系统安装过程,以下为官网指导,英语易懂,只做批注,就不翻译了。
Install Hugo
apt install hugo
hugo version
Create a New Site
hugo new site blog
Add a Theme
See themes.gohugo.io for a list of themes to consider. This quickstart uses the beautiful Ananke theme.
First, download the theme from GitHub and add it to your site’s themes
directory:
cd blog
git init
git submodule add https://github.com/budparr/gohugo-theme-ananke.git themes/ananke
注意,此处为 submodule ,是为了避免和当前 git 库冲突,个人建议用如下方式会更适合管理
cd blog
git init
#注意皮肤名称
git clone --depth=1 https://github.com/budparr/gohugo-theme-ananke.git themes/ananke #拉取深度1,减少体积
rm -rf themes/ananke/.git #删除它的git库
Note for non-git users:
- If you do not have git installed, you can download the archive of the latest version of this theme from: https://github.com/budparr/gohugo-theme-ananke/archive/master.zip
- Extract that .zip file to get a “gohugo-theme-ananke-master” directory.
- Rename that directory to “ananke”, and move it into the “themes/” directory.
Then, add the theme to the site configuration:
echo 'theme = "ananke"' >> config.toml
Add Some Content
You can manually create content files (for example as content/<CATEGORY>/<FILE>.<FORMAT>
) and provide metadata in them, however you can use the new
command to do a few things for you (like add title and date):
hugo new posts/my-first-post.md
Edit the newly created content file if you want, it will start with something like this:
Drafts do not get deployed; once you finish a post, update the header of the post to say
draft: false
. More info here.
Start the Hugo server
Now, start the Hugo server with drafts enabled:
hugo server -D
| EN
-------------------+-----
Pages | 10
Paginator pages | 0
Non-page files | 0
Static files | 6
Processed images | 0
Aliases | 1
Sitemaps | 1
Cleaned | 0
Total in 130 ms
Customize the Theme
Your new site already looks great, but you will want to tweak it a little before you release it to the public.
Site Configuration
Open up config.toml
in a text editor:
baseURL = "https://example.org/"
languageCode = "en-us" #中文是 zh-CN
title = "My New Hugo Site"
theme = "ananke"
Replace the title
above with something more personal. Also, if you already have a domain ready, set the baseURL
. Note that this value is not needed when running the local development server.
Tip: Make the changes to the site configuration or any other file in your site while the Hugo server is running, and you will see the changes in the browser right away, though you may need to clear your cache.
For theme specific configuration options, see the theme site.
For further theme customization, see Customize a Theme.
Build static pages
It is simple. Just call:
hugo -D
Output will be in ./public/
directory by default (-d
/--destination
flag to change it, or set publishdir
in the config file).