Skip to content

Commit

Permalink
Alternative implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
domdomegg committed Jan 16, 2024
1 parent 5674406 commit 497ec45
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 12 deletions.
7 changes: 4 additions & 3 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@
module.exports = async () => {
const nextMDX = require('@next/mdx');
const recmaMdxDisplayname = require('recma-mdx-displayname');
const recmaMdxFrontmatter = require('recma-mdx-frontmatter');
const recmaNextjsStaticProps = (await import('recma-nextjs-static-props')).default;
const remarkMdxFrontmatter = (await import('remark-mdx-frontmatter')).default;
const remarkFrontmatter = (await import('remark-frontmatter')).default;
const remarkGfm = (await import('remark-gfm')).default;

const withMDX = nextMDX({
extension: /\.mdx?$/,
options: {
recmaPlugins: [recmaMdxDisplayname, recmaMdxFrontmatter],
remarkPlugins: [remarkFrontmatter, remarkGfm],
recmaPlugins: [recmaMdxDisplayname, recmaNextjsStaticProps],
remarkPlugins: [remarkFrontmatter, remarkMdxFrontmatter, remarkGfm],
},
});

Expand Down
74 changes: 68 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@
"react": "18.2.0",
"react-dom": "18.2.0",
"recma-mdx-displayname": "^0.4.0",
"recma-mdx-frontmatter": "^1.0.0",
"recma-nextjs-static-props": "^2.0.0",
"remark-frontmatter": "^5.0.0",
"remark-gfm": "^4.0.0",
"remark-mdx-frontmatter": "^4.0.0",
"tailwindcss": "^3.2.4",
"typescript": "4.9.4",
"zod": "^3.22.4"
Expand Down
4 changes: 2 additions & 2 deletions pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ const App: React.FC<AppProps> = ({ Component, pageProps }: AppProps) => {
);

if (Component.displayName === 'MDXContent') {
if ('frontmatter' in Component && typeof Component.frontmatter === 'object' && Component.frontmatter !== null && 'title' in Component.frontmatter) {
if ('frontmatter' in pageProps) {
return (
<>
{common}
<ProsePage>
<article itemScope itemType="https://schema.org/BlogPosting">
<BlogHeader frontmatter={Component.frontmatter} />
<BlogHeader frontmatter={pageProps.frontmatter} />
<div itemProp="articleBody">
<Component {...pageProps} />
</div>
Expand Down
6 changes: 6 additions & 0 deletions pages/blog/example-post.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
title: 'An example post'
publishedAt: '2024-01-16'
---

This is an example blog post

0 comments on commit 497ec45

Please sign in to comment.