aboutsummaryrefslogtreecommitdiffstats
path: root/src/utils/helpers
diff options
context:
space:
mode:
authorArmand Philippot <git@armandphilippot.com>2023-11-15 12:24:42 +0100
committerArmand Philippot <git@armandphilippot.com>2023-11-15 17:26:16 +0100
commit0f38aee374029213a47ef7c29bd164093fe63c85 (patch)
tree290cb6471fdfe81e4c42f4da4729247536b04ee7 /src/utils/helpers
parentbe4d907efb4e2fa658baa7c9b276ed282eb920db (diff)
refactor(hooks): remove useSettings hook
It does not make sense to re-export an existing object through a hook. On some pages both the hook and the object was imported... It is better to use the CONFIG (previously settings) object directly and by doing it we avoid potential errors because of conditional hooks.
Diffstat (limited to 'src/utils/helpers')
-rw-r--r--src/utils/helpers/rss.ts22
-rw-r--r--src/utils/helpers/schema-org.ts38
-rw-r--r--src/utils/helpers/server/i18n.ts6
3 files changed, 33 insertions, 33 deletions
diff --git a/src/utils/helpers/rss.ts b/src/utils/helpers/rss.ts
index 0381c68..6de60cc 100644
--- a/src/utils/helpers/rss.ts
+++ b/src/utils/helpers/rss.ts
@@ -5,7 +5,7 @@ import {
getTotalArticles,
} from '../../services/graphql';
import type { Article } from '../../types';
-import { settings } from '../config';
+import { CONFIG } from '../config';
import { ROUTES } from '../constants';
/**
@@ -32,25 +32,25 @@ const getAllArticles = async (): Promise<Article[]> => {
*/
export const generateFeed = async (): Promise<Feed> => {
const author = {
- name: settings.name,
+ name: CONFIG.name,
email: process.env.APP_AUTHOR_EMAIL,
- link: settings.url,
+ link: CONFIG.url,
};
- const copyright = `${settings.name} CC BY SA ${settings.copyright.startYear} - ${settings.copyright.endYear}`;
- const title = `${settings.name} | ${settings.baseline.fr}`;
+ const copyright = `${CONFIG.name} CC BY SA ${CONFIG.copyright.startYear} - ${CONFIG.copyright.endYear}`;
+ const title = `${CONFIG.name} | ${CONFIG.baseline}`;
const feed = new Feed({
author,
copyright,
description: process.env.APP_FEED_DESCRIPTION,
feedLinks: {
- json: `${settings.url}${ROUTES.RSS}/json`,
- atom: `${settings.url}${ROUTES.RSS}/atom`,
+ json: `${CONFIG.url}${ROUTES.RSS}/json`,
+ atom: `${CONFIG.url}${ROUTES.RSS}/atom`,
},
generator: 'Feed & NextJS',
- id: settings.url,
- language: settings.locales.defaultLocale,
- link: settings.url,
+ id: CONFIG.url,
+ language: CONFIG.locales.defaultLocale,
+ link: CONFIG.url,
title,
});
@@ -62,7 +62,7 @@ export const generateFeed = async (): Promise<Feed> => {
date: new Date(article.meta.dates.publication),
description: article.intro,
id: `${article.id}`,
- link: `${settings.url}${ROUTES.ARTICLE}/${article.slug}`,
+ link: `${CONFIG.url}${ROUTES.ARTICLE}/${article.slug}`,
title: article.title,
});
});
diff --git a/src/utils/helpers/schema-org.ts b/src/utils/helpers/schema-org.ts
index 12bad28..2edc11b 100644
--- a/src/utils/helpers/schema-org.ts
+++ b/src/utils/helpers/schema-org.ts
@@ -8,7 +8,7 @@ import type {
WebPage,
} from 'schema-dts';
import type { Dates } from '../../types';
-import { settings } from '../config';
+import { CONFIG } from '../config';
import { ROUTES } from '../constants';
export type GetBlogSchemaProps = {
@@ -38,22 +38,22 @@ export const getBlogSchema = ({
slug,
}: GetBlogSchemaProps): Blog => {
return {
- '@id': `${settings.url}/#blog`,
+ '@id': `${CONFIG.url}/#blog`,
'@type': 'Blog',
- author: { '@id': `${settings.url}/#branding` },
- creator: { '@id': `${settings.url}/#branding` },
- editor: { '@id': `${settings.url}/#branding` },
- blogPost: isSinglePage ? { '@id': `${settings.url}/#article` } : undefined,
+ author: { '@id': `${CONFIG.url}/#branding` },
+ creator: { '@id': `${CONFIG.url}/#branding` },
+ editor: { '@id': `${CONFIG.url}/#branding` },
+ blogPost: isSinglePage ? { '@id': `${CONFIG.url}/#article` } : undefined,
inLanguage: locale,
isPartOf: isSinglePage
? {
- '@id': `${settings.url}${slug}`,
+ '@id': `${CONFIG.url}${slug}`,
}
: undefined,
license: 'https://creativecommons.org/licenses/by-sa/4.0/deed.fr',
mainEntityOfPage: isSinglePage
? undefined
- : { '@id': `${settings.url}${slug}` },
+ : { '@id': `${CONFIG.url}${slug}` },
};
};
@@ -137,19 +137,19 @@ export const getSinglePageSchema = <T extends SinglePageSchemaKind>({
};
return {
- '@id': `${settings.url}/#${id}`,
+ '@id': `${CONFIG.url}/#${id}`,
'@type': singlePageSchemaType[kind],
name: title,
description,
articleBody: content,
- author: { '@id': `${settings.url}/#branding` },
+ author: { '@id': `${CONFIG.url}/#branding` },
commentCount: commentsCount,
copyrightYear: publicationDate.getFullYear(),
- creator: { '@id': `${settings.url}/#branding` },
+ creator: { '@id': `${CONFIG.url}/#branding` },
dateCreated: publicationDate.toISOString(),
dateModified: updateDate?.toISOString(),
datePublished: publicationDate.toISOString(),
- editor: { '@id': `${settings.url}/#branding` },
+ editor: { '@id': `${CONFIG.url}/#branding` },
headline: title,
image: cover,
inLanguage: locale,
@@ -158,10 +158,10 @@ export const getSinglePageSchema = <T extends SinglePageSchemaKind>({
isPartOf:
kind === 'post'
? {
- '@id': `${settings.url}${ROUTES.BLOG}`,
+ '@id': `${CONFIG.url}${ROUTES.BLOG}`,
}
: undefined,
- mainEntityOfPage: { '@id': `${settings.url}${slug}` },
+ mainEntityOfPage: { '@id': `${CONFIG.url}${slug}` },
} as SinglePageSchemaReturn[T];
};
@@ -202,17 +202,17 @@ export const getWebPageSchema = ({
updateDate,
}: GetWebPageSchemaProps): WebPage => {
return {
- '@id': `${settings.url}${slug}`,
+ '@id': `${CONFIG.url}${slug}`,
'@type': 'WebPage',
- breadcrumb: { '@id': `${settings.url}/#breadcrumb` },
+ breadcrumb: { '@id': `${CONFIG.url}/#breadcrumb` },
lastReviewed: updateDate,
name: title,
description,
inLanguage: locale,
- reviewedBy: { '@id': `${settings.url}/#branding` },
- url: `${settings.url}${slug}`,
+ reviewedBy: { '@id': `${CONFIG.url}/#branding` },
+ url: `${CONFIG.url}${slug}`,
isPartOf: {
- '@id': `${settings.url}`,
+ '@id': `${CONFIG.url}`,
},
};
};
diff --git a/src/utils/helpers/server/i18n.ts b/src/utils/helpers/server/i18n.ts
index dbbc4e5..8abd92e 100644
--- a/src/utils/helpers/server/i18n.ts
+++ b/src/utils/helpers/server/i18n.ts
@@ -1,10 +1,10 @@
import { readFile } from 'fs/promises';
import path from 'path';
-import { settings } from '../../config';
+import { CONFIG } from '../../config';
-export type Messages = { [key: string]: string };
+export type Messages = Record<string, string>;
-export const defaultLocale = settings.locales.defaultLocale;
+export const { defaultLocale } = CONFIG.locales;
/**
* Load the translation for the provided locale.