public:: true
title:: Hugo+Netlify部署博客
alias:: Hugo+Netlify部署博客
file:: 2019030801.md
date:: 2019-03-08 19:37:38
tags:: Hugo, Github
description:: “Hugo+Netlify部署博客”

Hugo

安装

  • 下载Hugo 如主题提示需要扩展包,选择相应的文件包 参考文档 中文文档
  • 解压后放置你准备的目录,将hugo.exe所在目录添加到环境变量path后面
  • 验证
  1. # 验证安装
  2. $ hugo version

生成站点

  • 在希望的路径下执行
  1. # 生成站点
  2. $ hugo new site /path/to/site
  • 进入目录后创建文章
  1. # 创建页面
  2. $ cd site
  3. $ hugo new about.md
  4. # 创建文章
  5. $ hugo new post/first.md
  • 安装皮肤
  1. # 创建 themes 目录
  2. $ cd themes
  3. $ git clone https://github.com/spf13/hyde.git
  4. # 如果需要部署到Netlify,采用以下方式
  5. $ cd site
  6. $ git submodule add https://github.com/alex-shpak/hugo-book themes/book
  • 运行Hugo

在你的站点根目录执行 Hugo 命令进行调试:

  1. # 运行Hugo
  2. $ cd site
  3. $ hugo server --theme=hyde --buildDrafts

浏览器里打开: http://localhost:1313

  • 部署

在站点根目录执行 Hugo 命令生成最终页面

  1. # 生成最终页面
  2. $ cd site
  3. # 部署到GitHub
  4. $ git add .
  5. $ git commit -m "Create blog.wesvi.com"
  6. $ git push -u origin master

部署到netlify

网站根目录添加netlify.toml,参考内容如下:Netlify参考文档

  1. [build]
  2. publish = "public"
  3. command = "hugo --gc --minify"
  4. [context.production.environment]
  5. HUGO_VERSION = "0.68.0"
  6. HUGO_ENV = "production"
  7. HUGO_ENABLEGITINFO = "true"
  8. [context.split1]
  9. command = "hugo --gc --minify --enableGitInfo"
  10. [context.split1.environment]
  11. HUGO_VERSION = "0.68.0"
  12. HUGO_ENV = "production"
  13. [context.deploy-preview]
  14. command = "hugo --gc --minify --buildFuture -b $DEPLOY_PRIME_URL"
  15. [context.deploy-preview.environment]
  16. HUGO_VERSION = "0.68.0"
  17. [context.branch-deploy]
  18. command = "hugo --gc --minify -b $DEPLOY_PRIME_URL"
  19. [context.branch-deploy.environment]
  20. HUGO_VERSION = "0.68.0"
  21. [context.next.environment]
  22. HUGO_ENABLEGITINFO = "true"

配置

https://gohugo.io/getting-started/configuration/

参考资料

  1. 如何制作个人学术主页
  2. 使用Hugo搭建自己的博客 - 简书
  3. Hosting on GitHub Pages - Hugo中文文档
  4. Hugo-框架学习

Hugo themes

https://www.xianmin.org/

https://github.com/xianmin/hugo-theme-jane

https://github.com/servicemesher/website

Hugo输出API

主要参考以下两篇文章

使用 Hugo 生成 API 接口

hugoGetApi,但这篇文章里由于版本原因,其实例代码里修改config.toml文件中suffix为suffixes