This repository has been archived by the owner on Nov 28, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🐛 Fixed editor showing incorrect domain and "unsaved changes" modal f…
…or relative links no issue - convert relative links to absolute based on the configured blog url when displaying URLs in the link toolbar and when manually setting a relative link - converting to absolute in the editor prevents the in-memory mobiledoc getting out of sync with the server response when it converts relative urls to absolute
- Loading branch information
1 parent
3b43152
commit 90fc381
Showing
3 changed files
with
44 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
export default function relativeToAbsolute(path, rootUrl) { | ||
// if URL is absolute return it as-is | ||
try { | ||
const parsed = new URL(path, 'http://relative'); | ||
|
||
if (parsed.origin !== 'http://relative') { | ||
return path; | ||
} | ||
|
||
// Do not convert protocol relative URLs | ||
if (path.lastIndexOf('//', 0) === 0) { | ||
return path; | ||
} | ||
} catch (e) { | ||
return path; | ||
} | ||
|
||
// return the path as-is if it's a pure hash param or not root-relative | ||
if (!path.startsWith('/')) { | ||
return path; | ||
} | ||
|
||
// force root to always have a trailing-slash for consistent behaviour | ||
if (!rootUrl.endsWith('/')) { | ||
rootUrl = `${rootUrl}/`; | ||
} | ||
|
||
return new URL(path, rootUrl).toString(); | ||
} |