如何配置Hexo
Qianming Huang Three

配置图床

参考链接:Github+PicGo搭建个人免费图床 - misakivv - 博客园 (cnblogs.com)

对于博客页的照片上传

参考解决链接:[2024] hexo图片无法加载究极解决方案_hexo图片显示不出来-CSDN博客

对于markdown渲染器的优化

参考链接(优选):【Hexo】更高级的Markdown渲染器 | Everett Rain

参考链接:【Hexo】选择更高级的Markdown渲染器_hexo-renderer-marked-CSDN博客

对于渲染器优化后,mathjax用不了的解决方案

  • 在修改了渲染器后,会发现mathjax用不了,此时就需要针对新的渲染器安装一个插件

    如图所示:

    image

  • 解决方案:

    • 下载一个插件:
    1
    $ npm install markdown-it-mathjax3
    • 在hexo的_config.yml文件中,加上这个插件的名字

      image

    • 随后就可以啦!

      a=b+c=d+e=f+g

对于git部署的网络问题

参考资料:解决git报错:fatal: unable to access ‘https://github.com/…‘: Failed to connect to github.com port 443 a_git failed with a fatal error unable to access-CSDN博客

直接在git中输入:

1
2
git config --global --unset http.proxy
git config --global --unset https.proxy

然后挂vpn就好了。(稳定的vpn,或者也可以不挂直接传,没准也能成)

在输入完终端命令后可以检查一下是否真的删除了:

1
git config --global --list

如果输出中没有http.proxyhttps.proxy,则证明成功。

测试区

二级标题测试

三级标题测试

四级标题测试

五级标题测试
六级标题测试

test

test

test

test
test
  • 对于代码的测试

1
2
3
4
## 此处作为代码测试
import numpy as np

a = np.array([1,2,3])
  • 对于公式的测试

    a+b=c
itψ=22m2ψ+Vψ

​ 对于句子内部的公式:例如x+1=2

  • 对于图片的测试

    • 本地图片:

      image

image
  • ​ 网络图片

image

  • 上传图床的照片

image image

折叠,展开内容

  • 语法:

1
2
3
+++ **点击折叠**
这是被隐藏的内容
+++
  • 效果:

     点击折叠

    这是被隐藏的内容

自定义容器

  • 效果

    提示
    这是一个提示

    注意
    这是一个警告

    danger
    这是一个危险信号

    引用测试

    成功
    这是一个成功信号

  • d

    提示
    这是一个提示

提示
这是一个提示

  • 语法:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    ::: tips
    **提示**
    这是一个提示
    :::

    ::: warning
    **warning**
    这是一个警告
    :::

    ::: danger
    **警告**
    这是一个危险信号
    :::

    ::: success
    **成功**
    这是一个成功信号
    :::
  • 文本高亮测试:

    • 这是一句测试的文本。

He’s a good person

  • typora容器测试

    💡 Tip

    测试

    • 测试

      📘 Important

      测试

      • 在测试

        ⚠️ Warning

        测试行1

        测试行2

        d

        dddd

  • d

    ℹ️ Note

    缩进测试

💡 Tip

测试2

引用

ℹ️ Note

Test-Note

啦啦啦啦来啦

📘 Important

Important-test

llalalalallala

⚠️ Warning

Warning-test

❗ Caution

Caution-test

最初,想使用markdown-it的插件比如markdown-it-alert。但是貌似渲染器在版本上有冲突,并不支持。因此,便使用一种投机取巧的办法,基于markdown-it-container来实现。方式如下:

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
输入
> [!TIP]
>
> 测试2

> [!NOTE]
>
> Test-Note

> [!IMPORTANT]
>
> Important-test

> [!WARNING]
>
> Warning-test

> [!CAUTION]
>
> Caution-test

输出:
::: tip
**💡 Tip**
测试2
:::

::: note
**ℹ️ Note**
Test-Note
:::

::: important
**📘 Important**
Important-test
:::

::: warning
**⚠️ Warning**
Warning-test
:::

::: caution
**❗ Caution**
Caution-test
:::

为了实现自动化的脚本转化,且不影响原始的typora代码,需要在 Hexo根目录/scripts (如果没有这个文件夹就新建一个) 中新建一个叫admonition-convert.js的文件。将下面的代码拷贝进去

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
hexo.extend.filter.register('before_post_render', function(data) {
// 定义类型映射表,包含对应的图标和标题
const typeMap = {
TIP: { icon: '💡', title: 'Tip' },
NOTE: { icon: 'ℹ️', title: 'Note' },
IMPORTANT: { icon: '📘', title: 'Important' },
WARNING: { icon: '⚠️', title: 'Warning' },
CAUTION: { icon: '❗', title: 'Caution' }
};

// 匹配所有支持的Admonition类型,处理空行和多个连续块
const admonitionRegex = /(^> \[!([A-Z]+)\])(\r?\n)(> ?\r?\n)*((> .*?\r?\n)*?)(?=\r?\n> \[!|$)/gm;

data.content = data.content.replace(admonitionRegex, (match, header, type, firstLineBreak, emptyLines, content) => {
// 检查类型是否在映射表中
if (!typeMap[type]) {
return match; // 不匹配的类型保持原样
}

// 清理内容中的>前缀和多余空行
const cleanedContent = content
.replace(/^> ?/gm, '') // 移除每行开头的>和可能的空格
.replace(/^\s+|\s+$/g, ''); // 移除首尾空行

// 获取对应的图标和标题
const { icon, title } = typeMap[type];

// 转换为带图标和标题的Typora风格提示块
return `::: ${type.toLowerCase()}
**${icon} ${title}**
${cleanedContent}
:::`;
});

return data;
});

随后,渲染器就可以支持typora的alert啦

测试流程图

graph TD
    A[起点] --> B[步骤1]
    B --> C[步骤2]
    C --> D[步骤3]
    D --> E[终点]

测试表格

1 2 3
4 + 6
7 8 9
10 11 12
  • 缩进表格

时代 2 Time
时代 + Time
7 8 9
10 11 12
  • 进一步缩进的表格

    • 进一步缩进
1 2 3
4 + 6
7 8 9
10 11 12
  • 再进一步

    • 再进
1 2 3
4 + 6
7 8 9
10 11 12

测试有序无序列表

  • 1

    • 1
  • 一个人

    • 一个人
  • one person

    • one person
  1. 33324325123

  2. 234843929823409

  3. 一群人

    1. 一群人
  4. a group of people

    1. a group of people
      1. a antehr