1
0
Fork 0
This repository has been archived on 2025-08-23. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
mareshq-backoffice-v1-monolith/lib/content/training.ts
Vojtech Mares be651d1b9f
refactor: remove training property description, add svgIconURL, drop old migration and create new
- since app was not deployed yet, i deleted the migration to keep them clean
2023-06-26 22:26:13 +02:00

59 lines
1.3 KiB
TypeScript

import fs from 'fs';
import path from 'path';
import matter from 'gray-matter';
type Training = {
metadata: {
id: string;
name: string;
slug: string;
days: number;
weight: number;
draft?: boolean;
logoURL?: string;
svgIconURL?: string;
repositoryURL?: string;
priceOpen: number;
priceCorporate: number;
};
content: string;
};
export type { Training };
const root = process.cwd();
export async function getTrainingFiles() {
return fs.readdirSync(path.join(root, 'content', 'training'), 'utf-8');
}
export async function getTrainingBySlug(slug: string, fields: string[] = []) {
const source = fs.readFileSync(path.join(root, 'content', 'training', `${slug}.md`), 'utf8');
const { data, content } = matter(source);
return {
metadata: data,
content: content,
};
}
export async function getAllTrainingsWithMetadata(): Promise<Training[]> {
const files = fs.readdirSync(path.join(root, 'content', 'training'))
// @ts-ignore
return files.reduce((allTrainings, fileName) => {
const source = fs.readFileSync(path.join(root, 'content', 'training', fileName), 'utf8');
const { data, content } = matter(source);
return [
{
metadata: data,
content: content,
},
...allTrainings,
]
}, [])
}