hexo-记录博客用到的自定义js

感谢 https://github.com/lzuliuyun/hexo-image-cdn

感谢 https://github.com/2-3-5-7/hexo-relative-link

此代码参考了 hexo-image-link、hexo-asset-link

1
2
3
4
 如果使用了hexo g

if ((process.argv.indexOf('generate') > -1 || process.argv.indexOf('g') > -1) ){
}

page_path

1
2
3
4
5
6
7
8
9
// hello_my_posts.md文件中的引用为:[other_post](/hexo-%E8%AE%B0%E5%BD%95%E5%8D%9A%E5%AE%A2%E7%94%A8%E5%88%B0%E7%9A%84%E8%87%AA%E5%AE%9A%E4%B9%89js/../../life/internet)
// source/_posts/科技/hello_my_posts/ 加 ../ 变为source/_posts/科技/
// 最终变为source/_posts/life/internet.md
// 对于多文件夹下的文章相互访问有用

// hello_my_posts.md中有引用图片:![picture_asset](https://webdav-1309345210.file.myqcloud.com/images/hexo-%E8%AE%B0%E5%BD%95%E5%8D%9A%E5%AE%A2%E7%94%A8%E5%88%B0%E7%9A%84%E8%87%AA%E5%AE%9A%E4%B9%89js/../hello_my_posts/pic.png)
// source/_posts/科技/hello_my_posts/ 加 ../ 变为source/_posts/科技/
// 最终变为source/_posts/科技/hello_my_posts/pic.png

1
2
// \S+匹配1或多个非空白字符
// \s*匹配0或多个空白字符
1
2
3
4
// page_path获取当前 md 文件同名路径
// 例如: hello_my_posts.md 在 source/_posts/科技/hello_my_posts.md
// 则:page_path --> source/_posts/科技/hello_my_posts/ 是文件夹