Closed jzz4012650 closed 2 years ago
Just inspired by #694, maybe we could add a hack here make the following different?
Probably in core or as a new plugin?
/abc.html
pointing to base root as expected$abc.html
poiting to host rootE.g.: with base /demo/
:
/abc.html
is /demo/abc.html
$abc.html
is /abc.html
@meteorlxy is this ok for you?
@jzz4012650 I am disagree your "Proposed Solution" . A docs may deployed under server domain.
For vuepress2 docs, it's available at:
Also ,this becomes problematic even when you deploy in one place: you are stoping others to simply mirror it.
Just inspired by #694, maybe we could add a hack here make the following different?
Probably in core or as a new plugin?
/abc.html
pointing to base root as expected$abc.html
poiting to host rootE.g.: with base
/demo/
:
/abc.html
is/demo/abc.html
$abc.html
is/abc.html
@meteorlxy is this ok for you?
Does it supported now?
I will share some other advantages when using relative links.
$
as I mentioned above) will be broken in that case.It's not recommanded to change your doc structure very often, as users may add them as bookmark, or reference theme in other places. It's allways good to choose a good link wisely at the beginning.
And even if you change the url, you would better keep the old link available, just see what vue is doing at here. If you make sure the old link is available, there would be no broken links even if you forgot some.
But on the other hand, I do agree that it's good to have something I mention above to provide users more choise.
@meteorlxy I am planning to work on this, and I want to make sure that if this is ok to you:
Starting with base: '/base/'
as an exmple.
All markdown links should be resolved as <RouterLink />
so:
[Home](/README.md)
[Guide](/guide.md)
should be
<RouterLlink to="/">Home</RouterLink>
<RouterLlink to="/guide.html">Guide</RouterLink>
which is acutally:
<a href="/base/">Home</a>
<a href="/base/guide.html">Guide</a>
And when user want some thing without base, they should use a link not ending with .md
, and we will keep them as is:
<!-- /index.html should be the same-->
[Home](/)
[Guide](/guide.html)
should be
<!-- or /index.html when setting /index.html -->
<a href="/">Home</a>
<a href=/guide.html">Guide</a>
For anyone else running into this while the linked PR is not yet merged, you can solve this with a simple inline plugin that hacks markdown-it to prepend the base URL:
const baseUrl = "/SomeBaseUrl"
export default {
base: `${baseUrl}/`,
plugins: [
{
// Workaround for https://github.com/vuepress/vuepress-next/issues/653
// Prepend absolute URLs with base URL.
name: "baseify-link",
extendsMarkdown(md) {
const old = md.normalizeLink;
md.normalizeLink = (url) => {
url = old(url);
if (url.startsWith("/") && !url.startsWith(baseUrl)) {
url = baseUrl + url
}
return url;
}
}
},
]
}
@meteorlxy the fix in the linked commit doesn't work for .md
links that include a fragment. E.g. it works for /some/file.md
, but does not work for /some/file.md#heading
.
Would you like me to open a new issue, or do you want to reopen this one to track this?
@ascott18 It's better to open another bug report for that. The original issue was not in English, which is bad for reference. And, it was for the feature, not for the following bug.
Fixed in 252f4acb2f7b69b8c920aafac362d44027f9ae49
Feature request
Description
关联讨论 #652
设置了
base
选项的时候,希望能够自动将站内绝对路径转为<router-link>
,而现在会转为<a>
,导致需要将绝对路径改为相对路径;(关联文档)Proposed Solution
以
base
为/foo
的情况为例:[Guide](/guide/)
base
地址开头):[Guide](https://some-site.com/bar/guide/)
<a>
标签:<a href="/bar/guide/">Guide</a>
PS:Vue-Press 是个优秀的静态站点生成工具,插件化设计尤其棒,感谢开发组同学们的付出 ❤️ !