Hugo官网: https://gohugo.io
Hugo中文文档: https://www.gohugo.org/
hugo version
创建一个博客新站点使用命令:hogo new site blog
(其中blog为你的站点名字)
创建完成即生成你的博客目录,目录如下:
├─archetypes
├─content
├─data
├─layouts
├─static
├─themes
└─config.toml
配置你的 config.toml , 下面是我的配置:
demo预览
baseURL = "https://ohohhh.github.io/"
LanguageCode = "zh-CN"
HasCJKLanguage = true
title = "Ohohhh's blog"
theme = "blackburn"
author = "Ohohhh"
copyright = "© 2016. All rights reserved."
canonifyurls = true
paginate = 10
[indexes]
tag = "tags"
topic = "topics"
[params]
BottomIntroduce = "Ohohhh's Blog"
# Shown in the home page
subtitle = "好好学习 天天向上"
brand = "Ohohhh"
googleAnalytics = "Your Google Analytics tracking ID"
disqus = "Ohohhh"
# CSS name for highlight.js
highlightjs = "androidstudio"
dateFormat = "02 Jan 2006, 15:04"
[menu]
# Shown in the side menu.
[[menu.main]]
name = "Home"
pre = ""
weight = 1
identifier = "home"
url = "/"
[[menu.main]]
name = "Posts"
pre = ""
weight = 2
identifier = "post"
url = "/post/"
[[menu.main]]
name = "Tags"
pre = ""
weight = 3
identifier = "tags"
url = "/tags/"
[social]
# Link your social networking accouns to the side menu
# by entering your username or ID.
weibo = "5954877907"
twitter = "*"
github = "Ohohhh"
在Hugo的 主题网站 中挑选一款你喜欢的主题,克隆到 themes 目录下
cd themes
git clone https://github.com/yoshiharuyamashita/blackburn.gitt
创建第一篇文章,放到 post 目录,方便之后生成聚合页面。
hugo new post/my_first_blog.md
打开 my_first_blog.md
,默认内容为下:
---
title: "my_first_blog"
date: 2019-05-30T10:49:31+08:00
draft : true
---
文本内容
其中draft
表示是否是草稿文件,编辑完成后请将其改为 false,否则编译会跳过草稿文件。
在项目根目录下,通过 hugo server 命令可以使用 hugo 内置服务器调试预览博客。
hugo server --theme=blackburn --buildDrafts
其中 --theme 选项可以指定主题,–buildDrafts 包括标记为草稿
然后在浏览器里打开: http://localhost:1313 即可访问到你的博客
如果你需要部署在 GitHub Pages 上,首先在GitHub上创建一个Repository,命名为:ohohhh.github.io
(ohohhh替换为你的github用户名的小写)
在站点根目录执行 Hugo 命令生成最终页面:
hugo --theme=blackburn --buildDrafts --baseUrl=“https://ohohhh.github.io”
注意:这里的 --baseUrl 一定是https://(Hugo中文文档里为http://),不然你部署后的博客会没有样式!
可看到根目录下多出 /public文件夹出来,该文件夹的内容即Hugo生成的整个静态网站。然后继续在你的站点根目录执行git 命令,添加远程仓库。
cd public
$ git init
$ git remote add origin [email protected]:Ohohhh/ohohhh.github.io.git
$ git add -A
$ git commit -m “first commit”
$ git push -u origin master
然后浏览器里访问:https://ohohhh.github.io/ 即可看到刚刚搭建的博客。
发布博客:
–新建博客markdown文件,并编辑博客内容(文件名为 **.md )
hugo new post/newBlog.md
–生成静态页面
hugo --theme=blackburn --buildDrafts --baseUrl=“https://ohohhh.github.io/”
—发布
cd public
git add .
git commit -m “new blog added”
git push origin master