What is Hexo?
Hexo is a fast, simple and powerful blog framework. You write posts in Markdown (or other languages) and Hexo generates static files with a beautiful theme in seconds.
Requirements
Installing Hexo is quite easy. However, you do need to have a couple of other things installed first:
- Node.js
- Git (complete First-Time Git Setup)
For Chinese users, it is recommended to use cnpm.
Tip: If using Arch Linux, notice Arch Wiki: Node.js#Allow_user-wide_installations.
|
|
Installation
Run the following commands
|
|
Then you can see a web page at http://localhost:4000/.
Or a more convenient way: use neoFelhz’s HexoKit.
Usage
For more information, visit https://hexo.io/docs/commands.html.
|
|
In addition, Hexo provides tag plugins: a useful way for you to quickly add specific content to your posts. For more information, visit https://hexo.io/docs/tag-plugins.
Themes
I recommend hexo-theme-next and hexo-theme-material. Please read a short comparison of popular Hexo themes at https://en.abnerchou.me/Blog/5c00ca67. For more themes, visit https://hexo.io/themes/index.html.
Tip: hexo-theme-next suggests us replacing
themes/next/_config.yml
ofsource/_data/next.yml
(see hexo-theme-next #Theme configurations using Hexo data files).
Website Optimization
A simple optimizing tool: Gulp. Gulp is a toolkit for automating painful or time-consuming tasks in your development workflow.
Tip: hexo-all-minifier is a more convenient plugin, but maybe with more problems.
|
|
Need gulpfiles.js
in the root of hexo-site (like my gulpfile.js).
Then the following command (if use my gulpfiles.js) will optimize your generated files.
|
|
SEO (Search Engine Optimization): it seems useless…
Tip: You may want to use hexo-abbrlink.to create one and only one link for every post.
Other optimizations can’t be implemented without Web server (actually not, I just think we’d better wait for developers’ hard work).
Deployment
Here are several hosting service providers, which should we choose?
GitHub Pages
GitHub Pages is designed to host your personal, organization, or project pages directly from a GitHub repository.
What is GitHub Pages? says it
- may be no larger than 1GB
- limit of 10 builds per hour
- limit of 100GB or 100,000 requests per month
It’s easy to use hexo-deployer-git to complete deployment (find other deployer plugins at: https://hexo.io/docs/deployment.html).
For example, if you want to push the source files and generated files at the same time to two different branches, the option should be like
|
|
Coding Pages (Recommend)
It’s recommended to host your site to Coding Pages if you are in China (i.e., you main readers are Chinese). Just add Hosted by Coding Pages
to avoid redirection.
Coding Pages 介绍 says that it
- no larger than 100MB
- limit of 10 builds per hour
- redirect *.coding.me to a custom domain automaticlly
- One-Click SSL: free SSL certificate
- Force SSL: set a redirect from HTTP to HTTPS
Use it as same as GitHub Pages. Just one difference: don’t need CNAME
file, please set Pages service settings.
Netlify (Recommend)
“Netlify has everything you need to make a high performance site or web-app. You just push your code.”
–Tom Preston-Werner, Founder of GitHub & Creator of Jekyll
I think Netlify is the best chice. Netlify Docs says that they provide:
- One-Click SSL: Netlify integrates with Let’s Encrypt and automatically provisions, distributes and renews your certificate
- HTTP/2 works when HTTPS is enabled
- Force SSL
- Continuous Deployment: Each time you push to GitHub, Netlify runs a build with your tool of choice and deploys the result to CDN
Netlify lets you link a GitHub repository to a site. Each time you push to GitHub, Netlify runs a build with your tool of choice and deploys the result to Netlify’s powerful CDN. You also can deploy your static site without linking a GitHub (or GitLab) repository.
Use web UI or command line tools to deploy and generate.
By the way: Matt Biilmann and Netlify recommends
www.
domain unless you use ALIAS records or ANAME records, I’m naive, I dropwww.
directly. Users can’t remove thesitename.netlify.com
“default” hostname on Netlify, so I have three blog addresses now.
Firebase
Deploying site to Firebase may be a good choice.
Firebase Hosting tells us Firebase
- files deployed to Firebase Hosting are cached on SSDs at CDN edge servers around the world
- provides free SSL certificates for custom domains
- force SSL
Read Firebase Hosting Docs to learn how to deploy static site to Firebase.
You need to cross GFW, and have a Google account.
Login and create a project in Firebase console, get project-id.
|
|
In fact, Firebase is user-friendly (it has Chinese tutorial), just need to follow its guides. In its console, you can see your history record and learn how to bind domain name.
Edit firebase.json to determine which files should be deployed.
Easy Deploy: Script
Life is short, why not using npm-run-script?
Add "scripts": {}
to package.json, as follows:
|
|
Then the following command will cover:
hexo clean
: clean the cache file (db.json) and generated files (public)hexo g
: generate static filesgulp build
: optimize generated fileshexo d
: you can push the source files to GitHub
|
|
However, if you use Linux, you may prefer create a shell script, or edit .zshrc
(or .bashrc
?).
For example: a shell script.
|
|
|
|
Or edit ~/.zshrc.
|
|
|
|
Image Hosting
Hexo’s Asset Folders allows us to keep images in source/images folder, use something like 
to access them.
I use Imgur to store images for this blog. There are some other choices (please refer to https://blog.nfz.moe/archives/collection-of-image-hosting.html).
HTTPS and Secure Symbol
If you get SSL certificates for your custom domains, and in your pages “absolute” URLs point to secure content - images, scripts and css files (all need HTTPS), then, to the left of the web address, Firefox and Chrome (or Chromium) will show (like this blog):
Secure
Otherwise, will show:
Info or Not secure
You can use JitBit to scan your website for non-secure content.
I don’t think a secure symbol provided by Chrome or Firefox is important… But it seems that browsers force us be “secure”.
About This Blog
Comment system? I’m waiting for Feature: Add Gitalk Support #1814, as I mentioned above, we’d better wait for developers’ hard work. Here is my whole custom settings: README.md.
My blog is “hosted by Netlify”, but all of the following domains are avaliable now.
I’m considering using Travis CI or GitLab CI, which may make blogging more convenient (post and edit using Git, not need strict development environment). But Netlify seems convenient enough…
Others’ relative articles: