Hugo-MemE(真)自動(dòng)部署至Netlify

寫(xiě)作不易,資瓷一下唄!https://raycoder.me
本文首發(fā)于[Ray's Blog](https://raycoder.me/p/deploy-your-hugo-blog-to-netlify/

我之前寫(xiě)了一個(gè)蠢蠢的腳本,用于自動(dòng)推送生成完的靜態(tài)網(wǎng)站:

Hugo-Python(偽)自動(dòng)部署

自以為很好……

不過(guò)在看了reuixiy大佬的博客后,才發(fā)現(xiàn)他有一個(gè)Edit Me

點(diǎn)擊后發(fā)現(xiàn)可以Fork這個(gè)Markdown文件來(lái)修改。

不過(guò)俺們這個(gè)靜態(tài)網(wǎng)頁(yè)好像就不太行……這個(gè)腳本<heimu>有毛用?。。?!</heimu>

果然是我太嫩了

研究了下人家的博客Repo

沒(méi)錯(cuò)他是直接推送一個(gè)源代碼的!

咱們打開(kāi)netlify.toml

自己也新建一個(gè)netlify.toml(~blog/netlify.toml)

填入如下內(nèi)容:

[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出了問(wèn)題。于是我們似乎需要npm init,再對(duì)package.json進(jìn)行修改:

{
  "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"
  }
}

當(dāng)然,./node_modules/gulp/bin/gulp.js build是可選的:因?yàn)槲沂褂昧?code>gulp來(lái)創(chuàng)建sw.js

其中的配置請(qǐng)自己修改。

每次推送時(shí)Netlify會(huì)自動(dòng)運(yùn)行hugo指令,并且部署至他們的CDN~

好噠我們這就成功了~想修改的人可以直接點(diǎn)擊下面的Edit Me,直接PR!

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容