写作不易,资瓷一下呗!https://raycoder.me
本文首发于[Ray's Blog](https://raycoder.me/p/deploy-your-hugo-blog-to-netlify/
我之前写了一个蠢蠢的脚本,用于自动推送生成完的静态网站:
自以为很好……
不过在看了reuixiy大佬的博客后,才发现他有一个Edit Me
:
点击后发现可以Fork
这个Markdown
文件来修改。
不过俺们这个静态网页好像就不太行……这个脚本<heimu>有毛用!!!!</heimu>
果然是我太嫩了
研究了下人家的博客Repo
没错他是直接推送一个源代码的!
咱们打开netlify.toml
自己也新建一个netlify.toml
(~blog/netlify.toml
)
填入如下内容:
[build]
publish = "public"
command = "npm run build"
[build.environment]
HUGO_VERSION = "YOUR_HUGO_VERSION"
HUGO_ENV = "production"
HUGO_ENABLEGITINFO = "true"
很愉快的push
~
push
成功啦!
Netlify
失败了...
Executing user command: npm run build
npm
ERR! code ENOENT
npm
ERR! syscall open
npm ERR!
path /opt/build/repo/package.json
npm ERR! errno -2
npm
ERR! enoent ENOENT: no such file or directory, open '/opt/build/repo/package.json'
npm
ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent
npm ERR!
A complete log of this run can be found in:
npm ERR! /opt/buildhome/.npm/_logs/2020-03-23T23_50_59_667Z-debug.log
是build
出了问题。于是我们似乎需要npm init
,再对package.json
进行修改:
{
"name": "blog",
"version": "1.0.0",
"description": "Ray's Blog",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "git config --global core.quotePath false && hugo --gc --minify --cleanDestinationDir && ./node_modules/gulp/bin/gulp.js build",
},
"repository": {
"type": "git",
"url": "git+https://github.com/FFRaycoder/blog.git"
},
"keywords": [
"blog",
"hugo",
"hugo-theme-meme"
],
"author": "FFRaycoder",
"license": "CC-BY-NC-SA-4.0",
"bugs": {
"url": "https://github.com/FFRaycoder/blog/issues"
},
"homepage": "https://github.com/FFRaycoder/blog",
"devDependencies": {
"gulp": "^4.0.2",
"gulp-uglify": "^3.0.2",
"readable-stream": "^3.6.0",
"uglify-es": "^3.3.9",
"workbox-build": "^5.0.0"
}
}
当然,./node_modules/gulp/bin/gulp.js build
是可选的:因为我使用了gulp
来创建sw.js
。
其中的配置请自己修改。
每次推送时Netlify会自动运行hugo
指令,并且部署至他们的CDN
~
好哒我们这就成功了~想修改的人可以直接点击下面的Edit Me
,直接PR!