Skip to content

Commit a88cb70

Browse files
committed
Support path-based pod roots in header and footer helpers
1 parent 9046dfd commit a88cb70

2 files changed

Lines changed: 22 additions & 8 deletions

File tree

src/footer/index.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,20 @@ export function rebuildFooter (footer: HTMLElement, store: LiveStore, pod: Named
4949
*/
5050
export function createControllerInfoBlock (store: LiveStore, user: NamedNode | null, pod: NamedNode | null, podOwner: NamedNode | null, options?: FooterOptions): HTMLElement {
5151
const profileLinkContainer = document.createElement('div')
52+
profileLinkContainer.setAttribute('style', style.footer)
53+
54+
const solidProjectLink = document.createElement('a')
55+
solidProjectLink.href = options && options.solidProjectUrl ? options.solidProjectUrl : DEFAULT_SOLID_PROJECT_URL
56+
solidProjectLink.innerText = options && options.solidProjectName ? options.solidProjectName : DEFAULT_SOLID_PROJECT_NAME
57+
5258
if (!pod || !podOwner || (user && user.equals(podOwner))) {
59+
const defaultPrefix = document.createElement('span')
60+
defaultPrefix.innerText = 'Powered by '
61+
profileLinkContainer.appendChild(defaultPrefix)
62+
profileLinkContainer.appendChild(solidProjectLink)
5363
return profileLinkContainer
5464
}
5565

56-
profileLinkContainer.setAttribute('style', style.footer)
57-
5866
const podLinkPre = document.createElement('span')
5967
podLinkPre.innerText = 'You\'re visiting '
6068

@@ -72,10 +80,6 @@ export function createControllerInfoBlock (store: LiveStore, user: NamedNode | n
7280
const solidProjectLinkPre = document.createElement('span')
7381
solidProjectLinkPre.innerText = '. For more info, check out '
7482

75-
const solidProjectLink = document.createElement('a')
76-
solidProjectLink.href = options && options.solidProjectUrl ? options.solidProjectUrl : DEFAULT_SOLID_PROJECT_URL
77-
solidProjectLink.innerText = options && options.solidProjectName ? options.solidProjectName : DEFAULT_SOLID_PROJECT_NAME
78-
7983
const solidProjectLinkPost = document.createElement('span')
8084
solidProjectLinkPost.innerText = '.'
8185

src/utils/headerFooterHelpers.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,18 @@ type ThrottleOptions = {
1515
* @ignore exporting this only for the unit test
1616
*/
1717
export function getPod (): NamedNode {
18-
// @@ TODO: This is given that mashlib runs on NSS - might need to change when we want it to run on other Pod servers
19-
return sym(document.location.origin).site()
18+
const { origin, pathname } = document.location
19+
const isDatabrowserShell = document.body?.dataset?.appShell === 'databrowser'
20+
const segments = pathname.split('/').filter(Boolean)
21+
const lastSegment = segments[segments.length - 1] || ''
22+
const looksLikeFile = /\.[^/]+$/.test(lastSegment)
23+
24+
if (isDatabrowserShell && segments.length > 0 && !looksLikeFile) {
25+
return sym(`${origin}/${segments[0]}/`)
26+
}
27+
28+
// Root-hosted pods and static databrowser pages still use the site root.
29+
return sym(origin).site()
2030
}
2131
/**
2232
*/

0 commit comments

Comments
 (0)