Metadata parsing and types update

This commit is contained in:
Matthieu Morin 2024-04-05 14:32:07 +02:00
parent 22e59b089f
commit c04d27265b
4 changed files with 23 additions and 29 deletions

View File

@ -10,5 +10,5 @@ export interface OpenGraphMetadata {
imageType: OGImageType;
imageWidth: OGImageWidth;
imageHeight: OGImageHeight;
url: string;
canonical: string;
};

View File

@ -2,7 +2,7 @@ import type { MarkdownMetadata } from '$lib/types/mdMetadata';
import type { OpenGraphMetadata } from '$lib/types/ogMetadata';
// Base service item type
export interface Service {
export type Service = {
title: string;
description: string;
id: string;

View File

@ -40,30 +40,3 @@ export const readJsonFile = async (filePath: string) => {
const jsonData = await fs.readFileSync(path.join(process.cwd(), 'src', 'content', filePath), 'utf-8');
return JSON.parse(jsonData);
}
// ======= MARKDOWN PARSER ========
// https://github.com/jonschlinkert/gray-matter
import * as matter from 'gray-matter';
// https://github.com/markedjs/marked
// import marked from 'marked';
export const parseMarkdownFile = async (filePath: string) => {
const markdownData = await fs.readFileSync(path.join(process.cwd(), 'src', 'content', filePath), 'utf-8');
const { data, content } = matter(markdownData);
return { frontmatter: data, content };
}
// export function parseMarkdown<T>(filePath: string): { frontmatter: T; content: string } {
// const data = matter.read(filePath).data;
// return {
// frontmatter: data as T,
// };
// }
// export function parseMarkdownFile(filePath: string) {
// const markdownData = fs.readFileSync(path.join(process.cwd(), filePath), 'utf-8');
// const { data, content } = grayMatter(markdownData);
// return { frontmatter: data, content };
// }
console.log(parseMarkdownFile('../../content/permanentni-make-up/pmu/pmu.md'))

View File

@ -0,0 +1,21 @@
// ======= MARKDOWN PARSER ========
// https://github.com/jonschlinkert/gray-matter
import matter from 'gray-matter';
// https://github.com/markedjs/marked;- unused
// import marked from 'marked';
import fs from 'fs';
import path from 'path'
export const parseMarkdownFile = async (filePath: string) => {
const markdownData = fs.readFileSync(path.join(process.cwd(), 'src', 'content', filePath), 'utf-8');
const { data, content } = matter(markdownData);
return { frontmatter: data, content };
}
// export function parseMarkdown<T>(filePath: string): { frontmatter: T; content: string } {
// const data = matter.read(filePath).data;
// return {
// frontmatter: data as T,
// };
// }
console.log(parseMarkdownFile('../../content/permanentni-make-up/pmu/pmu.md'))