尝试过 Hexo 、GatsbyJs、 Vuepress 搭建博客后,对这些工具最大的不满,就是运行速度以及打包速度。
后来看到 Hugo ,号称最快的静态站点生成器后。
尝试搭建博客,发现不管是运行速度,还是打包速度超级快,果断将个人博客迁移到 Hugo。
Hugo 官方的定义是:
Hugo is a fast and modern static site generator written in Go, and designed to make website creation fun again.(Hugo 是使用 Go 编写的快速而现代的静态站点生成器,旨在使网站创建变得有趣。)
安装 hugo
brew install hugo
安装完成后,在命令行输入以下命令验证安装:
MacBook-Pro:demo lucky$ hugo version Hugo Static Site Generator v0.69.1/extended darwin/amd64 BuildDate: unknown
输出版本信息表示安装成功,更多安装方式查看 https://gohugo.io/getting-started/installing
建立 Hugo 项目
一个 Hugo 项目就是一个站点,创建命令如下:
hugo new site [project-name]
例如我的站点名称是 quickstart,创建命令如下:
hugo new site quickstart
创建完成后,在 centos 文件夹下会生成以下文件结构:
MacBook-Pro:~ lucky$ ls -l quickstart total 8 drwxr-xr-x 3 lucky staff 96 4 23 17:53 archetypes -rw-r--r-- 1 lucky staff 82 4 23 17:53 config.toml drwxr-xr-x 2 lucky staff 64 4 23 17:53 content drwxr-xr-x 2 lucky staff 64 4 23 17:53 data drwxr-xr-x 2 lucky staff 64 4 23 17:53 layouts drwxr-xr-x 2 lucky staff 64 4 23 17:53 static drwxr-xr-x 2 lucky staff 64 4 23 17:53 themes
添加主题
为了快速搭建博客,可以使用主题。使用主题后,只需要向 content 文件夹添加 Markdown 文件即可。
MacBook-Pro:~ lucky$ cd quickstart MacBook-Pro:quickstart lucky$ git init 已初始化空的 Git 仓库于 /Users/lucky/quickstart/.git/ MacBook-Pro:quickstart lucky$ git submodule add https://github.com/budparr/gohugo-theme-ananke.git themes/ananke
将主题添加到站点配置中:
MacBook-Pro:quickstart lucky$ echo 'theme = "ananke"' >> config.toml
添加一些内容
MacBook-Pro:quickstart lucky$ hugo new posts/my-first-post.md /Users/lucky/quickstart/content/posts/my-first-post.md created
启动Hugo服务器
MacBook-Pro:quickstart lucky$ hugo server -D Building sites … WARN 2020/04/24 11:06:58 Page.URL is deprecated and will be removed in a future release. Use .Permalink or .RelPermalink. If what you want is the front matter URL value, use .Params.url | EN -------------------+----- Pages | 10 Paginator pages | 0 Non-page files | 0 Static files | 3 Processed images | 0 Aliases | 1 Sitemaps | 1 Cleaned | 0 Built in 14 ms Watching for changes in /Users/lucky/quickstart/{archetypes,content,data,layouts,static,themes} Watching for config changes in /Users/lucky/quickstart/config.toml Environment: "development" Serving pages from memory Running in Fast Render Mode. For full rebuilds on change: hugo server --disableFastRender Web Server is available at http://localhost:1313/ (bind address 127.0.0.1) Press Ctrl+C to stop
浏览器查看
继续阅读
- 我的QQ
- QQ扫一扫
-
- 我的头条
- 头条扫一扫
-
评论