使用Zola部署静态博客
Install Zola
你可以用你喜欢的包管理器安装zola
,因为我使用Arch Linux,所以我在这里使用pacman
。
其他发行版(操作系统)详细的安装指南请移步Zola 官方文档。
Configuration Zola
初始化Zola
运行init会有三个问题,默认即可,这些选择都可以在之后的config.toml
中配置。
> What is the URL of your site? (https://example.com):
> Do you want to enable Sass compilation? [Y/n]:
> Do you want to enable syntax highlighting? [y/N]:
> Do you want to build a search index of the content? [y/N]:
这是默认的config.toml
:
# The URL the site will be built for
= "https://example.com"
# Whether to automatically compile all Sass files in the sass directory
= true
# Whether to build a search index to be used later on by a JavaScript library
= false
[]
# Whether to do syntax highlighting
# Theme can be customised by setting the `highlight_theme` variable to a theme supported by Zola
= false
[]
# Put all your custom variables here
构建网页
运行本地实施更新的服务器
安装使用主题
这里我选择使用serene
,这是在我浏览zola主题时发现的一款简洁、美观、功能丰富的zola主题。
安装serene主题,实际上就是把主题仓库clone到本地的themes目录下。
serene主题提供了config.toml
示例,我们直接使用示例配置替换默认配置并根据注释和主题文档配置。
之后请根据isunjn/serene的README配置主题。
推送到 GitHub1
添加远程存储库
部署Cloudflare Pages2
Note
以下内容假定你已经拥有并登录Cloudflare账号,且已将源文件push到远程仓库。
在 Account Home, 选择 Workers & Pages > Create application > Pages > Connect to Git.
选择你放置blog源文件的GitHub存储库, 在Set up builds and deployments 页面, 选择你要使用的branch,这里我们选择main。在Framework preset 选择zola。
Configuration option | Value |
---|---|
Production branch | main |
Build command | zola build |
Build directory | public |
在下面的Environment variables (advanced) 新建以下变量3:
Variable name | Value |
---|---|
ZOLA_VERSION | 0.19.2 |
UNSTABLE_PRE_BUILD | asdf plugin add zola <https://github.com/salasrod/asdf-zola> && asdf install zola 0.19.2 && asdf global zola 0.19.2 |
若不添加第二个变量会出现部署错误,value内的版本号可随zola更新调整。写这篇教程时zola的最新版本是0.19.2
。
点击Save and Deploy,开始你的第一次部署。在部署完成后,你可以在<你的项目名>.pags.dev
查看你的blog。
你可以在config.toml
中将base_url
的值指向这个子域名
例如:
# The URL the site will be built for
= "https://my-zola-project.pages.dev"
绑定自定义域名请参考Custom domains · Cloudflare Pages docs,之后将base_url
指向你新绑定的域名即可。
部署到Github Pages
TODO
Reference
https://github.com/git-guides GitHub Git Guide
https://developers.cloudflare.com/pages/framework-guides/deploy-a-zola-site/ Cloudflare Pages docs