From e4019fba593bf49d10a6f1d41e596243321f2908 Mon Sep 17 00:00:00 2001 From: khalilcodes Date: Fri, 15 Apr 2022 13:52:13 +0300 Subject: [PATCH] frontmatter setup --- site/contentlayer.config.ts | 37 +++++++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/site/contentlayer.config.ts b/site/contentlayer.config.ts index 81ec9b6..15e0d31 100644 --- a/site/contentlayer.config.ts +++ b/site/contentlayer.config.ts @@ -1,19 +1,44 @@ -import { defineDocumentType, makeSource } from 'contentlayer/source-files' +import { defineDocumentType, defineNestedType, makeSource } from 'contentlayer/source-files' // import readingTime from 'reading-time' -import remarkGfm from 'remark-gfm'; +import remarkGfm from 'remark-gfm' import rehypeSlug from 'rehype-slug' import rehypeAutolinkHeadings from 'rehype-autolink-headings' import wikiLinkPlugin from "remark-wiki-link-plus" +const ObsidianAliases = defineNestedType(() => ({ + name: 'Obsidian', + filePathPattern: '**/*.md*', + fields: { + title: { type: 'string', required: true } + } +})) + const OtherPage = defineDocumentType(() => ({ name: 'OtherPage', filePathPattern: '**/*.md*', contentType: 'mdx', fields: { - title: { type: 'string', required: false }, - date: { type: 'string', required: false }, - authors: { type: 'string', required: false }, - description: { type: 'string', required: false }, + title: { type: 'string' }, + date: { type: "date", description: "This will be the publication date" }, + image: { type: "string" }, + description: { type: 'string' }, + youtube: { type: "string" }, + podcast: { type: "string" }, + featured: { type: "boolean", default: false }, + created: { type: "date", description: "The date this page was created (For internal use)" }, + aliases: { type: 'reference', of: ObsidianAliases } + }, + computedFields: { + date: { + type: "date", + resolve: (doc) => new Date(doc.date).toLocaleDateString('en-US', { + weekday: "long", year: "numeric", month: "long", day: "numeric" + }) + }, + created: { + type: "date", + resolve: (doc) => new Date(doc.created).toLocaleDateString('en-US') + }, } }));