hexo icon indicating copy to clipboard operation
hexo copied to clipboard

fix(tag): use url_for

Open stevenjoezhang opened this issue 1 year ago • 4 comments

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.

stevenjoezhang avatar Dec 22 '23 13:12 stevenjoezhang

How to test

git clone -b post_link https://github.com/hexojs/hexo.git
cd hexo
npm install
npm test

github-actions[bot] avatar Dec 22 '23 13:12 github-actions[bot]

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 Coverage Status
Change from base Build 8578073587: -0.001%
Covered Lines: 9326
Relevant Lines: 9370

💛 - Coveralls

coveralls avatar Dec 22 '23 13:12 coveralls

Help, when will the package be updated?

hx-yinpengfei avatar Dec 25 '23 02:12 hx-yinpengfei

fail to pass test on Windows because of backslash (%5c)

log

try: https://github.com/hexojs/hexo/blob/f5e0f92eda9491116c585142c565efcf7bf7a3e3/lib/theme/index.ts#L53

uiolee avatar Dec 28 '23 13:12 uiolee

How to test

git clone -b post_link https://github.com/hexojs/hexo.git
cd hexo
npm install
npm test

github-actions[bot] avatar Apr 06 '24 11:04 github-actions[bot]

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

github-actions[bot] avatar Apr 06 '24 12:04 github-actions[bot]

@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/'

stevenjoezhang avatar Apr 06 '24 12:04 stevenjoezhang

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

uiolee avatar Apr 06 '24 12:04 uiolee

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 /.

stevenjoezhang avatar Apr 07 '24 02:04 stevenjoezhang

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

stevenjoezhang avatar Apr 07 '24 02:04 stevenjoezhang

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.

stevenjoezhang avatar Apr 07 '24 03:04 stevenjoezhang