hexo配置小記
流程
- 安裝nodejs、npm
https://nodejs.org/en/download/

在安裝目錄下新建兩個文件夾
在cmd窗口輸入
npm config set prefix "D:\apps\nodejs\node_global"
npm config set cache "D:\apps\nodejs\node_cache"
在環境變量的系統變量加入node_modules
用戶變量的npm的path修改成node_global對應的路徑
這里還需要將新鍵的兩個文件夾的權限放開,否則使用npm安裝會失敗
- git已經安裝了,跳過
- 下載hexo
npm install hexo-cli -g
- 搭建github倉庫
由于ssh之前設置過,只需要簡單搭建一個空遠程倉庫
- 在apps目錄下新建一個hexo文件夾
hexo init
hexo cl;hexo g;hexo s
在本地生成一個靜態網址

點擊4000端口的網址即可訪問
- 配置_config.yml中的部署信息
# URL
## Set your site url here. For example, if you use GitHub Page, set url as 'https://username.github.io/project'
url: https://github.com/2575451471/2575451471.github.io/ #網址,搜索時會在搜索引擎中顯示
root: / #網站根目錄
permalink: :year/:month/:day/:title/ #永久鏈接格式
permalink_defaults: #永久鏈接中各部分的默認值
pretty_urls:
trailing_index: true # Set to false to remove trailing 'index.html' from permalinks
trailing_html: true # Set to false to remove trailing '.html' from permalinks
# Deployment #部署到github
## Docs: https://hexo.io/docs/one-command-deployment
deploy:
type: git
repository: https://github.com/2575451471/2575451471.github.io.git
branch: main
- 配置主題
選擇困難癥,糾結了很久
最后甲方(自己)還是選回了第一版
jelly主題預覽:https://preccrepad.github.io/
jelly主題github倉庫:https://github.com/xinyiwang01/hexo-theme-jelly
my show:

- 同步博客園
1.將博客園的vscode插件的md生成地址改到hexo的文件夾下
然后將md文章都剪切到hexo文件夾的source/_posts下
這樣在一篇文章即可在vscode上同步到兩個平臺
2.hexo使用Front-Matter(添加在md文檔首部)來表示文章信息
---
title: "日記"
date: 2025-02-13 21:17:00
tags: "日記"
hidden: true
top: false # 是否置頂文章(如果主題支持)
layout: post # 文章布局類型,默認為 post,也可以設置為 page 等
---
# 標題
而之前寫的文章是額外設置
嘗試了下添加Front-Matter信息也不會在博客園平臺顯示,
編寫sh腳本進行批量處理,在所有的mdwe文件中添加Front-Matter信息
#!/bin/bash
# 設置目錄路徑
directory="d:/apps/hexo/source/_posts" # 替換為你的 Markdown 文件目錄路徑
# 定義要添加的 Front Matter 片頭
front_matter="""---
title: \"1\"
date: 2025-02-14 21:17:00
tags: \"1\"
hidden: false
top: false # 是否置頂文章(如果主題支持)
layout: "post" # 文章布局類型,默認為 "post",也可以設置為 "page" 等
---
<meta name="referrer" content="no-referrer"/>
<!-- more -->
"""
# 遍歷目錄下的所有 .md 文件
for file in "$directory"/*.md; do
# 讀取文件的第一行
first_line=$(head -n 1 "$file")
# 如果文件已經包含 Front Matter,跳過
if [[ "$first_line" == "---" ]]; then
echo "Skipped: $(basename "$file") (already has Front Matter)"
continue
fi
# 在文件開頭插入 Front Matter
echo -e "$front_matter\n$(cat "$file")" > "$file"
echo "Processed: $(basename "$file")"
done
echo "All files processed."
上面<meta name="referrer" content="no-referrer"/>是為了能使用博客園的圖床
使用hexo g;hexo s本地預覽后發現文章都是全顯示
3.繼續編寫批處理腳本解決問題
#!/bin/bash
# 設置目錄路徑
directory="d:/apps/hexo/source/_posts" # 替換為你的 Markdown 文件目錄路徑
# 定義要插入的行
insert_line="<!-- more -->"
# 定義目標行
target_line='<meta name=referrer content=no-referrer/>'
# 遍歷目錄下的所有 .md 文件
for file in "$directory"/*.md; do
# 檢查文件是否包含目標行
if ! grep -q "$target_line" "$file"; then
echo "Skipped: $(basename "$file") (target line not found)"
continue
fi
# 使用 awk 在目標行下方插入新行
awk -v line="$insert_line" -v target="$target_line" '
{ print }
$0 ~ target { print line }
' "$file" > "$file.tmp" && mv "$file.tmp" "$file"
echo "Processed: $(basename "$file")"
done
echo "All files processed."
- 修改cnblogs新md文檔的模板
博客園新md文檔會有一行# hello world,希望修改成Front-Matter模板
使用vscode打開C:\Users\86177\.vscode\extensions\cnblogs.vscode-cnb-1.8.58-win32-x64這個vscode擴展的文件夾
全局搜索hello
定位到C:\Users\86177\.vscode\extensions\cnblogs.vscode-cnb-1.8.58-win32-x64\dist\extension.js
代碼修改后如下
async function hwe(){
const currentDate = new Date();
const year = currentDate.getFullYear();
const month = String(currentDate.getMonth() + 1).padStart(2, '0');
const day = String(currentDate.getDate()).padStart(2, '0');
const hour = String(currentDate.getHours()).padStart(2, '0');
const minute = String(currentDate.getMinutes()).padStart(2, '0');
const second = String(currentDate.getSeconds()).padStart(2, '0');
let e=ln.getWorkspaceUri().fsPath.replace((0,fwe.homedir)(),"~"),r=await mwe.window.showInputBox({placeHolder:"\u8BF7\u8F93\u5165\u6807\u9898",prompt:`\u6587\u4EF6\u5C06\u4F1A\u4FDD\u5B58\u81F3 ${e}`,title:"\u65B0\u5EFA\u535A\u6587",validateInput:a=>{if(a==="")return"\u6807\u9898\u4E0D\u80FD\u4E3A\u7A7A"}});if(r==null)return;let n=new Kt;n.title=r,
n.postBody=`---
title: "文檔標題"
date: "${year}-${month}-${day} ${hour}:${minute}:${second}"
tags: "標簽"
hidden: false
top: false
layout: post
---
<meta name="referrer" content="no-referrer"/>
<!-- more -->
# 標題
`;
n.isMarkdown=!0,n.isDraft=!0,n.displayOnHomePage=!0,n.postType=1;let i=(await wt.update(n)).id;i>0?(n.id=i,await cn.refresh(),await ps(n,void 0,!0)):ue.err("\u521B\u5EFA\u535A\u6587\u5931\u8D25\uFF0CpostId: "+i)}var F4=require("vscode");async function _we(t){let r=Jt.postCategoriesList.selection.map(s=>s instanceof ds?s.category:s instanceof Aa?s:null).filter(s=>s!=null)??[],n=null;if(t instanceof ds?n=t.category:t instanceof Aa&&(n=t),n===null)return;r.find(s=>s.categoryId===n?.categoryId)===void 0&&r.unshift(n);let i=r;if(i.length<=0)return;let a=i.map(s=>s.title);if(await ue.warn("\u786E\u5B9A\u8981\u5220\u9664\u8FD9\u4E9B\u535A\u6587\u5206\u7C7B\u5417",{detail:`\u5206\u7C7B ${a.join(", ")} \u5C06\u88AB\u5220\u9664`,modal:!0},"\u786E\u5B9A")==="\u786E\u5B9A")return F4.window.withProgress
- 增加hidden屬性
安裝插件
npm install hexo-hide-posts --save
在 _config.yml 中添加以下配置:
hide_posts:
enable: true
filter: hidden
在文章的 Front Matter 中添加 hidden: true,插件會自動隱藏這些文章。
- 一鍵配置
在 D:\apps\hexo 目錄下創建一個名為 myhexo.sh 的腳本文件。
#!/bin/bash
# 切換到 Hexo 博客目錄
cd /d/apps/hexo
# 清除緩存并生成靜態文件,然后部署
hexo clean && hexo generate && hexo deploy
chmod +x /d/apps/hexo/myhexo.sh
再創建.bashrc nano ~/.bashrc
加入alias myhexo='/d/apps/hexo/myhexo.sh'
保存退出,運行source ~/.bashrc
現在,無論在哪個目錄下,都可以直接運行myhexo來更新Hexo
- 一些困難
1.在修改_config.yml配置文件時,試圖修改網易云音樂播放器
原版是利用網易云的iframe嵌入,但是我修改成歌單播放就會受到平臺限制,只能最多顯示10首歌曲(外鏈生成)
嘗試使用hexo-tag-aplayer插件,具體配置方法請看https://github.com/MoePlayer/hexo-tag-aplayer
但是前端代碼不是很懂,邊套邊ai也沒有實際解決問題,遂放棄,
最終是只放了一首最喜歡的歌在博客上
2.在使用博客園的圖床來提供頭像時出現了問題,中途它右能正常識別了,沒過一會兒直接把圖床鏈接整403了,遂放棄,改本地存頭像
3.在嘗試增添github等跳轉鏈接時失敗,發現還需要在main.styl文件中自定義圖標和顏色(倒騰,也不能用圖床圖片,改本地)

浙公網安備 33010602011771號