It's a useful plugin and helps me a lot. I might never think of using Hexo's tag plugin {% post_link %}
to implement such function.
I found 3 glitches while using this plugin, shown as below.
1. Wikilink in inline code and code blocks
The [[knapsack]]
inside inline code and fenced code block are also converted to {% post_link %}
by this plugin.
2. Post not found
The path seperator of Windows is '\'
, but tag plugin {% post_link %}
requires '/'
, so I get a "Post not found" error:
Add the following code can fix this, but I'm not sure whether it's the "standard" way or not. (I never use js before, I'm new to it.)
if (path.sep === "\\") {
each = each.replace(new RegExp("\\" + path.sep, "g"), "/");
}
3. Plugin load failed
Currently this plugin only works properly when I launch hexo s
(or hexo g
) in my hexo project's root directory.
If I launch hexo s
in a sub directory (e.g. the source
folder), then errors will occur:
PS D:\Sync\workspace\mlog\source> hexo s
INFO Validating config
ERROR Plugin load failed: hexo-backlink
Error: ENOENT: no such file or directory, scandir 'D:\Sync\workspace\mlog\source\source\_posts'
at _readAndFilterDirSync (D:\Sync\workspace\mlog\node_modules\hexo-fs\lib\fs.js:120:13)
at _listDirSyncWalker (D:\Sync\workspace\mlog\node_modules\hexo-fs\lib\fs.js:173:22)
at Object.listDirSync (D:\Sync\workspace\mlog\node_modules\hexo-fs\lib\fs.js:189:3)
at D:\Sync\workspace\mlog\node_modules\hexo-backlink\index.js:7:4
at D:\Sync\workspace\mlog\node_modules\hexo\lib\hexo\index.js:317:14
at Promise._settlePromiseFromHandler (D:\Sync\workspace\mlog\node_modules\bluebird\js\release\promise.js:547:31)
at Promise._settlePromise (D:\Sync\workspace\mlog\node_modules\bluebird\js\release\promise.js:604:18)
at Promise._settlePromises (D:\Sync\workspace\mlog\node_modules\bluebird\js\release\promise.js:729:18)
at _drainQueueStep (D:\Sync\workspace\mlog\node_modules\bluebird\js\release\async.js:93:12)
at _drainQueue (D:\Sync\workspace\mlog\node_modules\bluebird\js\release\async.js:86:9)
at Async._drainQueues (D:\Sync\workspace\mlog\node_modules\bluebird\js\release\async.js:102:5)
at Immediate.Async.drainQueues [as _onImmediate] (D:\Sync\workspace\mlog\node_modules\bluebird\js\release\async.js:15:14)
at processImmediate (internal/timers.js:461:21)
To fix it, change the way of construct base_dir
in the plugin's code:
// index.js
// const base_dir = path.join(process.cwd(), "source", "_posts");
const base_dir = path.join(hexo.source_dir, "_posts");