♻️ Add fallback head title for board page

This commit is contained in:
Meier Lukas
2023-08-05 16:21:24 +02:00
parent da0314a180
commit f650915832
2 changed files with 11 additions and 8 deletions

View File

@@ -1,23 +1,22 @@
import Head from 'next/head'; import Head from 'next/head';
import React from 'react'; import React from 'react';
import { firstUpperCase } from '~/tools/shared/strings';
import { useConfigContext } from '../../../config/provider'; import { useConfigContext } from '../../../config/provider';
export const BoardHeadOverride = () => { export const BoardHeadOverride = () => {
const { config } = useConfigContext(); const { config, name } = useConfigContext();
if (!config) return null; if (!config || !name) return null;
const { metaTitle, faviconUrl } = config.settings.customization; const { metaTitle, faviconUrl } = config.settings.customization;
const fallbackTitle = `${firstUpperCase(name)} Board • Homarr`;
const title = metaTitle && metaTitle.length > 0 ? metaTitle : fallbackTitle;
return ( return (
<Head> <Head>
{metaTitle && metaTitle.length > 0 && ( <title>{title}</title>
<> <meta name="apple-mobile-web-app-title" content={title} />
<title>{metaTitle}</title>
<meta name="apple-mobile-web-app-title" content={metaTitle} />
</>
)}
{faviconUrl && faviconUrl.length > 0 && ( {faviconUrl && faviconUrl.length > 0 && (
<> <>

View File

@@ -8,3 +8,7 @@ export const trimStringEnding = (original: string, toTrimIfExists: string[]) =>
return original; return original;
}; };
export const firstUpperCase = (str: string) => {
return str.charAt(0).toUpperCase() + str.slice(1);
};