[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 rehypeAutolinkHeadings from 'rehype-autolink-headings'
|
||||||
import wikiLinkPlugin from "remark-wiki-link-plus"
|
import wikiLinkPlugin from "remark-wiki-link-plus"
|
||||||
|
|
||||||
|
const isValidDate = dateObject => new Date(dateObject)
|
||||||
|
.toString() !== 'Invalid Date';
|
||||||
|
|
||||||
const ObsidianAliases = defineNestedType(() => ({
|
const ObsidianAliases = defineNestedType(() => ({
|
||||||
name: 'Obsidian',
|
name: 'Obsidian',
|
||||||
filePathPattern: '**/*.md*',
|
filePathPattern: '**/*.md*',
|
||||||
|
|
@ -22,6 +25,7 @@ const OtherPage = defineDocumentType(() => ({
|
||||||
date: { type: "date", description: "This will be the publication date" },
|
date: { type: "date", description: "This will be the publication date" },
|
||||||
image: { type: "string" },
|
image: { type: "string" },
|
||||||
description: { type: 'string' },
|
description: { type: 'string' },
|
||||||
|
keywords: { type: "string" },
|
||||||
youtube: { type: "string" },
|
youtube: { type: "string" },
|
||||||
podcast: { type: "string" },
|
podcast: { type: "string" },
|
||||||
featured: { type: "boolean", default: false },
|
featured: { type: "boolean", default: false },
|
||||||
|
|
@ -31,13 +35,19 @@ const OtherPage = defineDocumentType(() => ({
|
||||||
computedFields: {
|
computedFields: {
|
||||||
date: {
|
date: {
|
||||||
type: "date",
|
type: "date",
|
||||||
resolve: (doc) => new Date(doc.date).toLocaleDateString('en-US', {
|
resolve: (doc) => {
|
||||||
weekday: "long", year: "numeric", month: "long", day: "numeric"
|
const formattedDate = new Date(doc.date).toLocaleDateString('en-US', {
|
||||||
})
|
weekday: "long", year: "numeric", month: "long", day: "numeric"
|
||||||
|
})
|
||||||
|
return isValidDate(formattedDate) ? formattedDate : null
|
||||||
|
}
|
||||||
},
|
},
|
||||||
created: {
|
created: {
|
||||||
type: "date",
|
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 MdxPage from '../components/MDX';
|
||||||
import { allOtherPages } from 'contentlayer/generated';
|
import { allOtherPages } from 'contentlayer/generated';
|
||||||
import { useMDXComponent } from 'next-contentlayer/hooks';
|
import { useMDXComponent } from 'next-contentlayer/hooks';
|
||||||
import siteConfig from "../config/siteConfig"
|
|
||||||
|
|
||||||
|
|
||||||
export default function Page({ body, ...rest }) {
|
export default function Page({ body, ...rest }) {
|
||||||
|
|
@ -9,19 +8,12 @@ export default function Page({ body, ...rest }) {
|
||||||
const children = {
|
const children = {
|
||||||
Component,
|
Component,
|
||||||
frontmatter: {
|
frontmatter: {
|
||||||
...rest,
|
...rest
|
||||||
date: rest.date === "Invalid Date" ? null : rest.date,
|
|
||||||
created: rest.created === "Invalid Date" ? null : rest.created
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
// 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 (
|
return (
|
||||||
<MdxPage children={children} editUrl={editUrl} />
|
<MdxPage children={children} />
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue