Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
韦竞
/
glsx-hexo
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 61f612a4
authored
Mar 28, 2022
by
韦竞
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
reflash
1 parent
1fda24b9
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
119 additions
and
79 deletions
README.md
README.md
View file @
61f612a
# Docker部署hexo脚本
**快速、简洁且高效的博客框架,Node.js 所带来的超快生成速度,让上百个页面在几秒内瞬间完成渲染。**
**只需一条指令即可部署到 GitHub Pages, Heroku 或其他网站。**
**Hexo 拥有强大的插件系统,安装插件可以让 Hexo 支持 Jade, CoffeeScript。**
## 1、本地环境运行
## 目录说明
```
bash
blog
├── data
# 存放你的hexo博客根目录下所有内容
├──
source
# 存放你的hexo博客的source文件夹下的内容
└── themes
# 存放你的hexo博客的themes的内容
```
npm install hexo-cli -g
hexo init blog
cd blog
npm install
hexo server
```
到这里,你的hexo博客已经初始化好了, blog/public文件夹下面已经生成了对应的HTML文件.
## 食用方法:

1.
将本项目clone到
```/home/blog```
下
```
bash
cd
/home/blog
git clone https://github.com/xia5800/docker-hexo.git
```
2.
给shell脚本添加可执行权限
## 2、docker 部署运行
```
bash
chmod +a
*
.sh
```
### 什么是 Dockerfile?
3.
初始化
Dockerfile 是一个用来构建镜像的文本文件,文本内容包含了一条条构建镜像所需的指令和说明。
```
bash
./init-blog.sh
```
4.
浏览器访问
```http://服务器ip:8080```
### 使用 Dockerfile 定制镜像
这里仅讲解如何运行 Dockerfile 文件来定制一个hexo博客镜像,具体 Dockerfile 文件内指令详解。
##
更新博客
##
# 开始构建镜像
博客启动成功之后,如果上传了新文章或者对以前的文章进行了更改, 只需要执行
在 Dockerfile 文件的存放目录下,执行构建动作。
```
bash
./restart-blog.sh
```
即可对博客内容进行更新。
如果修改了主题或者hexo的配置文件,则需要执行
```
bash
./config-blog.sh
[root@nagios ~/github/glsx-hexo/data]# ll
总用量 196
-rw-r--r-- 1 root root 0 3月 28 11:56 _config.landscape.yml
-rw-r--r-- 1 root root 2441 3月 28 11:56 _config.yml
-rw-r--r-- 1 root root 25595 3月 28 14:03 db.json
-rw-r--r-- 1 root root 453 3月 28 16:51 Dockerfile
-rw-r--r-- 1 root root 619 3月 28 11:58 package.json
-rw-r--r-- 1 root root 159600 3月 28 11:57 package-lock.json
drwxr-xr-x 7 root root 89 3月 28 15:57 public
drwxr-xr-x 2 root root 52 3月 28 15:57 scaffolds
drwxr-xr-x 3 root root 20 3月 28 15:57 source
drwxr-xr-x 3 root root 39 3月 28 15:57 themes
[root@nagios ~/github/glsx-hexo/data]# cat Dockerfile
FROM node:14
# 切换工作空间为
WORKDIR /root/blog
# 拷贝json文件
COPY package*.json ./
# 配置淘宝镜像源
RUN npm config set registry http://registry.npm.taobao.org/
# 安装hexo脚手架
RUN npm install hexo-cli -g
# 安装依赖
RUN npm install
# 拷贝博客所有内容到容器
COPY . .
# 开放4000端口
EXPOSE 4000
# 容器启动的时候执行的命令
ENTRYPOINT ["hexo","clean"]
ENTRYPOINT ["hexo","g"]
ENTRYPOINT ["hexo","s"]
```
**注意**
:新文章请上传到
```/blog/source/_posts```
文件夹下,上传到
```/blog/data/source/_posts```
文件夹无效
## 替换成你的博客
本项目的hexo博客为刚刚初始化的博客,如果你需要替换成自己已有的博客。需要做如下操作
-
将你的hexo博客根目录下的所有文件(不包括
```node_modules```
文件夹),替换
```/data```
下的内容。注意保留Dockerfile文件
-
将你的hexo博客source目录下的所有文件,替换
```/source```
下的内容。
-
将你的hexo博客themes目录下的所有文件,替换
```/themes```
下的内容。
## 修改你的配置
如果你的hexo路径不在
```/home/blog```
下,则需要将
```docker-compose.yml```
文件内的
```/home/blog/source```
和
```/home/blog/themes```
修改成你的路径。
构建hexo博客镜像
```
[root@nagios ~/github/glsx-hexo/data]# docker build -t glsx-hexo:202203281657 .
Sending build context to Docker daemon 1.976MB
Step 1/11 : FROM node:14
---> b55951795ffb
Step 2/11 : WORKDIR /root/blog
---> Using cache
---> e6627659f0c1
Step 3/11 : COPY package*.json ./
---> Using cache
---> 7c20b7bfbabd
Step 4/11 : RUN npm config set registry http://registry.npm.taobao.org/
---> Using cache
---> a26532b94f48
Step 5/11 : RUN npm install hexo-cli -g
---> Using cache
---> 7b3a3d83f544
Step 6/11 : RUN npm install
---> Using cache
---> 50d4a3792cd2
Step 7/11 : COPY . .
---> Using cache
---> e2a486d37387
Step 8/11 : EXPOSE 4000
---> Using cache
---> e972d0dcce2c
Step 9/11 : ENTRYPOINT ["hexo","clean"]
---> Using cache
---> 1e033899b03c
Step 10/11 : ENTRYPOINT ["hexo","g"]
---> Using cache
---> baf706ca0f44
Step 11/11 : ENTRYPOINT ["hexo","s"]
---> Using cache
---> da6f24c981c0
Successfully built da6f24c981c0
Successfully tagged glsx-hexo:202203281657
[root@nagios ~/github/glsx-hexo/data]#
```
## 以下插件已经安装过了
使用docker-compose单机单机编排hexo博客的容器
```
bash
# stun主题
git clone https://github.com/liuyib/hexo-theme-stun.git themes/stun
npm install hexo-render-pug --save
# 生成atom.xml 开启rss功能
npm install hexo-generator-feed --save
# 文章预计的阅读时间、文章字数统计
npm install hexo-wordcount --save
# 生成sitemap
npm install hexo-generator-sitemap --save
# 博客本地搜索功能
npm install hexo-generator-search --save
# Markdown emoji语法支持 与其他插件冲突,建议从http://emojihomepage.com/这个网站复制粘贴emoji
# npm install hexo-filter-github-emojis --save
# live2d动画支持
npm install hexo-helper-live2d --save
# 音视频播放插件
npm install hexo-tag-mmedia --save
# 图片插件
npm install hexo-asset-image --save
```
#安装docker-compose
yum install docker-compose -y
[root@nagios ~/github/glsx-hexo]# pwd
/root/github/glsx-hexo
[root@nagios ~/github/glsx-hexo]# cat docker-compose.yml
version: '3'
services:
hexo-blog:
container_name: hexo-blog
image: glsx-hexo:202203281657
restart: always
privileged: true
ports:
- '80:4000'
#启动hexo容器
[root@nagios ~/github/glsx-hexo/data]# docker-compose up -d
Creating hexo-blog ... done
```
## live2d模型库
[
https://github.com/xiazeyu/live2d-widget-models
](
https://github.com/xiazeyu/live2d-widget-models
)
### 成功运行hexo博客

#
# 配置文档
#
3、gitlab新建项目
-
[
hexo官方文档
](
https://hexo.io/zh-cn/docs/
)
-
[
hexo-theme-stun 配置文档
](
https://liuyib.github.io/hexo-theme-stun/zh-CN/guide/quick-start.html
)
-
[
hexo插件使用与配置
](
https://easyhexo.com/3-Plugins-use-and-config/
)

Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment