Added fetching of *.custom.* indexes that aren't part of source tree
This commit is contained in:
parent
507824224f
commit
fd1e3f65a8
1
changelog.d/custom.add
Normal file
1
changelog.d/custom.add
Normal file
|
@ -0,0 +1 @@
|
||||||
|
Added support for fetching /{resource}.custom.ext to allow adding instance-specific themes without altering sourcetree
|
|
@ -228,12 +228,12 @@ export const applyConfig = (input, i18n) => {
|
||||||
|
|
||||||
export const getResourcesIndex = async (url, parser = JSON.parse) => {
|
export const getResourcesIndex = async (url, parser = JSON.parse) => {
|
||||||
const cache = 'no-store'
|
const cache = 'no-store'
|
||||||
|
const customUrl = url.replace(/\.(\w+)$/, '.custom.$1')
|
||||||
|
let builtin
|
||||||
|
let custom
|
||||||
|
|
||||||
try {
|
const resourceTransform = (resources) => {
|
||||||
const data = await window.fetch(url, { cache })
|
return Object
|
||||||
const resources = await data.json()
|
|
||||||
return Object.fromEntries(
|
|
||||||
Object
|
|
||||||
.entries(resources)
|
.entries(resources)
|
||||||
.map(([k, v]) => {
|
.map(([k, v]) => {
|
||||||
if (typeof v === 'object') {
|
if (typeof v === 'object') {
|
||||||
|
@ -255,8 +255,29 @@ export const getResourcesIndex = async (url, parser = JSON.parse) => {
|
||||||
return [k, null]
|
return [k, null]
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
)
|
|
||||||
} catch (e) {
|
|
||||||
return Promise.reject(e)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const builtinData = await window.fetch(url, { cache })
|
||||||
|
const builtinResources = await builtinData.json()
|
||||||
|
builtin = resourceTransform(builtinResources)
|
||||||
|
} catch (e) {
|
||||||
|
builtin = []
|
||||||
|
console.warn(`Builtin resources at ${url} unavailable`)
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const customData = await window.fetch(customUrl, { cache })
|
||||||
|
const customResources = await customData.json()
|
||||||
|
custom = resourceTransform(customResources)
|
||||||
|
} catch (e) {
|
||||||
|
custom = []
|
||||||
|
console.warn(`Custom resources at ${customUrl} unavailable`)
|
||||||
|
}
|
||||||
|
|
||||||
|
const total = [...builtin, ...custom]
|
||||||
|
if (total.length === 0) {
|
||||||
|
return Promise.reject(new Error(`Resource at ${url} and ${customUrl} completely unavailable. Panicking`))
|
||||||
|
}
|
||||||
|
return Promise.resolve(Object.fromEntries(total))
|
||||||
}
|
}
|
||||||
|
|
1
static/.gitignore
vendored
Normal file
1
static/.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
*.custom.*
|
Loading…
Reference in a new issue