-
-
Notifications
You must be signed in to change notification settings - Fork 432
Sane default for no base element in an html file #1208
Conversation
@Conduitry @benmccann I have rebased and submitted this new pull as a cleanup to PR #1118. Please look over and let me know if you have any feedback. Thanks for your time. |
There's a couple other PRs dealing with
I think #984 and #866 may be overlapping, but the rest (including this one) are probably largely orthogonal from each other and could all have value |
#866 is supporting website running on ipfs where the basepath is unknown, hence the need for relative base href. So from the look of it, neither #984 nor #600 will work. The latter actually mention that relative base path is not standard (and do not work on IE). This would means that #866 would not support such browser. I still think it is worth it for IPFS website that would be broken otherwise To be clear the use case is that of website that want to be fully operational from different url like :
All 3 are valid url for ipfs website. A user might prefer the easily memorable Also some browser when navigating to a domain name like examples
or
If you are using a compatible browser, the latter can be also tested with |
@jamesjnadeau what if the file isn't at the base of the static directory? E.g. you use |
@benmccann, good question,
Let's walk through your examples
with a base set to
So in the above example, any links made relatively would have to be based out of The default, when no I threw together an example here that demonstrates how this works. The sub-pages are using the My code is really just to deal with a scenario where someone forgets to put the IMHO, if someone wants to use a It's on the developer to choose how they want to handle relative urls, and with the So for the examples @wighawag offered, they should be capable of setting the I hope this answers your question and clears up some confusion here. Happy to help more if you need anything else. |
It sounds to me like |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/
would break if the current page is in a subfolder.
thanks @thgh for pointing this out Co-authored-by: Thomas Ghysels <info@thomasg.be>
src/api/export.ts
Outdated
@@ -186,7 +186,7 @@ async function _export({ | |||
const cleaned = clean_html(body); | |||
|
|||
const base_match = /<base ([\s\S]+?)>/m.exec(cleaned); | |||
const base_href = base_match && get_href(base_match[1]); | |||
const base_href = base_match ? get_href(base_match[1]) : url.pathname; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't pathname
include the the name of the html file? it wouldn't really be the base_href
in that case
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good point @benmccann
I wrapped it with a call to path.dirname, which should do as we need.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, it should include the name of the html file. I'm pretty sure that using dirname will not work, so there should be a test for it.
And to make it even better: it should include the search params to make this work correctly: href="#test"
. (Except that that link probably won't output an extra page)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For anchor tags (i.e. #test
) you would want the name of the html file, but it'd also be repetitive to visit those pages again, so the best approach would probably be discarding those. For normal links to other files I think you'd still want just the directory name, right?
In either case, I agree that a couple more tests would be nice to make sure it's clear those cases are working
per recommendation from @benmccann
Yup, I'll add some tests so we can ensure we are doing the right thing, and the right thing keeps happening. I'm going to write out the test I think need to be made, please add a note of if I missed any. As a user running export, I should be able to have an html file without a base element that...
I plan to extend the existing plain old html files in the static folder so this is dead simple to reason about. |
@jamesjnadeau sorry this hasn't been merged yet. Would you mind rebasing it? |
@benmccann just resolved the merge conflict(it was easier than rebasing, it's just indentation) I dropped this because life got in the way, but I was having trouble with the last check:
I don't remember why, but please check this out before you merge |
Is there still a hold-up needed for this? It seems to be blocking the merge of #984 |
Any html file that didn't have a
<base>
element would cause export to fail with an error that didn't really relate to the problem at hand.This pull sets a sane default and adds a test static file to the export test app to test if this is fixed.
This is a fix for #1202 and a resubmission of #1118
Before submitting the PR, please make sure you do the following
npm run lint
!)Tests
npm test
oryarn test
)