利用Hugo搭建个人博客

Apr 13, 2018 15:48 · 619 words · 2 minute read

安装 brew,用 brew 安装 Hugo, brew install hugo

关于 Hugo 是一种静态网站生成器,可用于搭建个人博客、小型公司网站,是一种 CMS 系统。mac 版,可直接在终端安装 brew install Hugo 使用Hugo快速生成站点,例如在该路径 /hugo/blog下:

hugo new site /hugo/blog

然后 cd /hugo/blog ,可看到以下目录文件

▸ archetypes/

▸ content/

▸ data/

▸ themes/

▸ layouts/

▸ static/

config.toml

archetypes 里放置一些原型,可以配置一些新建内容属性,在 content 里放网站里的内容,static 下存放静态文件资源。themes 下是我们选择的主题。config.toml 是网站配置文件。 我们可以使用以下命令创建一个新的文件:

hugo new post/hi.md

hugo 会在 content 目录下创建 post 目录,在 post 目录下创建 hi.md 文件

为 Hugo 配置自己喜欢的主题

hugo主题网站有各种不同风格的网站,我们可以选择自己喜欢的,我选择的是一款比较简洁的主题cactus-plus。然后命令行,执行以下命令:

cd themes
git clone https://github.com/nodejh/hugo-theme-cactus-plus.git

接着配置config.toml ,去对应主题的官网参考config.toml配置。配置好以后,你可以输入以下命令:

hugo server

启动本地服务,进行项目预览。本地测试没有问题,就可以准备发布到github了。 执行以下命令:

hugo -t hugo-theme-cactus-plus

部署到 github

新建一个 rep, 命名为 ‘ githubName.github.io’就可以了。执行命令 hugo -t hugo-theme-cactus-plus后,会发现多出一个 public 文件夹。命令行进入 public 文件夹,初始化 git。

cd public
git init
git remote add origin https://github.com/yourGithubName/yourGithubName.github.io.git
git add .
git commit -m 'Init commit'
git push -u origin master

去浏览器打开http://yourGithubName.github.io/(不可浏览啊) 就能看到自己的个人主页了。

tweet Share