Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some glitches: wikilink in code block, post not found, plugin load failed #11

Closed
afterglowu opened this issue Aug 30, 2022 · 2 comments
Closed

Comments

@afterglowu
Copy link
Contributor

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.

image

2. Post not found

The path seperator of Windows is '\', but tag plugin {% post_link %} requires '/', so I get a "Post not found" error:

image

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");
@Cyrusky
Copy link
Owner

Cyrusky commented Sep 1, 2022

Thx for your issue. Can you start a PR? I will merge it in to main.

@afterglowu
Copy link
Contributor Author

I have started PR #12 , please check it.

P.S. I don't know how to fix the first problem (wikilink inside inline code and code block), thus this PR only contain the code of the second and the third.

@Cyrusky Cyrusky closed this as completed Sep 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants