hexo
hexo copied to clipboard
fix(tag): use url_for
What does it do?
Issue resolved: https://github.com/hexojs/hexo/issues/5383
Screenshots
Pull request tasks
- [x] Add test cases for the changes.
- [x] Passed the CI test.
How to test
git clone -b post_link https://github.com/hexojs/hexo.git
cd hexo
npm install
npm test
Pull Request Test Coverage Report for Build 8611939935
Details
- 15 of 15 (100.0%) changed or added relevant lines in 7 files are covered.
- No unchanged relevant lines lost coverage.
- Overall coverage decreased (-0.001%) to 99.53%
Totals | |
---|---|
Change from base Build 8578073587: | -0.001% |
Covered Lines: | 9326 |
Relevant Lines: | 9370 |
💛 - Coveralls
Help, when will the package be updated?
fail to pass test on Windows because of backslash (%5c
)
try: https://github.com/hexojs/hexo/blob/f5e0f92eda9491116c585142c565efcf7bf7a3e3/lib/theme/index.ts#L53
How to test
git clone -b post_link https://github.com/hexojs/hexo.git
cd hexo
npm install
npm test
flamegraph
https://2841be169799bd071696bb5b92e98498e843c1bf-14-hexo.surge.sh/flamegraph.html https://2841be169799bd071696bb5b92e98498e843c1bf-16-hexo.surge.sh/flamegraph.html https://2841be169799bd071696bb5b92e98498e843c1bf-18-hexo.surge.sh/flamegraph.html
@uiolee I have made the modification, and indeed, I haven't found a more elegant solution. In the future, we can consider adding this path replacement inside url_for
. The WHATWG URL Standard is capable of handling such paths.
> new URL('\\a\\b\\', 'http://example.com').pathname
'/a/b/'
Yes. I noticed that hexo uses different styles of paths in different places. Maybe we should use the same style of paths everywhere so we can avoid conversions
I think we can introduce a new convention: In the database models used by Hexo (including Asset, Page, Post, etc.), the source
attribute is used to specify the file system path under the source directory, which includes backslashes (\
) on Windows; whereas the path
attribute is used to specify their paths on the web, where backslashes should be replaced by /
.
Database model Asset
also contains an _id
attribute (instead of using the UUID automatically assigned by warehouse), which by default is the file's relative path. I have found that when using it, backslashes are replaced, which seems unnecessary. I will try to continue with the refactoring.
See https://github.com/hexojs/hexo/commit/2876faf
Another issue is that when calculating relative paths, sometimes substring
is used and sometimes relative
is used. This inconsistency also needs to be addressed and fixed in the future.