code, software architect, articles and novels. 代码,软件架构,博客和小说
Hexo Is Not Support Markdown Template, So I Write One!
Posted onWord count in article: 5.5kReading time ≈5 mins.
I update Hexo last stable version (6.3.0). And I change node/npm version to v18.18.0/9.8.1.
I found the changes in Hexo is quite big. I found images can not be displayed properly.
Then it worked. I think it is hexo incompatibility issue.
Every time I add a centered picture and picture title, I write like the above code. It’s too complicated. If hexo support markdown template,m, I will write like this:
returnfunctionassetImgMidTag(args) { const len = args.length; if (args.length <= 0) { console.warn('image path is not set. args:', args, 'file:', this.full_source); return; }
var path = args[0]; var figure = ''; var text = ''; if (args.length >= 2) { figure = escapeHTML(args[1]); }
if (args.length === 3) { text = escapeHTML(args[2]); } // Find image html tag var image = getImage(this._id, path, text, ctx); return`<div align=center><br/>${image}<br/><strong>${figure}</strong><br/></div>` }; };
In file node_modules/hexo/lib/plugins/tag/index.js, add the following code.
If you install jsdelivr_cdn plugin. And you write your _config.yml in Hexo root like this:
1 2 3
jsdelivr_cdn: use_cdn:true cdn_url_prefix:writeyour_cdn_root_pathlike'https://cdn.jsdelivr.net/gh/<username for github>/<assets repo name>/'
The html will be generated like this:
1 2
<divalign="center"><br><imgsrc="https://cdn.jsdelivr.net/gh/<username for github>/<assets repo name>@master/image/a.png"class=""><br><strong></strong><br></div>
The effect is as follows:
在4旁边生成4
The image tag is generated as CDN path.
This image_mid is support:
post asset path
relative path
http/https path
And post asset path and relative path can be generated as CDN path.