Add tech talk helpers
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Aditya Thakral 2021-08-25 11:11:02 -04:00
parent 0cc0b307d1
commit d0fb81af67
2 changed files with 40 additions and 1 deletions

View File

@ -1,4 +1,4 @@
import { promises as fs } from "fs";
import fs from "fs/promises";
import path from "path";
import matter from "gray-matter";

39
lib/tech-talks.ts Normal file
View File

@ -0,0 +1,39 @@
import fs from "fs/promises";
import path from "path";
import matter from "gray-matter";
import { serialize } from "next-mdx-remote/serialize";
export interface Metadata {
slug: string;
index: number;
title: string;
presentors: string[];
thumbnails: { small: string; large: string };
links: { file: string; type: string; size?: string }[];
}
const TALKS_PATH = path.join("content", "tech-talks");
export async function getTechTalk(slug: string) {
const raw = await fs.readFile(path.join(TALKS_PATH, slug));
const { content, data: metadata } = matter(raw);
return {
content: await serialize(content),
metadata: { ...metadata, slug } as Metadata,
};
}
export async function getTechTalkNames() {
return (await fs.readdir(TALKS_PATH))
.filter((name) => name.endsWith(".md"))
.map((name) => name.slice(0, -1 * ".md".length));
}
export async function getTechTalks() {
const names = await getTechTalkNames();
const talks = await Promise.all(names.map(getTechTalk));
return talks.sort((a, b) => a.metadata.index - b.metadata.index);
}