nextlify部署hugo blog
参考:
hugo官方: https://gohugo.io/hosting-and-deployment/hosting-on-netlify
nextlify官方: https://docs.netlify.com/integrations/frameworks/hugo/
步骤
上传项目到github仓库, 该仓库可以是私人仓库
hugo的主题必须是
git submodule形式, 如果自定义主题, 上传到gihub仓库上, 以子模块方式引入在
.gitignore里排除public文件夹在项目根目录下新建文件
netlify.toml1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30[build] publish = "public" command = "hugo --gc --minify" [context.production.environment] HUGO_VERSION = "0.65.3" HUGO_ENV = "production" HUGO_ENABLEGITINFO = "true" [context.split1] command = "hugo --gc --minify --enableGitInfo" [context.split1.environment] HUGO_VERSION = "0.65.3" HUGO_ENV = "production" [context.deploy-preview] command = "hugo --gc --minify --buildFuture -b $DEPLOY_PRIME_URL" [context.deploy-preview.environment] HUGO_VERSION = "0.65.3" [context.branch-deploy] command = "hugo --gc --minify -b $DEPLOY_PRIME_URL" [context.branch-deploy.environment] HUGO_VERSION = "0.65.3" [context.next.environment] HUGO_ENABLEGITINFO = "true"注册Nextlify,可以用github账号授权
选择
“New site from Git”——“Github”——选择自己hugo博客源码对应的仓库在
Deploy之前可以先设置下,"site overview"--"site setting"--"change site name", 不改的话会默认分配https://xxx-xxx-xxx.netlify.app一堆符号的二级域名Deploy status badge徽章可以放到项目的readme上, 可以看到最新部署状态Deploy
每次仓库更新, netlify就会自动部署
可选: 绑定域名
Site settings -- Domain management--Custom domains--Add domain alias--填写域名--verify--Yes,add domain- 填写后到DNS 解析提供商里面,将 CNAME 记录值更改为 Netlify 给你的二级域名
- https: 隔一段时间后点
Verify DNS configuration
可能的问题
- 报错:
| |
“setting”——“Build&deploy”——“Environment”——"Environment variables"——“Edit variables”,左边填“HUGO_VERSION”,右边填“v?.?.?”。
注:版本号以实际为准
报错
1 2The build image for this site uses Ubuntu 16.04 Xenial Xerus, which is no longer supported. # ubuntu 版本过低"Deploys"--"Delploy settings"--"Build image selection"--"Edit settings"--选最新的重新部署