Skip to content

Commit

Permalink
Added Favicon support to config
Browse files Browse the repository at this point in the history
  • Loading branch information
Mocca101 committed Aug 29, 2023
1 parent a9bbab4 commit 76f6bce
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 10 deletions.
6 changes: 5 additions & 1 deletion App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@
</div>
</template>
<script setup lang="ts">
const { $discoveryConfig } = useNuxtApp();
useHead({
titleTemplate: (titleChunk) => {
return titleChunk ? `${titleChunk} - ${$discoveryConfig.title}` : $discoveryConfig.title;
}
},
link: [
getFavicon()
]
});
</script>
20 changes: 20 additions & 0 deletions composables/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,23 @@ export function getHeaderLogo () : string {

return ($discoveryConfig.headerLogo ?? $discoveryConfig.logo) ?? '/header_logo.svg';
}

export function getFavicon () : { rel: string; type: string; href: string; sizes: string } {
const { $discoveryConfig } = useNuxtApp();

const favicon = {
rel: 'icon',
type: 'image/svg+xml',
href: '/favicon.svg',
sizes: 'any'
};
const faviconExt = $discoveryConfig.favicon?.split('.').pop();

// Can Handle SVGs, .ico
if (faviconExt === 'ico') {
favicon.type = 'image/x-icon';
favicon.href = '/' + $discoveryConfig.favicon;
}

return favicon;
}
10 changes: 10 additions & 0 deletions config/discoveryConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,22 @@ export interface DiscoveryConfig {
*/
headerLogo?: string;

// Favicon

/**
* The favicon of the website.
* Specifies the favicon that will be used for the Discovery website.
* @supportedTypes image/svg+xml, image/x-icon
*/
favicon?: string;

/**
* The title of the website.
* Specifies the title that will be used for the Discovery website.
* @default OpenAtlas Discovery
*/
title: string;

}

export const defaultDiscoveryConfig: DiscoveryConfig = {
Expand Down
10 changes: 1 addition & 9 deletions nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,7 @@ export default defineNuxtConfig({
head: {
meta: [{
name: config.title ?? 'OpenAtlas Discovery'
}],
link: [
{
rel: 'icon',
type: 'image/svg+xml',
href: '/favicon.svg',
sizes: 'any'
}
]
}]
}
},
runtimeConfig: {
Expand Down

0 comments on commit 76f6bce

Please sign in to comment.