以往咱们搭建blog要么学习一个编程语言+Web开发框架,要么使用现成的blog系统(如WordPress)。其实咱们还可使用Hugo。Hugo是由Go语言实现的静态网站生成器,它不须要数据库,因此页面都是经过MarkDown开发的页面。不用安装编程语言环境,不用安装数据库,只须要几个步骤就能够快速搭建一个blog出来。git
1 安装github
---------------------------数据库
推荐二进制安装(简单、快速)编程
到 Hugo Releases 下载对应的操做系统版本的Hugo二进制文件(hugo或者hugo.exe)ubuntu
Hugo Releases:https://github.com/gohugoio/hugo/releases浏览器
本文以Windows为例,因此下载:hugo_0.24.1_Windows-64bit.zip服务器
下载以后解压获得“hugo.exe”文件。markdown
将hugo.exe所在的目录添加到系统环境变量PATH下面,打开cmd,输入“hugo version”。框架
2 建立站点&文章编程语言
---------------------------------------
想要建立站点,一个命令搞定,切换到你想要建立站点的目录,输入:
D:\git>hugo new site blog Congratulations! Your new Hugo site is created in D:\git\blog. Just a few more steps and you're ready to go: 1. Download a theme into the same-named folder. Choose a theme from https://themes.gohugo.io/, or create your own with the "hugo new theme <THEMENAME>" command. 2. Perhaps you want to add some content. You can add single files with "hugo new <SECTIONNAME>\<FILENAME>.<FORMAT>". 3. Start the built-in live server via "hugo server". Visit https://gohugo.io/ for quickstart guide and full documentation.
一个blog站点就建立好了。新建的站点目录结果以下:
blog/
archetypes/
doc/
content/
data/
layouts/
static/
config.toml
当前的站没有任何内容,也没作任何配置。
接下来切换到blog站点目录,建立一篇文章:
D:\git>cd blog
D:\git\blog>hugo new about.md
该文件位于 blog/content/about.md目录下。打开编辑:
+++
date = "2017-07-03T15:37:11+08:00"
tags = ["blog"]
title = "my first blog"
+++
### 这里使用markdown来编写文章
markdown 教程:http://wowubuntu.com/markdown/
3 安装主题
---------------------------
站点必定要有主题,安装主题应该是最难的一步了,由于不一样的主题设置方式也会有所不一样。
Hugo themes:https://themes.gohugo.io/
你能够到上面的网站中挑选你喜欢的主题。而后,根据指引找到github项目地址进行下载。
3.1 下载主题:
我使用的主题是:https://github.com/wd/hugo-fabric
把主题经过git克隆或直接下载到本地。放到 …/blog/themes/目录下。
3.2 使用主题:
生成主题资源文件(hugo-fabric为主题名)
D:\git\blog>hugo -t hugo-fabric
Started building sites ...
Built site for language en:
0 of 3 drafts rendered
0 future content
0 expired content
8 regular pages created
12 other pages created
0 non-page files copied
2 paginator pages created
1 tags created
1 categories created
total in 35 ms
将\blog\themes\hugo-fabric\exampleSite\config.toml 替换 \blog\config.toml
注:config.toml文件是核心,对网站的配置多数须要修改该文件,而每一个主题的配置又不彻底同样。
4 启动服务器
------------------------------
D:\git\blog>hugo server
WARNING: Site config's rssURI is deprecated and will be removed in a future release. Set baseName in outputFormats.RSS.
Started building sites ...
Built site for language en:
0 draft content
0 future content
0 expired content
1 regular pages created
8 other pages created
0 non-page files copied
1 paginator pages created
1 tags created
0 categories created
total in 9 ms
Watching for changes in D:\git\blog\{data,content,layouts,static,themes}
Serving pages from memory
Web Server is available at http://localhost:1313/ (bind address 127.0.0.1)
Press Ctrl+C to stop
打开浏览器访问:http://localhost:1313/
用Hugo搭建的网站:http://www.testclass.net/