-
Notifications
You must be signed in to change notification settings - Fork 42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Multi source support for commerce configs and placeholders #286
base: main
Are you sure you want to change the base?
Changes from 16 commits
5af1925
6d845e6
a60bc9c
1433d1a
4174060
3ef2451
5517558
09f2ed1
f50a66e
6bccb24
f7458e3
4af4b69
30be7c5
396deb2
a0fa27a
5f78829
9156bd9
7e9133b
91a34b7
1a7c265
a2e1271
7c6a4f2
e63b1f6
9cc9754
42efb12
e0943a7
6efb16f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -150,6 +150,7 @@ export function decorateMain(main) { | |
buildAutoBlocks(main); | ||
decorateSections(main); | ||
decorateBlocks(main); | ||
decorateLinks(main); | ||
} | ||
|
||
function preloadFile(href, as) { | ||
|
@@ -356,6 +357,45 @@ export async function fetchIndex(indexFile, pageSize = 500) { | |
return newIndex; | ||
} | ||
|
||
/** | ||
* Get root path | ||
*/ | ||
export function getRootPath() { | ||
window.ROOT_PATH = window.rootPath || getMetadata('root') || '/'; | ||
fnhipster marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return window.ROOT_PATH; | ||
} | ||
|
||
/** | ||
* Decorates links. | ||
* @param {Element} main The main element | ||
*/ | ||
export function decorateLinks(main) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should not be needed once the content was updated accordingly. There shouldn't be any links in the content that point to a URL that does not include the root. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about links added to the document? How would those be relative to the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You would link to a document like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's a good point. @anthoula, can you try removing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
const root = getRootPath(); | ||
if (root === '/') return; | ||
const links = main.querySelectorAll('a'); | ||
|
||
links.forEach((link) => { | ||
if (link.href.startsWith('//' || link.href.startsWith(root))) return; | ||
fnhipster marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
if ( | ||
link.href.startsWith('/') | ||
|| link.href.startsWith(window.location.origin) | ||
) { | ||
const url = new URL(link.href, window.location.origin); | ||
link.href = `${root}${url.pathname.substring(1)}${url.search}${url.hash}`; | ||
} | ||
}); | ||
} | ||
|
||
/** | ||
* Decorates links. | ||
* @param {string} [url] url to be localized | ||
*/ | ||
export function localizeLink(link) { | ||
const root = getRootPath().replace(/\/$/, ''); | ||
return `${root}${link}`; | ||
} | ||
|
||
/** | ||
* Check if consent was given for a specific topic. | ||
* @param {*} topic Topic identifier | ||
|
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.
See my comment on placeholder fallbacks.