184 lines
6.5 KiB
Bash
184 lines
6.5 KiB
Bash
#!/bin/bash
|
|
|
|
#############################################################################################
|
|
# 用途: Hexo-Async-Deployer 项目初始化脚本
|
|
# 作者: 丁辉
|
|
# 编写日期: 2021-10-1
|
|
# 更新日期: 2025-12-13
|
|
#############################################################################################
|
|
|
|
# 加载检测脚本
|
|
source <(curl -sS https://gitee.com/offends/Linux/raw/main/File/Shell/Check_command.sh)
|
|
|
|
# 修改默认 _config.yml 文件
|
|
function MODIFY_DEFAULT_FILE(){
|
|
SEND_INFO "正在修改 Hexo 基础配置"
|
|
# 修改语言
|
|
sed -i "s#language: en#language: zh-Hans#g" /hexo/_config.yml
|
|
# 修改作者
|
|
sed -i "s#author: John Doe#author: Offends#g" /hexo/_config.yml
|
|
# 修改网址
|
|
sed -i "s#url: http://example.com#url: https://blog.offends.cn#g" /hexo/_config.yml
|
|
}
|
|
|
|
# 初始化图片
|
|
function INIT_IMAGE() {
|
|
SEND_INFO "正在拉取站点图片资源"
|
|
CHECK_DIR /hexo/source/img/
|
|
# 存储地址
|
|
MINIO_URL="https://minio.offends.cn:9000/offends/hexo-async"
|
|
IMAGE_NAME=(
|
|
"avatar.png"
|
|
"favicon-default.png"
|
|
"favicon-circle.png"
|
|
"index-background.png"
|
|
"cover-background.png"
|
|
"wx.png"
|
|
"zfb.png"
|
|
"404.gif"
|
|
"404.jpg"
|
|
"md.png"
|
|
)
|
|
# 循环下载页面
|
|
for NAME in ${IMAGE_NAME[@]}; do
|
|
CHECK_COMMAND_NULL curl -so /hexo/source/img/$NAME $MINIO_URL/$NAME
|
|
done
|
|
# 预防控制台报错
|
|
cp /hexo/source/img/favicon-default.png /hexo/source/img/favicon-16x16.png
|
|
}
|
|
|
|
# 初始化页面
|
|
function INIT_PAGE() {
|
|
SEND_INFO "正在创建栏目页面"
|
|
# 分类
|
|
CHECK_COMMAND_NULL npm install hexo-generator-category
|
|
# 页面名称
|
|
PAGE_NAME=(
|
|
"categories"
|
|
"about"
|
|
"comment"
|
|
"links"
|
|
)
|
|
# 循环创建页面
|
|
for NAME in ${PAGE_NAME[@]}; do
|
|
# 创建页面
|
|
CHECK_COMMAND_NULL hexo new page $NAME
|
|
if [ $? -eq 0 ]; then
|
|
# 创建页面成功
|
|
SEND_INFO "创建页面 $NAME 成功"
|
|
else
|
|
# 创建页面失败
|
|
SEND_WARN "创建页面 $NAME 失败"
|
|
fi
|
|
done
|
|
# 初始化名称
|
|
sed -i 's#title: links#title: 友情链接#g' /hexo/source/links/index.md
|
|
sed -i 's#title: about#title: 关于#g' /hexo/source/about/index.md
|
|
sed -i 's#title: comment#title: 留言#g' /hexo/source/comment/index.md
|
|
sed -i 's#title: categories#title: 分类#g' /hexo/source/categories/index.md
|
|
# 初始功能特性
|
|
sed -i '3a\layout: links' /hexo/source/links/index.md
|
|
sed -i '3a\layout: about' /hexo/source/about/index.md
|
|
sed -i '3a\layout: comment' /hexo/source/comment/index.md
|
|
sed -i '3a\layout: category' /hexo/source/categories/index.md
|
|
# 初始化单栏显示详情页
|
|
sed -i '4a\single_column: false' /hexo/source/about/index.md
|
|
sed -i '4a\single_column: true' /hexo/source/categories/index.md
|
|
# 初始化关闭特定页面评论功能
|
|
sed -i '5a\comments: false' /hexo/source/about/index.md
|
|
sed -i '5a\comments: false' /hexo/source/categories/index.md
|
|
}
|
|
|
|
# 初始化 Async 文件
|
|
function INIT_BASE_INFO() {
|
|
SEND_INFO "正在初始化友情链接"
|
|
CHECK_DIR /hexo/source/_data/
|
|
CHECK_COMMAND_NULL mv /app/links.yml /hexo/source/_data/links.yml
|
|
SEND_INFO "正在初始本地搜索引擎"
|
|
CHECK_COMMAND_NULL npm install hexo-generator-searchdb
|
|
SEND_INFO "正在初始本地数字统计引擎"
|
|
CHECK_COMMAND_NULL npm install hexo-wordcount
|
|
SEND_INFO "正在初始化关键配置"
|
|
CHECK_COMMAND_NULL mv /app/_config.async.yml /hexo/_config.async.yml
|
|
CHECK_COMMAND_NULL mv /app/404.md /hexo/source/404.md
|
|
CHECK_COMMAND_NULL mv /app/site.webmanifest /hexo/source/site.webmanifest
|
|
CHECK_DIR /hexo/source/_data/style/
|
|
CHECK_COMMAND_NULL mv /app/index.less /hexo/source/_data/style/index.less
|
|
}
|
|
|
|
# 初始化收录配置
|
|
function INIT_BAIDU_SITEMAP() {
|
|
SEND_INFO "正在初始化收录配置"
|
|
################################## 百度Sitemap 和 Google Sitemap ##################################
|
|
CHECK_COMMAND_NULL npm install hexo-generator-sitemap
|
|
CHECK_COMMAND_NULL npm install hexo-generator-baidu-sitemap
|
|
|
|
sed -i '/^url:/ {N; s/\n/\nroot: \/\n/;}' /hexo/_config.yml
|
|
sed -i 's/permalink: :year\/:month\/:day\/:title\//permalink: :title.html/' /hexo/_config.yml
|
|
cat << EOF >> /hexo/_config.yml
|
|
sitemap:
|
|
path: sitemap.xml
|
|
baidusitemap:
|
|
path: baidusitemap.xml
|
|
EOF
|
|
sed -i '1i<meta name="google-site-verification" content="V1iIzgHls93z_BAPofTvRD8jwh01u4Ls0fqXgGo86Ro" />' /hexo/node_modules/hexo-theme-async/layout/_partial/head.ejs
|
|
sed -i '1i<meta name="baidu-site-verification" content="codeva-MZXYU3JS1x" />' /hexo/node_modules/hexo-theme-async/layout/_partial/head.ejs
|
|
################################## 百度主动推送 ##################################
|
|
CHECK_COMMAND_NULL npm install hexo-baidu-url-submit
|
|
sed -i '/deploy:/!b;n;s/ type: \x27\x27/- type: baidu_url_submitter/' /hexo/_config.yml
|
|
cat << EOF >> /hexo/_config.yml
|
|
baidu_url_submit:
|
|
count: 200
|
|
host: blog.offends.cn
|
|
token: CRBfMzmp8EjAnQCl
|
|
path: baidu_urls.txt
|
|
EOF
|
|
}
|
|
|
|
# 添加看板娘
|
|
function ADD_TOUCH_ICON() {
|
|
SEND_INFO "添加看板娘"
|
|
git clone https://githubfast.com/stevenjoezhang/live2d-widget.git /hexo/node_modules/hexo-theme-async/source/live2d-widget
|
|
# 清理无用文件
|
|
IMAGE_NAME=(
|
|
".git"
|
|
".gitignore"
|
|
".github"
|
|
"README.en.md"
|
|
"README.md"
|
|
"LICENSE"
|
|
)
|
|
# 循环下载页面
|
|
for NAME in ${IMAGE_NAME[@]}; do
|
|
rm -rf /hexo/node_modules/hexo-theme-async/source/live2d-widget/$NAME
|
|
done
|
|
# 配置看板娘
|
|
sed -i '1i<script src="/live2d-widget/dist/autoload.js"></script>' /hexo/node_modules/hexo-theme-async/layout/_partial/head.ejs
|
|
# 配置本地话
|
|
mv /app/autoload.js /hexo/node_modules/hexo-theme-async/source/live2d-widget/dist/autoload.js
|
|
# 修改看板娘层级
|
|
sed -i 's/z-index: 1;/z-index: 9999;/g' /hexo/node_modules/hexo-theme-async/source/live2d-widget/dist/waifu.css
|
|
}
|
|
|
|
# 音乐位置 : 符号去除
|
|
# function INIT_MUSIC() {
|
|
# sed -i 's/<%- __(item.key) %>:/<%- __(item.key) %>/g' /hexo/node_modules/hexo-theme-async/layout/_partial/sidebar/card/info.ejs
|
|
# }
|
|
|
|
# 执行全部初始化
|
|
function INIT_ALL() {
|
|
# 修改默认 _config.yml 文件
|
|
MODIFY_DEFAULT_FILE
|
|
# 初始化图片
|
|
INIT_IMAGE
|
|
# 初始化页面
|
|
INIT_PAGE
|
|
# 初始化 Async 文件
|
|
INIT_BASE_INFO
|
|
# 初始化收录配置
|
|
INIT_BAIDU_SITEMAP
|
|
# 添加看板娘
|
|
ADD_TOUCH_ICON
|
|
}
|
|
|
|
INIT_ALL |