hugo 图片_55.使用Hugo快速建站

安装Hugo

不使用数据库存放文章数据,每一篇文章都是一个markdown文件.
hugo可以server运行,也可以编译成静态的html页面,让Nginx运行解析.因为是纯静态页渲染,性能超强……
到 Hugo Releases 下载对应的操作系统版本的Hugo二进制文件,解压到/usr/local/bin/

这样就可以直接使用 hugo 命令了

创建站点

#hugo new site /path/to/site#例如本站的创建hugo new site /data/hugo/jiagou.com

这样就在 /path/to/site 目录里生成了初始站点,进入目录:

 ▸ archetypes/  ▸ content/  --存放markdown文件,文章内容  ▸ data/    ▸ layouts/    ▸ static/   --静态资源根目录(/),文章内的图片,附件等静态资源  ▸ themes/   --存放网站主题   config.toml --网站的核心配置文件

下载主题,放到 themes 目录下,本站是使用了even主题

创建页面

#创建 about 页面hugo new about.md

about.md 自动生成到了 content/about.md ,打开 about.md 看下:

---date = "2015-10-25T08:36:54-07:00"  --时间draft = true --是否是草稿title = "about" --标题---正文内容

内容是 Markdown 格式的,--- 之间的内容是YAML 格式的,根据你的喜好,你可以换成 TOML 格式(使用 +++ 标记)或者 JSON 格式.

可以在 archetypes/default.md 中定义默认模板,例如本站的默认模板内容是

---title: "{{ replace .Name "-" " " | title }}"date: {{ .Date }}draft: falsetags: ["web"]categories: ["web"]author: "springrain"---

创建第一篇文章,放到 post 目录,其他文章页都尽量放到post目录,方便之后生成聚合页面.

hugo new post/first.md

server运行(本站未使用)

# hugo server 默认是1313端口hugo server -p 80 -b http://39.98.249.100/  --bind "0.0.0.0"

server方式运行,hugo就是web服务器了,负责响应http请求,解析markdown文件

静态运行(本站使用)

每次发布都需要进入到站点目录,运行hugo命令

#进入到站点目录cd /data/hugo/jiagou.com#编译markdown文件为html,放到站点的public目录,本站是/data/hugo/jiagou.com/publichugo

安装nginx

本站主要Nginx配置

### HTTPS server ###    server {         ### 代替 ssl on###        listen 443 ssl;         server_name www.jiagou.com;        ### SSL 设置 开始 ####        ### 1.15版本之后,使用 listen 443 ssl 代替###        ###ssl                 on;             ssl_certificate /usr/local/nginx/ssl/www.jiagou.com/4468359_www.jiagou.com.pem;          ssl_certificate_key /usr/local/nginx/ssl/www.jiagou.com/4468359_www.jiagou.com.key;        ssl_session_timeout 5m;        ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4; #使用此加密套件.        ssl_protocols TLSv1 TLSv1.1 TLSv1.2; #使用该协议进行配置.        ssl_prefer_server_ciphers on;        location / {            root   /data/hugo/jiagou.com/public;            index  index.html index.htm;        }    }

配置

本站 config.yoml中的主要配置

baseURL = "http://39.98.249.100:80/"languageCode = "zh-cn"defaultContentLanguage = "zh-cn"                             # en / zh-cn / ... (This field determines which i18n file to use)title = "架构"preserveTaxonomyNames = trueenableRobotsTXT = trueenableEmoji = truetheme = "even"enableGitInfo = false # use git commit log to generate lastmod record # 可根据 Git 中的提交生成最近更新记录.# Syntax highlighting by Chroma. NOTE: Don't enable `highlightInClient` and `chroma` at the same time!pygmentsOptions = "linenos=table"pygmentsCodefences = truepygmentsUseClasses = truepygmentsCodefencesGuessSyntax = truehasCJKLanguage = true     # has chinese/japanese/korean ? # 自动检测是否包含 中文日文韩文paginate = 10                                              # 首页每页显示的文章数disqusShortname = ""      # disqus_shortnamegoogleAnalytics = ""      # UA-XXXXXXXX-Xcopyright = "jiagou.com 版权所有 豫ICP备2020026846号-1   豫公网安备41010302002680号"            # default: author.name ↓        # 默认为下面配置的author.name ↓[taxonomies]    category = "categories"  tag = "tags"  #web ="web"[author]                  # essential                     # 必需  name = "jiagou.com"[sitemap]                 # essential                     # 必需  changefreq = "weekly"  priority = 0.5  filename = "sitemap.xml"[[menu.main]]             # config your menu              # 配置目录  name = "Home"  weight = 10  identifier = "home"  url = "/"[[menu.main]]  name = "CloudNative"  weight = 20  identifier = "cloudnative"  url = "/categories/cloudnative/"[[menu.main]]  name = "BigData"  weight = 30  identifier = "bigdata"  url = "/categories/bigdata/"[[menu.main]]  name = "Web"  weight = 40  identifier = "web"  url = "/categories/web/"

even主题修改

我主要是修改了even主题的底部文件模板footer.html
路径是 themes/even/layouts/partials/footer.html

本站文章例子

本站about.md的完整内容如下:

---title: "About"date: 2017-08-20T21:38:52+08:00lastmod: 2017-08-28T21:41:52+08:00menu: "main"weight: 50---本站使用1核CPU,512M内存,20G硬盘的阿里云服务器.  使用hugo和even模板,编译成静态文件,Nginx作为WEB服务器.  我所见识过的一切都将消失一空,就如眼泪消逝在雨中......  不妨大胆一些,大胆一些......  小项目:  * [springrain](https://gitee.com/chunanyong/springrain)* [javadoc4openapi-maven-plugin](https://gitee.com/chunanyong/javadoc4openapi-maven-plugin)* [zorm](https://gitee.com/chunanyong/zorm)* [gowe](https://gitee.com/chunanyong/gowe)

头条代码样式不太好,影响阅读体验,请访问原文链接或者点击 [了解更多]

https://www.jiagou.com/post/55-hugo-even-config

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值