1
0
Fork 0

refactor: move lib/* to src/

This commit is contained in:
Vojtěch Mareš 2023-07-04 18:47:05 +02:00
parent 2745bb32c7
commit 7ae10b4ecc
Signed by: vojtech.mares
GPG key ID: C6827B976F17240D
6 changed files with 5 additions and 6 deletions

65
src/content/training.ts Normal file
View file

@ -0,0 +1,65 @@
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 function getTrainingFiles() {
return fs.readdirSync(path.join(root, 'content', 'training'), 'utf-8');
}
export function getTrainingBySlug(slug: string) {
const source = fs.readFileSync(path.join(root, 'content', 'training', `${slug}.md`), 'utf8');
const { data, content } = matter(source);
return {
metadata: data,
content: content,
};
}
export function getAllTrainingsWithMetadata(): Training[] {
const files = fs.readdirSync(path.join(root, 'content', 'training'))
const trainings = [] as Training[];
for (const fileName of files) {
const source = fs.readFileSync(path.join(root, 'content', 'training', fileName), 'utf8');
const { data: metadata, content: content } = matter(source);
trainings.push({metadata, content} as Training);
}
return trainings;
// return files.reduce((allTrainings, fileName) => {
// const source = fs.readFileSync(path.join(root, 'content', 'training', fileName), 'utf8');
// const training = matter(source);
// return [
// training,
// ...allTrainings,
// ]
// }, [])
}

View file

@ -0,0 +1,9 @@
export function formatCurrency(price: number | bigint, locale ='en-US', currency = 'CZK'): string {
const currencyFormatter = new Intl.NumberFormat(locale, {
style: 'currency',
currency: currency,
maximumFractionDigits: 0,
});
return currencyFormatter.format(price).replace(',', ' ')
}

View file

@ -3,7 +3,7 @@ import { type GetServerSideProps } from "next";
import Head from "next/head";
import Link from "next/link";
import { formatCurrency } from "~/lib/currency/formatter";
import { formatCurrency } from "~/currency/formatter";
import { getServerAuthSession } from "~/server/auth";
import { prisma } from "~/server/db";

View file

@ -2,11 +2,11 @@ import { type GetServerSideProps } from "next";
import Head from "next/head";
import Link from "next/link";
import { formatCurrency } from "~/lib/currency/formatter";
import { formatCurrency } from "~/currency/formatter";
import { getServerAuthSession } from "~/server/auth";
import { prisma } from "~/server/db";
import { Training } from "lib/content/training";
import { Training } from "~/content/training";
import { Layout } from "~/components/Layout";
import { Button } from "~/components/Button";