将Hugo站点部署到Cloudflare Pages

建立Hugo站点

参考使用hugo建立静态个人网站,将新建的站点push到github上。

设置Cloudflare Pages

登录https://dash.cloudflare.com/,打开Cloudflare Pages,点击Get started开始设置。

点击创建项目

创建项目

接下来选择存储库,通过gihub账户授权后,选择账户下的hugo存储库,点击开始设置

选择存储库

进入设置构建和部署,参考下图设置好后点击保存并部署开始部署。

设置构建和部署

以下为一次部署成功的详细信息,点击其中的二级域名即可浏览。

部署详细信息

构建日志如下:

20:05:17.479	Initializing build environment
20:05:44.784	Finished
20:05:44.784	Cloning repo
20:05:48.384	Finished
20:05:49.122	Installing dependencies
20:05:49.165	Python version set to 2.7
20:05:52.705	v12.18.0 is already installed.
20:05:53.071	Now using node v12.18.0 (npm v6.14.4)
20:05:53.092	Started restoring cached build plugins
20:05:53.103	Finished restoring cached build plugins
20:05:53.594	Attempting ruby version 2.7.1, read from environment
20:05:54.935	Using ruby version 2.7.1
20:05:55.260	Using PHP version 5.6
20:05:55.308	5.2 is already installed.
20:05:55.311	Using Swift version 5.2
20:05:55.311	Installing Hugo 0.54.0
20:05:56.249	Hugo Static Site Generator v0.54.0-B1A82C61A/extended linux/amd64 BuildDate: 2019-02-01T10:04:38Z
20:05:56.249	Started restoring cached go cache
20:05:56.251	Finished restoring cached go cache
20:05:56.738	go version go1.14.4 linux/amd64
20:05:56.742	go version go1.14.4 linux/amd64
20:05:56.751	Installing missing commands
20:05:56.752	Verify run directory
20:05:56.752	Executing user command: hugo
20:05:56.788	Building sites … 
20:05:56.788	                   | EN  
20:05:56.788	+------------------+----+
20:05:56.788	  Pages            |  4  
20:05:56.788	  Paginator pages  |  0  
20:05:56.789	  Non-page files   |  0  
20:05:56.789	  Static files     |  3  
20:05:56.789	  Processed images |  0  
20:05:56.789	  Aliases          |  0  
20:05:56.789	  Sitemaps         |  1  
20:05:56.789	  Cleaned          |  0  
20:05:56.789	
20:05:56.789	Total in 5 ms
20:05:56.790	Finished
20:05:57.225	Deploying site
20:06:00.105	Finished

添加自定义域名

进入到Cloudflare Pages中可以点击详细的部署实例,点击自定义域添加自定义域名,如下:

添加自定义域名

如果你的域名放到Cloudflare DNS上,系统会提示自动修改域名相关配置并生效。

域名生效

如上图所示,添加的两个自定义域名均已生效。

至此所有配置均已完成,以后如果你的github有新的push,则会触发新的Cloudflare Pages部署。

发布于