shadowfacts.net/lib/metadata.ts

36 lines
738 B
TypeScript

import { promises as fs } from "fs";
export interface Page {
text: string;
metadata: Metadata;
}
export interface Metadata {
permalink: string;
source?: string;
layout?: string;
oldPermalink?: string;
}
export interface PostMetadata extends Metadata {
title: string;
slug: string;
category: string;
date: string | Date;
excerpt?: string;
uuid: string;
}
export async function get(path: string): Promise<Page> {
let text = (await fs.readFile(path)).toString();
let metadata = {
source: path
} as Metadata;
if (text.startsWith("```")) {
const parts = text.split("```");
text = parts.slice(2).join("```");
const configure = new Function("metadata", parts[1]);
configure(metadata);
}
return {text, metadata};
}