用hugo快速搭建自己的静态博客
对于那些想搭建自己的博客,又只想简单专注写markdown,注重博客内容质量的童鞋,推荐一个神器——Hugo。
Hugo
Hugo是一款开源的用go语言编写的静态网站生成工具。
- 项目地址:http://gohugo.io/
- GitHub:https://github.com/gohugoio/hugo
- 下载地址:https://github.com/gohugoio/hugo/releases
- 网站模板:https://themes.gohugo.io/
使用Hugo
创建新站点
hugo new site mysitename
该命令将会生成一个名为mysitename的文件夹,文件夹中的目录结构如下:
▸ archetypes/
▸ content/
▸ data/
▸ layouts/
▸ static/
▸ themes/
config.toml
content中放置自己写的markdown,static放置一些需要引用的图片等资源,themes放置网页模板文件,config.toml是hugo网站的配置文件。
创建新页面
进入mysitename,创建一个页面:
cd mysitename
hugo new new.md
如果是博客文件,可以创建在content的post目录下:
hugo new post/new.md
打开new.md,将会看到:
---
title: "New"
date: 2017-11-30T11:05:09+08:00
draft: true
---
然后你就可以在后面写自己的markdown文章啦~
下载模板文件
可以从网站模板https://themes.gohugo.io/中挑选你自己喜欢的网站风格,这里我选的是hugo-tranquilpeak-theme
切换到themes目录下:
cd themes
git clone https://github.com/kakawait/hugo-tranquilpeak-theme.git
本地调试
hugo server --theme=hugo-tranquilpeak-theme --buildDrafts --watch
然后就可以在浏览器中输入http://127.0.0.1:1313欣赏自己的网站啦~
远程发布
当你想上传至自己的服务器上,或者github上,就可以使用以下的命令生成静态网站文件
hugo --theme=hugo-tranquilpeak-theme --baseUrl="http://yourname.github.io/" --buildDrafts
这时会在网站目录下多生成一个public目录,其中就是生成的静态网站文件,直接放入服务器网站目录下,或者push到自己的GitHub上就可以啦~
修改网站模板
网站模板中的一些信息,可以直接通过config.toml配置,具体的配置方式,请查看各自的模板的说明文档,么么哒~