hexo搭建blog及安装第三方主题Next等配置操作(二)

hexo搭建blog及安装第三方主题Next等配置操作(二)

  • 一键盘生成hexo及安装第三方主题next脚本如下:
    # ----------------------------------------------------------------
    # Copyright © 2024 OpenSource Ltd. All rights reserved.
    # FileName : hexo_blog_init.sh
    # Author : looismes
    # Mail : looismes@gmail.com
    # Version : v1.0.0
    # CreateTime : 2024-05-24 11:53:17
    # COPYRIGHT : Copyright ©2024 - 开源服务
    # Description: Welcome Use The Script.
    # ----------------------------------------------------------------
#!/bin/bash

hexo_dir="/acdata/dba_tools/hexo_blog"
cd ${hexo_dir}/blog

func_init_hexo(){
#switch node version
nvm use node

#Install Hexo
npm install hexo-cli -g

#Setup your blog
hexo init blog
cd blog

#Start the server
hexo server -p 8080

#Create a new post
hexo new "Hello Hexo"

#Generate static files
hexo generate
}

<!-- more -->

func_install_theme(){
hexo_dir="/acdata/dba_tools/hexo_blog"
cd ${hexo_dir}/blog
pwd

#1.添加hexo-theme-next第三方主题
npm install --save hexo-theme-next
sleep 5
pwd
cat ./node_modules/hexo-theme-next/_config.yml > ./_config.next.yml

theme_num=$(grep -n "^theme" ./_config.yml|cut -d ":" -f1)
echo "########$theme_num"

sed -i 's/^theme/#theme/g' ./_config.yml
#在theme所在行的下一行添加新的主题:
sed -i "${theme_num}a \theme: next" ./_config.yml

#2. add hexo-filter-nofollow 插件
npm install hexo-filter-nofollow --save
cat >> ./_config.yml << sqleof
# 外部链接优化
nofollow:
enable: true
field: site
exclude:
- 'exclude1.com'
- 'exclude2.com'
sqleof
echo "#######2.add hexo-filter-nofollow插件"

#3.站点地图 sitemap 生成
npm install hexo-generator-sitemap --save
cat >> ./_config.yml << sqleof
# 通用站点地图
sitemap:
path: sitemap.xml
sqleof
echo "#######3.站点地图sitemap生成"

#4.修改网站的图标 Favicon
cat >> ./_config.yml << sqleof
favicon:
small: /images/favicon-16x16-next.png
medium: /images/favicon-32x32-next.png
apple_touch_icon: /images/favicon-32x32-next.png
safari_pinned_tab: /images/favicon-32x32-next.png
#android_manifest: /images/manifest.json
#ms_browserconfig: /images/browserconfig.xml
sqleof
echo "#######4.修改网站的图标 Favicon"

#5.主题配置:
#5.1 指定next-Gemini模板
sed -i "s/scheme: Muse/#scheme: Muse/g" ./_config.next.yml
sed -i "s/#scheme: Gemini/scheme: Gemini/g" ./_config.next.yml

#Muse - 默认 Scheme,这是 NexT 最初的版本,黑白主调,大量留白
#Mist - Muse 的紧凑版本,整洁有序的单栏外观
#Pisces - 双栏 Scheme,小家碧玉似的清新
#Gemini - 左侧网站信息及目录,块 + 片段结构布局

#5.2 配置hexo中的about,tag,categories,sitemap菜单
cat >> ./_config.yml << sqleof
# 菜单设置为 菜单名: /菜单目录 || 菜单图标名字
menu:
home: / || home
about: /about/ || user
tags: /tags/ || tags
categories: /categories/ || th
archives: /archives/ || archive
#schedule: /schedule/ || calendar
sitemap: /sitemap.xml || sitemap
commonweal: /404/ || heartbeat

menu_settings:
icons: true # 显示图标
badges: true # 显示统计信息
sqleof




# 生成表态htm
hexo generate
}

func_init_hexo
func_install_theme