#官方文档

https://hexo.io/zh-cn/docs/one-command-deployment

#安装教程,还可以上b站看别人的视频教学

https://blog.csdn.net/wushibo123/article/details/124619123

hexo c == hexo clean # 清除缓存

hexo g == hexo generate # 生成静态文件

hexo d == hexo deploy # 部署到github中,更新网页端的内容

hexo s == hexo server # 通过启动本地服务器,预览文章效果

hexo n == hexo new

更新

图片放该目录

文章放该目录

1
hexo clean && hexo g && hexo d

将语雀的文章快速部署到自己的博客上,先下载md,使用以下脚本

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
import os
import re
import requests
import argparse
from datetime import datetime


def download_image(url, save_path):
try:
response = requests.get(url, timeout=10)
response.raise_for_status()
with open(save_path, 'wb') as f:
f.write(response.content)
print(f"下载成功:{url} -> {save_path}")
except Exception as e:
print(f"下载失败:{url},错误:{e}")


def ensure_front_matter(content, base_name):
"""
如果原始内容没有 YAML front matter,则添加默认的 front matter。
默认 front matter 包括 title 和当前日期,您可以根据需要修改。
"""
stripped = content.lstrip()
if stripped.startswith('---'):
# 已有 front matter,不做修改
return content
else:
now = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
front_matter = f"---\ntitle: {base_name}\ndate: {now}\n---\n\n"
return front_matter + content


def process_md_file(md_file, hexo_img_folder):
# 提取 Markdown 文件名(不含扩展名),用于图片文件夹名称和 front matter 标题
base_name = os.path.splitext(os.path.basename(md_file))[0]
# 图片存放在 hexo_img_folder 下,如:source/img/<base_name>
img_folder = os.path.join(hexo_img_folder, base_name)
os.makedirs(img_folder, exist_ok=True)

with open(md_file, 'r', encoding='utf-8') as f:
content = f.read()

# 保证内容含有 Hexo 所需的 YAML front matter
content = ensure_front_matter(content, base_name)

# 匹配 Markdown 中的图片语法:![描述](图片链接)
pattern = r'!\[(.*?)\]\((.*?)\)'
matches = re.findall(pattern, content)
print(f"在文件 {md_file} 中找到 {len(matches)} 张图片。")

counter = 1
for alt_text, url in matches:
# 只处理 HTTP 链接的图片
if not url.startswith('http'):
print(f"非HTTP链接,跳过下载:{url}")
continue

# 提取图片扩展名,如果无法提取则默认 .jpg
original_name = os.path.basename(url).split('?')[0]
_, ext = os.path.splitext(original_name)
if not ext:
ext = '.jpg'

# 按顺序命名图片:1.jpg, 2.png, 等
new_file_name = f"{counter}{ext}"
local_path = os.path.join(img_folder, new_file_name)

download_image(url, local_path)

# 修改图片链接为 Hexo 部署后静态资源的绝对路径
new_link = f"/img/{base_name}/{new_file_name}"
new_image_md = f"![{alt_text}]({new_link})"
# 替换 Markdown 文件中的图片链接
content = content.replace(f"![{alt_text}]({url})", new_image_md)

counter += 1

# 生成新的 Markdown 文件,文件名加上 _local 后缀,存放于原文件所在目录
new_md_file = os.path.splitext(md_file)[0] + '_local.md'
with open(new_md_file, 'w', encoding='utf-8') as f:
f.write(content)
print(f"生成本地化 Markdown 文件:{new_md_file}")


def main():
parser = argparse.ArgumentParser(
description="处理 Markdown 文件,下载其中的图片到 Hexo 博客指定目录,并更新图片链接。"
)
parser.add_argument(
"-i", "--input",
help="输入的 Markdown 文件或包含 Markdown 文件的目录(默认:当前目录)",
default="."
)
parser.add_argument(
"-o", "--output",
help="Hexo 博客中存放图片的目录(默认:source/img)",
default=os.path.join("source", "img")
)
args = parser.parse_args()

input_path = args.input
# 如果输入的是单个文件,则只处理这个文件;否则处理目录下所有 .md 文件
if os.path.isfile(input_path):
md_files = [input_path]
else:
md_files = [os.path.join(input_path, f) for f in os.listdir(input_path) if f.endswith('.md')]

if not md_files:
print("没有找到 Markdown 文件。")
return

for md_file in md_files:
print(f"正在处理文件:{md_file}")
process_md_file(md_file, args.output)


if __name__ == "__main__":
main()

go的去除_local的脚本

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package main

import (
"fmt"
"os"
"path/filepath"
"strings"
)

func main() {
// 获取当前目录
dir, err := os.Getwd()
if err != nil {
fmt.Printf("获取当前目录失败: %v\n", err)
return
}

// 遍历目录中的文件
err = filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}

// 跳过目录
if info.IsDir() {
return nil
}

// 获取文件名和扩展名
filename := info.Name()
ext := filepath.Ext(filename)
base := strings.TrimSuffix(filename, ext)

// 检查是否包含_local后缀
if strings.HasSuffix(base, "_local") {
// 构建新文件名
newBase := strings.TrimSuffix(base, "_local")
newFilename := newBase + ext
newPath := filepath.Join(filepath.Dir(path), newFilename)

// 重命名文件
err := os.Rename(path, newPath)
if err != nil {
fmt.Printf("重命名失败: %s -> %s (错误: %v)\n", path, newPath, err)
return nil
}

fmt.Printf("重命名成功: %s -> %s\n", path, newPath)
}

return nil
})

if err != nil {
fmt.Printf("遍历目录失败: %v\n", err)
}
}

rename.exe是去除_local的

美化和主题配置

https://blog.csdn.net/mjh1667002013/article/details/129290903

https://butterfly.js.org/

显示超时就多试几次吧