hexo的文章在source/_post/里,图片应该放在public/img/

  • 配置typora:左上角文件–>首选项–>图像 选择存储到指定位置 /img/${filename}.assets ,配置完以后再拖入图片就会自动存储到系统/img目录下

  • 编写脚本vim /opt/HexoImgCp/hexoImgCp.sh,写入:cp -r /img/* /var/www/html/blogs/github-pages/public/img/

    目的是将

  • 建立脚本的软连接到/usr/local/bin/hexoImgCp

  • 以后在上传文章到github前先执行一遍hexoImgCp来同步本地图片到hexo目录

2024.11.11更新

hexo init Blog

latex的支持:https://www.wzhecnu.cn/2021/08/31/blog/math-tex/

Butterfly 中使用 KaTeX 步骤如下:

  1. 更换插件

    1
    复制成功
1
2
3
4
npm un hexo-renderer-marked --save # 卸载 marked 插件
npm un hexo-renderer-kramed --save # 卸载 kramed 插件
npm i hexo-renderer-markdown-it --save # 安装渲染插件
npm install @neilsustc/markdown-it-katex --save # 安装katex插件

修改主题配置文件 _config.butterfly.yml

1
2
3
4
5
6

# KaTeX
katex:
enable: true
per_page: false
hide_scrollbar: true

在博客配置文件 _config.yml 中追加代码:

1
2
3
4
5
6
7

markdown:
plugins:
- plugin:
name: '@neilsustc/markdown-it-katex'
options:
strict: false
1
npm install hexo-renderer-pug hexo-renderer-stylus --save
1
npm i hexo-blog-encrypt hexo-wordcount --save

新的npm包

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
hexo-site@0.0.0 F:\Blog                              
├── @neilsustc/markdown-it-katex@1.0.0
├── @upupming/hexo-renderer-markdown-it-plus@2.0.2
├── hexo-asset-image@1.0.0
├── hexo-blog-encrypt@3.1.9
├── hexo-butterfly-extjs@1.4.15
├── hexo-deployer-git@4.0.0
├── hexo-generator-archive@2.0.0
├── hexo-generator-category@2.0.0
├── hexo-generator-index@4.0.0
├── hexo-generator-json-content@4.2.3
├── hexo-generator-search@2.4.3
├── hexo-generator-tag@2.0.0
├── hexo-renderer-ejs@2.0.0
├── hexo-renderer-markdown-it@7.1.1
├── hexo-renderer-pug@3.0.0
├── hexo-renderer-stylus@3.0.1
├── hexo-server@3.0.0
├── hexo-theme-landscape@1.0.0
├── hexo-wordcount@6.0.1
└── hexo@7.3.0

旧的npm包

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
λ npm list
(node:13356) ExperimentalWarning: CommonJS module C:\Users\hasee\AppData\Roaming\npm\node_modules\npm\node_modules\debug\src\node.js is loading ES Module C:\Users\hasee\AppData\Roaming\npm\node_modules\npm\node_modules\supports-color\index.js using require().
Support for loading ES Module in require() is an experimental feature and might change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
hexo-site@0.0.0 F:\Blog
├── @neilsustc/markdown-it-katex@1.0.0
├── @upupming/hexo-renderer-markdown-it-plus@2.0.2
├── @waline/client@2.4.0
├── algoliasearch@4.13.0
├── core-js@3.22.5
├── formidable@3.2.3
├── hexo-algolia@1.3.2
├── hexo-asset-image@0.0.5 (git+ssh://git@github.com/CodeFalling/hexo-asset-image.git#3c114cf0c0343ab28469635085b225fcae7fb9d3)
├── hexo-blog-encrypt@3.1.6
├── hexo-butterfly-extjs@1.1.7
├── hexo-deployer-git@3.0.0
├── hexo-generator-archive@0.1.5
├── hexo-generator-category@0.1.3
├── hexo-generator-index-pin-top@0.2.2
├── hexo-generator-index@2.0.0
├── hexo-generator-json-content@4.2.3
├── hexo-generator-search@2.4.3
├── hexo-generator-tag@0.2.0
├── hexo-renderer-ejs@0.3.1
├── hexo-renderer-jade@0.4.1
├── hexo-renderer-markdown-it@6.0.1
├── hexo-renderer-pug@3.0.0
├── hexo-renderer-stylus@0.3.3
├── hexo-server@0.3.3
├── hexo-wordcount@6.0.1
├── hexo@6.2.0
├── mkdirp@1.0.4
└── save@2.5.0

2024.11.06更新:

Hexo更新后,根据官方文档https://hexo.io/zh-cn/docs/asset-folders,想要插入图片要不就使用asset标签插件,要不就使用`markdown-marked`插件。但是这两种插入方式对markdown的本地编写都不友好,本地编写插入的图片路径和它生成的路径是不一样的(ps:越改越蠢的设计)。

要想使用markdown原生的图片插入方法,参考下面两篇博客找到解决方法,首先卸载markdown-marked插件。安装hexo-asset-image插件,然后修改此插件的index.js文件如下:

https://alvincr.com/2021/01/hexo-with-github_pages/

https://wangwei1237.github.io/2020/02/05/handle-the-bug-of-hexo-asset-image-plugin/

1

node_modules/hexo-asset-image/index.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
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
'use strict';
var cheerio = require('cheerio');

// http://stackoverflow.com/questions/14480345/how-to-get-the-nth-occurrence-in-a-string
function getPosition(str, m, i) {
return str.split(m, i).join(m).length;
}

var version = String(hexo.version).split('.');
hexo.extend.filter.register('after_post_render', function(data){
var config = hexo.config;
if(config.post_asset_folder){
var link = data.permalink;
if(version.length > 0 && Number(version[0]) == 3)
var beginPos = getPosition(link, '/', 1) + 1;
else
var beginPos = getPosition(link, '/', 3) + 1;
// In hexo 3.1.1, the permalink of "about" page is like ".../about/index.html".
var endPos = link.lastIndexOf('/') + 1;
link = link.substring(beginPos, endPos);

var toprocess = ['excerpt', 'more', 'content'];
for(var i = 0; i < toprocess.length; i++){
var key = toprocess[i];

var $ = cheerio.load(data[key], {
ignoreWhitespace: false,
xmlMode: false,
lowerCaseTags: false,
decodeEntities: false
});

$('img').each(function(){
if ($(this).attr('src')){
// For windows style path, we replace '\' to '/'.
var src = $(this).attr('src').replace('\\', '/');
if(!/http[s]*.*|\/\/.*/.test(src) &&
!/^\s*\//.test(src)) {
// For "about" page, the first part of "src" can't be removed.
// In addition, to support multi-level local directory.
var linkArray = link.split('/').filter(function(elem){
return elem != '';
});
var srcArray = src.split('/').filter(function(elem){
return elem != '' && elem != '.';
});
if(srcArray.length > 1)
srcArray.shift();
src = srcArray.join('/');
$(this).attr('src', config.root + link + src);
console.info&&console.info("update link as:-->"+config.root + link + src);
}
}else{
console.info&&console.info("no src attr, skipped...");
console.info&&console.info($(this));
}
});
data[key] = $.html();
}
}
});

image-20241106211342482

2019.11.23更新:

上述方法不利于资源的管理,也不利于平台之间的同步,所以更换了方法

typora的更改

图像存储位置

image-20191123071145624