Hugo-MemE/Hexo(真)自动推送部署至Netlify

gakki的二向箔 2020-04-07

Hugo


我之前写了一个蠢蠢的脚本,用于自动推送生成完的静态网站:

Hugo-Python(伪)自动部署

自以为很好……

不过在看了reuixiy大佬的博客后,才发现他有一个Edit Me

Hugo-MemE/Hexo(真)自动推送部署至Netlify

点击后发现可以Fork这个Markdown文件来修改。

不过俺们这个静态网页好像就不太行……这个脚本有毛用!!!!

果然是我太嫩了

Hugo-MemE/Hexo(真)自动推送部署至Netlify

研究了下人家的博客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会{{< udpoint "自动运行" >}}hugo指令,并且部署至他们的CDN~

好哒我们这就成功了~想修改的人可以直接点击下面的Edit Me,提个PR给我!

Hexo


Hexo倒要比Hugo简单:Hexo的node_moudles会在执行Hexo命令时自动运行。实现Hexo甚至不需要修改~blog/packages.json

修改你的Deploy Settings,更改成如图:

Hugo-MemE/Hexo(真)自动推送部署至Netlify

只需你推送博客源码,Netlify就会{{< udpoint "自动帮你部署博客" >}}!!!太贴心了吧~

这样的好处是什么呢?我们都知道hexo g生成文件很慢,hexo d比你自己推送都慢??貌似是因为hexo要推送全部的静态文件。使用Netlify自动部署后,你只需要推送一篇新的博文,你的网站就自动帮你部署好啦~~~

还有一点:如果你的网站hexo g出现了错误,Netlify会自动回滚到前一个版本,保持你网站的正常访问!

赶快入坑~

Hugo-MemE/Hexo(真)自动推送部署至Netlify

相关推荐

JingLisen / 0评论 2020-01-06