summaryrefslogtreecommitdiffstats
path: root/src/utils/helpers/projects.ts
diff options
context:
space:
mode:
authorArmand Philippot <git@armandphilippot.com>2022-04-29 12:13:34 +0200
committerArmand Philippot <git@armandphilippot.com>2022-04-29 18:30:05 +0200
commit7e16f500cb7bc0cfd8bafbf6bb1555704f771231 (patch)
treebfc2b4a475cb06a787e2c4bdf284165644e82952 /src/utils/helpers/projects.ts
parent5324664e87bedfaa01ba62c0c847ef5b861e69b3 (diff)
chore: remove old pages, components, helpers and types
Since I'm using new components, I will also rewrite the GraphQL queries so it is easier to start from scratch.
Diffstat (limited to 'src/utils/helpers/projects.ts')
-rw-r--r--src/utils/helpers/projects.ts86
1 files changed, 0 insertions, 86 deletions
diff --git a/src/utils/helpers/projects.ts b/src/utils/helpers/projects.ts
deleted file mode 100644
index 1612dae..0000000
--- a/src/utils/helpers/projects.ts
+++ /dev/null
@@ -1,86 +0,0 @@
-import { Project, ProjectMeta } from '@ts/types/app';
-import { readdirSync } from 'fs';
-import path from 'path';
-
-/**
- * Retrieve project's data by id.
- * @param {string} id - The filename without extension.
- * @returns {Promise<Project>} - The project data.
- */
-export const getProjectData = async (id: string): Promise<Project> => {
- try {
- const {
- intro,
- meta,
- seo,
- tagline,
- }: {
- intro: string;
- meta: ProjectMeta & { title: string };
- seo: { title: string; description: string };
- tagline?: string;
- } = await import(`../../content/projects/${id}.mdx`);
-
- const { title, ...onlyMeta } = meta;
-
- return {
- id,
- intro: intro || '',
- meta: onlyMeta || {},
- slug: id,
- title,
- seo: seo || {},
- tagline: tagline || '',
- };
- } catch (err) {
- console.error(err);
- throw err;
- }
-};
-
-/**
- * Retrieve the projects data from filenames.
- * @param {string[]} filenames - An array of filenames.
- * @returns {Promise<Project[]>} An array of projects with meta.
- */
-const getProjectsWithMeta = async (filenames: string[]): Promise<Project[]> => {
- return Promise.all(
- filenames.map(async (filename) => {
- return getProjectData(filename);
- })
- );
-};
-
-/**
- * Method to sort an array of projects by publication date.
- * @param {Project} a - A single project.
- * @param {Project} b - A single project.
- * @returns The result used by Array.sort() method: 1 || -1 || 0.
- */
-const sortProjectByPublicationDate = (a: Project, b: Project) => {
- if (a.meta.publishedOn < b.meta.publishedOn) return 1;
- if (a.meta.publishedOn > b.meta.publishedOn) return -1;
- return 0;
-};
-
-/**
- * Retrieve all the projects filename.
- * @returns {string[]} An array of filenames.
- */
-export const getAllProjectsFilename = (): string[] => {
- const projectsDirectory = path.join(process.cwd(), 'src/content/projects');
- const filenames = readdirSync(projectsDirectory);
-
- return filenames.map((filename) => filename.replace(/\.mdx$/, ''));
-};
-
-/**
- * Retrieve all projects in content folder sorted by publication date.
- * @returns {Promise<Project[]>} An array of projects.
- */
-export const getSortedProjects = async (): Promise<Project[]> => {
- const filenames = getAllProjectsFilename();
- const projects = await getProjectsWithMeta(filenames);
-
- return [...projects].sort(sortProjectByPublicationDate);
-};