diff options
Diffstat (limited to 'src/utils/hooks')
| -rw-r--r-- | src/utils/hooks/index.ts | 1 | ||||
| -rw-r--r-- | src/utils/hooks/use-breadcrumb.ts | 11 | ||||
| -rw-r--r-- | src/utils/hooks/use-settings.tsx | 95 |
3 files changed, 5 insertions, 102 deletions
diff --git a/src/utils/hooks/index.ts b/src/utils/hooks/index.ts index 68fb7ce..ad412c8 100644 --- a/src/utils/hooks/index.ts +++ b/src/utils/hooks/index.ts @@ -24,7 +24,6 @@ export * from './use-route-change'; export * from './use-scroll-lock'; export * from './use-scroll-position'; export * from './use-scrollbar-width'; -export * from './use-settings'; export * from './use-state-change'; export * from './use-system-color-scheme'; export * from './use-theme'; diff --git a/src/utils/hooks/use-breadcrumb.ts b/src/utils/hooks/use-breadcrumb.ts index 57c27bd..1cd18d9 100644 --- a/src/utils/hooks/use-breadcrumb.ts +++ b/src/utils/hooks/use-breadcrumb.ts @@ -2,9 +2,9 @@ import { useIntl } from 'react-intl'; import type { BreadcrumbList } from 'schema-dts'; import type { BreadcrumbsItem } from '../../components'; +import { CONFIG } from '../config'; import { ROUTES } from '../constants'; import { slugify } from '../helpers'; -import { useSettings } from './use-settings'; const isArticle = (url: string) => url.startsWith(`${ROUTES.ARTICLE}/`); @@ -61,7 +61,6 @@ export const useBreadcrumb = ({ url, }: useBreadcrumbProps): useBreadcrumbReturn => { const intl = useIntl(); - const { website } = useSettings(); const labels = { home: intl.formatMessage({ defaultMessage: 'Home', @@ -88,7 +87,7 @@ export const useBreadcrumb = ({ '@type': 'ListItem', position: 1, name: labels.home, - item: website.url, + item: CONFIG.url, }, ]; @@ -100,7 +99,7 @@ export const useBreadcrumb = ({ '@type': 'ListItem', position: 2, name: labels.blog, - item: `${website.url}${ROUTES.BLOG}`, + item: `${CONFIG.url}${ROUTES.BLOG}`, }); } @@ -110,7 +109,7 @@ export const useBreadcrumb = ({ '@type': 'ListItem', position: 2, name: labels.projects, - item: `${website.url}${ROUTES.PROJECTS}`, + item: `${CONFIG.url}${ROUTES.PROJECTS}`, }); } @@ -119,7 +118,7 @@ export const useBreadcrumb = ({ '@type': 'ListItem', position: schema.length + 1, name: title, - item: `${website.url}${url}`, + item: `${CONFIG.url}${url}`, }); return { items, schema }; diff --git a/src/utils/hooks/use-settings.tsx b/src/utils/hooks/use-settings.tsx deleted file mode 100644 index 968930d..0000000 --- a/src/utils/hooks/use-settings.tsx +++ /dev/null @@ -1,95 +0,0 @@ -import { useRouter } from 'next/router'; -import { settings } from '../config'; - -export type BlogSettings = { - /** - * The number of posts per page. - */ - postsPerPage: number; -}; - -export type CopyrightSettings = { - /** - * The copyright end year. - */ - end: string; - /** - * The copyright start year. - */ - start: string; -}; - -export type LocaleSettings = { - /** - * The default locale. - */ - default: string; - /** - * The supported locales. - */ - supported: string[]; -}; - -export type WebsiteSettings = { - /** - * The website name. - */ - name: string; - /** - * The website baseline. - */ - baseline: string; - /** - * The website copyright dates. - */ - copyright: CopyrightSettings; - /** - * The website admin email. - */ - email: string; - /** - * The website locales. - */ - locales: LocaleSettings; - /** - * The website url. - */ - url: string; -}; - -export type UseSettingsReturn = { - blog: BlogSettings; - website: WebsiteSettings; -}; - -/** - * Retrieve the website and blog settings. - * - * @returns {UseSettingsReturn} - An object describing settings. - */ -export const useSettings = (): UseSettingsReturn => { - const { baseline, copyright, email, locales, name, postsPerPage, url } = - settings; - const router = useRouter(); - const locale = router.locale ?? locales.defaultLocale; - - return { - blog: { - postsPerPage, - }, - website: { - baseline: locale.startsWith('en') ? baseline.en : baseline.fr, - copyright: { - end: copyright.endYear, - start: copyright.startYear, - }, - email, - locales: { - default: locales.defaultLocale, - supported: locales.supported, - }, - name, - url, - }, - }; -}; |
