Skip to content

fix: resolve markdown links to handle relative URLs - #358

Merged
camwiegert merged 5 commits into
masterfrom
absolute-links
Jan 28, 2019
Merged

camwiegert merged 5 commits into
masterfrom
absolute-links

Conversation

@ltm

@ltm ltm commented Jan 26, 2019

Copy link
Copy Markdown
Contributor

No description provided.

@ltm
ltm requested a review from camwiegert January 26, 2019 18:23
@camwiegert

Copy link
Copy Markdown

Looking at the way that GitHub resolves links in a README, they seem to resolve all base paths as if they were a directory.

githubResolve('/some/path', '../other-path') => '/some/other-path'
githubResolve('/some/path/', '../other-path') => '/some/other-path'

Whereas Node's plain url.resolve would handle it like this:

url.resolve('/some/path', '../other-path') => '/other-path'
url.resolve('/some/path/', '../other-path') => '/some/other-path'

So I think we should handle it like GitHub and append a trailing slash during resolution if there isn't one.

resolve(/\/$/.test(basePath) ? basePath : `${basePath}/`, href)

Does that make sense?

@ltm

ltm commented Jan 28, 2019

Copy link
Copy Markdown
Contributor Author

@camwiegert I was achieving that with the trailing slash here:

const baseUrl = `/docs/api/${title.slice(4)}/`;

But it looks like that got lost in the merge.

@camwiegert

Copy link
Copy Markdown

@ltm Oh, I see. I think I'd rather move that into the link renderer so that it will apply to every link instead of just the API pages.

@ltm

ltm commented Jan 28, 2019

Copy link
Copy Markdown
Contributor Author

@camwiegert 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants