mirror of
https://github.com/YunoHost/yunohost-portal.git
synced 2024-09-03 20:06:23 +02:00
fix: fetch logo content for svg
This commit is contained in:
parent
3fd3e24891
commit
204306d8c4
2 changed files with 21 additions and 27 deletions
|
@ -1,44 +1,23 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
const settings = await useSettings()
|
let customLogo: Settings['portal_logo']
|
||||||
type CustomLogo = Partial<Record<'is' | 'src', string>>
|
|
||||||
let customLogo: Ref<CustomLogo> | ComputedRef<CustomLogo>
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const settings = await useSettings()
|
const settings = await useSettings()
|
||||||
|
customLogo = settings.value.portal_logo
|
||||||
customLogo = computed(() => {
|
} catch {
|
||||||
const logo = settings.value.portal_logo
|
|
||||||
|
|
||||||
if (!logo) return {}
|
|
||||||
|
|
||||||
if (logo.substr(-4) === '.svg') {
|
|
||||||
// Will render as inline SVG so that CSS "currentColor" can cascade to it
|
|
||||||
return {
|
|
||||||
is: 'svg',
|
|
||||||
src: `//${settings.value.domain}/yunohost/sso/customassets/${logo}`,
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return {
|
|
||||||
is: 'img',
|
|
||||||
src: `//${settings.value.domain}/yunohost/sso/customassets/${logo}`,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
} catch (error) {
|
|
||||||
// If `yunohost-portal-api` is down we can't get settings
|
// If `yunohost-portal-api` is down we can't get settings
|
||||||
customLogo = ref({})
|
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div
|
<div
|
||||||
v-if="customLogo.is === 'svg'"
|
v-if="customLogo?.is === 'svg'"
|
||||||
aria-hidden="true"
|
aria-hidden="true"
|
||||||
class="svg-div"
|
class="svg-div"
|
||||||
v-html="customLogo.src"
|
v-html="customLogo.src"
|
||||||
/>
|
/>
|
||||||
<img
|
<img
|
||||||
v-else-if="customLogo.is === 'img'"
|
v-else-if="customLogo?.is === 'svg'"
|
||||||
:src="customLogo.src"
|
:src="customLogo.src"
|
||||||
alt=""
|
alt=""
|
||||||
aria-hidden="true"
|
aria-hidden="true"
|
||||||
|
|
|
@ -81,7 +81,7 @@ export const useQueryMsg = () => useState<string | null>('queryMsg', () => null)
|
||||||
export interface Settings {
|
export interface Settings {
|
||||||
domain: string
|
domain: string
|
||||||
public: boolean
|
public: boolean
|
||||||
portal_logo?: string
|
portal_logo?: { is: 'img' | 'svg', src: string }
|
||||||
portal_theme: string
|
portal_theme: string
|
||||||
portal_title?: string
|
portal_title?: string
|
||||||
search_engine?: string
|
search_engine?: string
|
||||||
|
@ -99,6 +99,21 @@ export const useSettings = async () => {
|
||||||
|
|
||||||
if (!settings.value) {
|
if (!settings.value) {
|
||||||
const { data } = await useApi<Settings>('/public')
|
const { data } = await useApi<Settings>('/public')
|
||||||
|
|
||||||
|
const logo = data.value.portal_logo
|
||||||
|
if (logo) {
|
||||||
|
const src = `https://${data.value.domain}/yunohost/sso/customassets/${logo}`
|
||||||
|
const is = data.value.portal_logo.substr(-4) === '.svg' ? 'svg' : 'img'
|
||||||
|
data.value.portal_logo = { is, src: is === 'svg' ? '' : src }
|
||||||
|
|
||||||
|
if (is === 'svg') {
|
||||||
|
// Query file content to inject inline SVG so that CSS "currentColor" can cascade to it
|
||||||
|
$fetch(src).then((blob) => blob.text()).then((text) => {
|
||||||
|
data.value.portal_logo.src = text.replace('<?xml version="1.0" encoding="utf-8"?>', '')
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
settings.value = data.value as Settings
|
settings.value = data.value as Settings
|
||||||
|
|
||||||
const colorMode = useColorMode()
|
const colorMode = useColorMode()
|
||||||
|
|
Loading…
Reference in a new issue