Hexo博客搭建相关


Getting Started

1
docker pull spurin/hexo

Create a new blog container, substitute domain.com for your domain and specify your blog location with -v target:/app, specify your git user and email address (for deployment):

1
2
3
4
5
6
7
docker create --name=ideask.github.io \
-e HEXO_SERVER_PORT=4000 \
-e GIT_USER="ideask" \
-e GIT_EMAIL="ideask@outlook.com" \
-v /blog/ideask.github.io:/app \
-p 4000:4000 \
spurin/hexo
1
docker start ideask.github.io

Accessing the container

Should you wish to perform further configuration, i.e. installing custom themes, this should be viable from the app specific volume, either directly or via the container (changes to the app volume are persistent). Accessing the container -

1
2
3
docker exec -it ideask.github.io bash
npm config set registry https://registry.npm.taobao.org
yarn config set registry 'https://registry.npm.taobao.org'

Deployment keys for use with Github/Gitlab

Deployment keys are configured as part of the initial app configuration, see the .ssh directory within your app volume or, view the logs upon startup for the SSH public key

1
docker logs --follow ideask.github.io

Installing a theme

Each theme will vary but for example, a theme such as Hueman, clone the repository to the themes directory within the app volume

1
2
cd /app
git clone https://github.com/Yue-plus/hexo-theme-arknights.git themes/arknights

Update _config.yml in your app folder, and change theme accordingly

1
theme: arknights

Install the environment

1
yarn add hexo-server hexo-browsersync hexo-renderer-pug hexo-renderer-sass hexo-renderer-ts

Exit the container

1
exit

And restart the container

1
docker restart ideask.github.io

Accessing Hexo

Access the default hexo blog interface at http://< ip_address >:4000

Accessing Hexo-Admin

Access Hexo-Admin at http://< ip_address >:4000/admin

Generating Content

1
docker exec -it ideask.github.io hexo generate

New post

Example:

1
2
3
4
5
6
---
title: 'Hello World !'
date: 2020-04-15 21:54:02
tags: code
category: Example
---

New page

1
2
3
4
5
6
7
hexo new page 'about'
vi source/about/index.md

vi _config.yml
->
menu:
About: /about

Deploying Generated Content

1
docker exec -it ideask.github.io hexo deploy

Adding hexo plugins

If you wish to add specific hexo plugins, add them to a requirements.txt file to your app volume, for example (app/requirements.txt) -

1
hexo-generator-json-content

← Prev Ubuntu服务器环境搭建