macOS搭建Hugo

Hugo 是一个用Go语言编写的静态网站生成器。类似的静态网站生成器还有Jekyll、hexo等等。

Hugo官方主页:https://gohugo.io/

1.安装homebrew: https://brew.sh/index_zh-cn

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

将以上命令粘贴至终端。

2. 安装hugo并查看hugo版本

brew install hugo
hugo version

3.创建hugo项目

hugo new site myblog

创建的站点文件目录说明:

archetypes :存放default.md,头文件格式
content :content目录存放博客文章(.markdown/.md文件)
data :存放自定义模版,导入的toml文件(或json,yaml)
layouts :layouts目录存放的是网站的模板文件
static :static目录存放js/css/img等静态资源
config.toml :config.toml是网站的配置文件
当前网站是没有任何内容的,需要下载个主题跑起来才有内容

4.安装主题

Hugo官方主题:https://themes.gohugo.io/

将下载的主题文件夹XXX,存放的路径为:\myblog\themes\XXX,包含以下文件:

archetypes :存放default.md,头文件格式
layouts :主题模板文件
static :静态资源
theme.toml :主题配置文件

config.toml在文本编辑器中打开:

baseURL = "https://example.org/"
languageCode = "en-us"
title = "My New Hugo Site"
theme = "XXX"

将title上面的内容替换为更私人的内容。另外,如果您已经准备好域,请设置baseURL。请注意,运行本地开发服务器时不需要此值。

5.本地预览命令

hugo server

浏览器里输入:http://localhost:1313 访问网站。

6.发表文章命令

使用 hugo new 命令创建文章

hugo new posts/test.md

可以用文本文件或markdown编辑器打开文件 posts/test.md ,并增加点内容。

+++
date = "2018-03-18T15:01:33+08:00"
title = "test"
draft = false

+++

Hello Hugo!测试内容

注意:默认创建的是草稿类型,需要将draft值改为false才能看到页面。

 

7.生成静态网站,即生成public文件夹,baseUrl填部署的仓库地址,这里用的github部署。

hugo --theme=XXX --baseUrl="https://xxxx"

所有静态页面都会生成到 public 目录下,生成静态网站后并push到你的GitHub Pages上,就能得到一个在线的个人博客了。

切换到public文件夹,并push到远程仓库。

cd public
git init
git remote add origin https://github.com/xxxx/xxx.git(从仓库的clone那里复制)
git add -A
git commit -m "first commit"
git push -u origin master

之后的更新就只需要后面三句命令就可以了。

posted @ 2018-03-18 13:23  AbelSu  阅读(351)  评论(0编辑  收藏  举报