hexo-util icon indicating copy to clipboard operation
hexo-util copied to clipboard

feat: joinPath()

Open curbengh opened this issue 5 years ago • 7 comments

ref: https://github.com/hexojs/hexo/pull/4479

this enhances path.join() to convert slash, but this joinPath() doesn't resolve '../' yet.

curbengh avatar Aug 16 '20 09:08 curbengh

Coverage Status

Coverage increased (+0.05%) to 97.476% when pulling c1295d6c77a58ecad58c897c1c32db2ea0e00ade on curbengh:join-path into bf42b664e717cbf81f338e8f67aad323797c336e on hexojs:master.

coveralls avatar Aug 16 '20 09:08 coveralls

but resolving '../' is not supported

path.resolve() is work?

jiangtj avatar Aug 17 '20 01:08 jiangtj

path.resolve() is work?

I mean this joinPath() doesn't support resolving path yet, perhaps in future if there is a demand, currently it's out of scope.

for now, need to joinPath(resolve(from, to), pathtwo).


fixed unit test, ready for review.

curbengh avatar Aug 17 '20 08:08 curbengh

@curbengh

Recently I have found a package on npm: https://npm.im/url-join

Have a look?

SukkaW avatar Sep 07 '20 08:09 SukkaW

See also https://github.com/hexojs/hexo/pull/5457 I believe there are many more pieces of code that could utilize this joinPath function.

stevenjoezhang avatar Apr 11 '24 02:04 stevenjoezhang

I think it should be implemented based on path or any other module instead of string concatenation.

uiolee avatar Apr 14 '24 04:04 uiolee

Yes, maybe path.posix.join will work for such cases. Moreover, some other languages have more comprehensive libraries for path manipulation, rather than just simple string operations. I particularly like Rust's PathBuf, which is very elegant. I'm not sure if Node.js has a similar implementation.

stevenjoezhang avatar Apr 14 '24 04:04 stevenjoezhang