[site/config]: add keywords field and move date logic to contentlayer
This commit is contained in:
parent
0171c58d35
commit
a9b303d029
|
|
@ -5,6 +5,9 @@ import rehypeSlug from 'rehype-slug'
|
|||
import rehypeAutolinkHeadings from 'rehype-autolink-headings'
|
||||
import wikiLinkPlugin from "remark-wiki-link-plus"
|
||||
|
||||
const isValidDate = dateObject => new Date(dateObject)
|
||||
.toString() !== 'Invalid Date';
|
||||
|
||||
const ObsidianAliases = defineNestedType(() => ({
|
||||
name: 'Obsidian',
|
||||
filePathPattern: '**/*.md*',
|
||||
|
|
@ -22,6 +25,7 @@ const OtherPage = defineDocumentType(() => ({
|
|||
date: { type: "date", description: "This will be the publication date" },
|
||||
image: { type: "string" },
|
||||
description: { type: 'string' },
|
||||
keywords: { type: "string" },
|
||||
youtube: { type: "string" },
|
||||
podcast: { type: "string" },
|
||||
featured: { type: "boolean", default: false },
|
||||
|
|
@ -31,13 +35,19 @@ const OtherPage = defineDocumentType(() => ({
|
|||
computedFields: {
|
||||
date: {
|
||||
type: "date",
|
||||
resolve: (doc) => new Date(doc.date).toLocaleDateString('en-US', {
|
||||
weekday: "long", year: "numeric", month: "long", day: "numeric"
|
||||
})
|
||||
resolve: (doc) => {
|
||||
const formattedDate = new Date(doc.date).toLocaleDateString('en-US', {
|
||||
weekday: "long", year: "numeric", month: "long", day: "numeric"
|
||||
})
|
||||
return isValidDate(formattedDate) ? formattedDate : null
|
||||
}
|
||||
},
|
||||
created: {
|
||||
type: "date",
|
||||
resolve: (doc) => new Date(doc.created).toLocaleDateString('en-US')
|
||||
resolve: (doc) => {
|
||||
const formattedDate = new Date(doc.created).toLocaleDateString('en-US')
|
||||
return isValidDate(formattedDate) ? formattedDate : null
|
||||
}
|
||||
},
|
||||
}
|
||||
}));
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
import MdxPage from '../components/MDX';
|
||||
import { allOtherPages } from 'contentlayer/generated';
|
||||
import { useMDXComponent } from 'next-contentlayer/hooks';
|
||||
import siteConfig from "../config/siteConfig"
|
||||
|
||||
|
||||
export default function Page({ body, ...rest }) {
|
||||
|
|
@ -9,19 +8,12 @@ export default function Page({ body, ...rest }) {
|
|||
const children = {
|
||||
Component,
|
||||
frontmatter: {
|
||||
...rest,
|
||||
date: rest.date === "Invalid Date" ? null : rest.date,
|
||||
created: rest.created === "Invalid Date" ? null : rest.created
|
||||
...rest
|
||||
},
|
||||
};
|
||||
|
||||
// enable editing content only for claims, concepts, and guide for now
|
||||
const editUrl = ['claims', 'concepts', 'guide'].includes(rest._raw.sourceFileDir)
|
||||
? siteConfig.repoRoot + siteConfig.repoEditPath + rest._raw.sourceFilePath
|
||||
: null
|
||||
|
||||
return (
|
||||
<MdxPage children={children} editUrl={editUrl} />
|
||||
<MdxPage children={children} />
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue