0%

Hello Hexo

Create blog

Pre-requirements

The blog framework used is Hexo

  • A fast, simple & powerful blog framework!
  • Powered by Node.js

The remote site used is Github Pages

Install the CLI(command-line interface) of Hexo via npm

1
2
$ npm install hexo-cli -g
#

Initialise Hexo

1
2
3
$ hexo init <folder>
$ cd <folder>
$ npm install

More info: about npm install(with no args, in package dir)

Deploy to the remote server

Install hexo-deployer-git

1
$ npm install hexo-deployer-git --save

And then open the _config.yml in the root directory
edit settings :

1
2
3
4
5
deploy:
type: git
repo: <repository url>
branch: [branch]
message: [message]

Deploy to remote sites after generate static files

1
$ hexo g -d

or

1
$ hexo d -g

More info: about Generating and Deployment

At last

1
2
# install sleepms, concurrently, open-cli first
$ npm i -D sleepms concurrently open-cli@6.0.0

open the package.json in the root directory,
and then add scripts to run hexo-cli command line combination via npm,

Then just like:

1
2
3
4
5
6
7
8
9
10
"scripts": {
"deploy": "hexo clean && hexo g -d && open-cli https://yourname.github.io",
"serve": "hexo clean && concurrently \"hexo server -p 1314\" \"hexo g -w\" \"sleepms 5000 && open-cli http://localhost:1314/\""
},
// ...
"devDependencies": {
"concurrently": "^3.6.1",
"open-cli": "^6.0.0",
"sleep-ms": "^2.0.1"
}

More info :

generate files, deploy and browse site online

1
$ npm run deloy

generate files, watching changes and use local server to browse page

1
$ npm run serve

More info :

  • if when you run hexo server and the port is occupied, you can try to stop the occupied port manually, (Windows OS can do so)
  • Using git deployer, so the deployment should be through Git Bash, and if execute npm run dist error that fatal: Unable to create 'path/.git/index.lock': File exists., check to see if .deploy_git already exists, delete it and execute npm run dist again.

Q&A

If you encounter the following problems

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
TypeError [ERR_INVALID_ARG_TYPE]: The "mode" argument must be integer. Received an instance of Object
at copyFile (node:fs:2766:10)
at copyFile ({{path xxx}}/yourname.github.io/node_modules/graceful-fs/graceful-fs.js:181:12)
at tryCatcher ({{path xxx}}/yourname.github.io/node_modules/bluebird/js/release/util.js:16:23)
at ret (eval at makeNodePromisifiedEval ({{path xxx}}/yourname.github.io/node_modules/bluebird/js/release/promisify.js:184:12), <anonymous>:13:39)
at {{path xxx}}/yourname.github.io/node_modules/hexo-deployer-git/node_modules/hexo-fs/lib/fs.js:181:12
at tryCatcher ({{path xxx}}/yourname.github.io/node_modules/bluebird/js/release/util.js:16:23)
at Promise._settlePromiseFromHandler ({{path xxx}}/yourname.github.io/node_modules/bluebird/js/release/promise.js:547:31)
at Promise._settlePromise ({{path xxx}}/yourname.github.io/node_modules/bluebird/js/release/promise.js:604:18)
at Promise._settlePromise0 ({{path xxx}}/yourname.github.io/node_modules/bluebird/js/release/promise.js:649:10)
at Promise._settlePromises ({{path xxx}}/yourname.github.io/node_modules/bluebird/js/release/promise.js:729:18)
at Promise._fulfill ({{path xxx}}/yourname.github.io/node_modules/bluebird/js/release/promise.js:673:18)
at Promise._resolveCallback ({{path xxx}}/yourname.github.io/node_modules/bluebird/js/release/promise.js:466:57)
at Promise._settlePromiseFromHandler ({{path xxx}}/yourname.github.io/node_modules/bluebird/js/release/promise.js:559:17)
at Promise._settlePromise ({{path xxx}}/yourname.github.io/node_modules/bluebird/js/release/promise.js:604:18)
at Promise._settlePromise0 ({{path xxx}}/yourname.github.io/node_modules/bluebird/js/release/promise.js:649:10)
at Promise._settlePromises ({{path xxx}}/yourname.github.io/node_modules/bluebird/js/release/promise.js:729:18)

Please switch to the old version of node, such as 12.4.0

Postscript:

Customize the pretty style, configure the local search, add comment and so on by the powerful and interesting third party theme NexT,
Through a variety of technical to add a variety of plugins…
The blog was born O(∩ _ ∩)O~