# Hugo 搭建指南 + Even 主题使用 Hugo是Go 语言写了一个静态网站生成器,解决了环境依赖、性能较差问题。作为解释型语言,应对大量的文章生成速度明显优于Hexo。本文详细介绍了Hugo( Windows的二进制版)的搭建放法,并且使用Even主题。 ## Hugo常用命令 ``` hugo # 生成静态文件 hugo server # 启动服务器,默认http://localhost:1313/ ``` ## Hugo使用指南 Hugo的官网是:[The world’s fastest framework for building websites | Hugo (gohugo.io)](https://gohugo.io/) Hugo中文文档:[Hugo中文文档 (gohugo.org)](https://www.gohugo.org/) Hugo的GitHub:[gohugoio/hugo: The world’s fastest framework for building websites. (github.com)](https://github.com/gohugoio/hugo) 这里我先使用的是hugo_0.87.0_Windows-64bit.zip,后来选择主题时需要extend版,于是使用了 hugo_extended_0.87.0_Windows-64bit.zip。当然也可以使用编译方法,不过需要搭建相应的环境。 下载相应文件并解压,使用PowerShell进入相应的目录。 ## Hugo 创建一个站点框架 ```shell hugo new site path/to/site cd path/to/site ``` 这时,使用ls命令,可以看到所有新建的站点文件,config.toml是我们使用主题要修改的文件。 ## 创建或迁移文章 创建文章: ```shell hugo new about.md hugo new post/article1.md ``` 第一句创建了一个about.md ,第二句在post文件夹中创建了article1。我们可以看到,Hugo会使用 archetypes/default.md 模板初始化文章。 ## 使用Even主题 使用这个主题的重要原因就是其中README和注释都有中文。 GitHub项目网址:[olOwOlo/hugo-theme-even: 🚀 A super concise theme for Hugo https://hugo-theme-even.netlify.app (github.com)](https://github.com/olOwOlo/hugo-theme-even) 中文说明:[hugo-theme-even/README-zh.md at master · olOwOlo/hugo-theme-even (github.com)](https://github.com/olOwOlo/hugo-theme-even/blob/master/README-zh.md) 要做的事项: 1. git 或 下载一个版本,解压到站点的themes文件夹,如果使用的是zip版本,将 hugo-theme-even-4.1.0 这样的文件夹名改为 even 。 2. 正常使用主题可修改站点下的config.toml。Even主题的 exampleSite目录下 config.toml 文件为主题范例配置,将 config.toml 文件复制到站点目录下,然后按需更改。具体更改参考其中中文注释。 3. 复制 themes/even/archetypes/default.md 到站点的 archetypes 文件夹下,此后命令行生成新文章时会按此模板进行生成,同时也可按需更改,如 ``` --- title: "电影《狗13》中讨好型人格的分析" tags: ["影评"] categories: ["生活"] slug: 20586 date: 2020-05-13T14:09:00 keywords: ["《狗13》","讨好型人格"] description: "电影《狗13》中讨好型人格的分析" --- 文章简介 文章内容 ``` 其中slug表示文章网址如 http://localhost:1313/post/20586/ 。 themes/even/archetypes/default.md 列出主题所有可选项,并不需要全都配置。其中默认值部分可在config.toml中配置。 4. 其他配置见[hugo-theme-even/README-zh.md at master · olOwOlo/hugo-theme-even (github.com)](https://github.com/olOwOlo/hugo-theme-even/blob/master/README-zh.md)。其中包含网站图标,语言支持,网站主题(需要extend版本)。 ## 部署 修改config.toml中的baseURL后,编写脚本,同步到要部署的网站。 ## 注意 Hugo没有默认主题,必须下载主题。