aboutsummaryrefslogtreecommitdiffstats
path: root/src/utils/helpers
diff options
context:
space:
mode:
authorArmand Philippot <git@armandphilippot.com>2023-09-20 16:38:54 +0200
committerArmand Philippot <git@armandphilippot.com>2023-09-20 16:38:54 +0200
commitf861e6a269ba9f62700776d3cd13b644a9e836d4 (patch)
treea5a107e7a6e4ff8b4261fe04349357bc00b783ee /src/utils/helpers
parent03331c44276ec56e9f235e4d5ee75030455a753f (diff)
refactor: use named export for everything except pages
Next expect a default export for pages so only those components should use default exports. Everything else should use named exports to reduce the number of import statements.
Diffstat (limited to 'src/utils/helpers')
-rw-r--r--src/utils/helpers/author.ts3
-rw-r--r--src/utils/helpers/images.ts3
-rw-r--r--src/utils/helpers/index.ts7
-rw-r--r--src/utils/helpers/pages.ts12
-rw-r--r--src/utils/helpers/rss.ts4
-rw-r--r--src/utils/helpers/schema-org.ts2
-rw-r--r--src/utils/helpers/server/i18n.ts (renamed from src/utils/helpers/i18n.ts)22
-rw-r--r--src/utils/helpers/server/index.ts2
-rw-r--r--src/utils/helpers/server/projects.ts (renamed from src/utils/helpers/projects.ts)15
9 files changed, 31 insertions, 39 deletions
diff --git a/src/utils/helpers/author.ts b/src/utils/helpers/author.ts
index 2892524..a5e9bc6 100644
--- a/src/utils/helpers/author.ts
+++ b/src/utils/helpers/author.ts
@@ -1,5 +1,4 @@
-import { type Author, type ContentKind } from '../../types/app';
-import { type RawAuthor } from '../../types/raw-data';
+import { type Author, type ContentKind, type RawAuthor } from '../../types';
/**
* Convert author raw data to regular data.
diff --git a/src/utils/helpers/images.ts b/src/utils/helpers/images.ts
index bff50c3..6e0c2c5 100644
--- a/src/utils/helpers/images.ts
+++ b/src/utils/helpers/images.ts
@@ -1,5 +1,4 @@
-import { Image } from '../../types/app';
-import { RawCover } from '../../types/raw-data';
+import { type Image, type RawCover } from '../../types';
/**
* Retrieve an Image object from raw data.
diff --git a/src/utils/helpers/index.ts b/src/utils/helpers/index.ts
new file mode 100644
index 0000000..1a35583
--- /dev/null
+++ b/src/utils/helpers/index.ts
@@ -0,0 +1,7 @@
+export * from './author';
+export * from './dates';
+export * from './images';
+export * from './pages';
+export * from './rss';
+export * from './schema-org';
+export * from './strings';
diff --git a/src/utils/helpers/pages.ts b/src/utils/helpers/pages.ts
index d6d44d2..6b27b6d 100644
--- a/src/utils/helpers/pages.ts
+++ b/src/utils/helpers/pages.ts
@@ -1,13 +1,13 @@
-import { type Post } from '../../components/organisms/layout/posts-list';
-import { type LinksListItems } from '../../components/organisms/widgets/links-list-widget';
-import { getArticleFromRawData } from '../../services/graphql/articles';
-import { type Article, type PageLink } from '../../types/app';
-import { EdgesResponse } from '../../types/graphql/queries';
+import { type LinksListItems, type Post } from '../../components';
+import { getArticleFromRawData } from '../../services/graphql';
import {
+ type Article,
+ type EdgesResponse,
+ type PageLink,
type RawArticle,
type RawThematicPreview,
type RawTopicPreview,
-} from '../../types/raw-data';
+} from '../../types';
import { getImageFromRawData } from './images';
/**
diff --git a/src/utils/helpers/rss.ts b/src/utils/helpers/rss.ts
index 41a036c..28f3c7b 100644
--- a/src/utils/helpers/rss.ts
+++ b/src/utils/helpers/rss.ts
@@ -3,8 +3,8 @@ import {
getArticleFromRawData,
getArticles,
getTotalArticles,
-} from '../../services/graphql/articles';
-import { Article } from '../../types/app';
+} from '../../services/graphql';
+import { type Article } from '../../types';
import { settings } from '../../utils/config';
/**
diff --git a/src/utils/helpers/schema-org.ts b/src/utils/helpers/schema-org.ts
index 5d400c8..82f99c2 100644
--- a/src/utils/helpers/schema-org.ts
+++ b/src/utils/helpers/schema-org.ts
@@ -7,7 +7,7 @@ import {
Graph,
WebPage,
} from 'schema-dts';
-import { Dates } from '../../types/app';
+import { type Dates } from '../../types';
import { settings } from '../../utils/config';
export type GetBlogSchemaProps = {
diff --git a/src/utils/helpers/i18n.ts b/src/utils/helpers/server/i18n.ts
index 35d495e..dbbc4e5 100644
--- a/src/utils/helpers/i18n.ts
+++ b/src/utils/helpers/server/i18n.ts
@@ -1,7 +1,6 @@
-import { createIntl, createIntlCache, IntlShape } from '@formatjs/intl';
import { readFile } from 'fs/promises';
import path from 'path';
-import { settings } from '../config';
+import { settings } from '../../config';
export type Messages = { [key: string]: string };
@@ -16,7 +15,7 @@ export const defaultLocale = settings.locales.defaultLocale;
export async function loadTranslation(
currentLocale: string | undefined
): Promise<Messages> {
- const locale: string = currentLocale || defaultLocale;
+ const locale: string = currentLocale ?? defaultLocale;
const languagePath = path.join(process.cwd(), `lang/${locale}.json`);
@@ -30,20 +29,3 @@ export async function loadTranslation(
throw error;
}
}
-
-/**
- * Create an Intl object to be used outside components.
- *
- * @returns {<Promise<IntlShape<string>>} The Intl object.
- */
-export async function getIntlInstance(): Promise<IntlShape<string>> {
- try {
- const cache = createIntlCache();
- const messages = await loadTranslation(defaultLocale);
-
- return createIntl({ locale: defaultLocale, messages }, cache);
- } catch (error) {
- console.error('Error: Could not create an Intl instance.');
- throw error;
- }
-}
diff --git a/src/utils/helpers/server/index.ts b/src/utils/helpers/server/index.ts
new file mode 100644
index 0000000..56ebad5
--- /dev/null
+++ b/src/utils/helpers/server/index.ts
@@ -0,0 +1,2 @@
+export * from './i18n';
+export * from './projects';
diff --git a/src/utils/helpers/projects.ts b/src/utils/helpers/server/projects.ts
index 0e4de7d..ed73da8 100644
--- a/src/utils/helpers/projects.ts
+++ b/src/utils/helpers/server/projects.ts
@@ -1,7 +1,10 @@
-import { readdirSync } from 'node:fs';
-import path from 'node:path';
-import { ProjectCard, ProjectPreview } from '../../types/app';
-import { MDXProjectMeta } from '../../types/mdx';
+import { readdirSync } from 'fs';
+import path from 'path';
+import {
+ type MDXProjectMeta,
+ type ProjectCard,
+ type ProjectPreview,
+} from '../../../types';
/**
* Retrieve all the projects filename.
@@ -29,11 +32,11 @@ export const getProjectData = async (
meta,
}: {
meta: MDXProjectMeta;
- } = await import(`../../content/projects/${filename}.mdx`);
+ } = await import(`../../../content/projects/${filename}.mdx`);
const { dates, intro, title, ...projectMeta } = meta;
const { publication, update } = dates;
- const cover = await import(`../../../public/projects/${filename}.jpg`);
+ const cover = await import(`../../../../public/projects/${filename}.jpg`);
return {
id: filename,