Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SOEOPSFY24-205 | explore contentlayer mdx #3

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,6 @@ yarn-error.log*
# typescript
*.tsbuildinfo
next-env.d.ts

# contentlayer
.contentlayer
28 changes: 27 additions & 1 deletion app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,39 @@
import Link from 'next/link';
import { compareDesc, format, parseISO } from 'date-fns';
import { allPages, Page } from 'contentlayer/generated';
import { Heading } from '@/components/Typography';
import { ShapeAnimation } from '@/components/ShapeAnimation';
import { TimelineBanner } from '@/components/TimelineBanner';

function PostCard(page: Page) {
return (
<div className="mb-8">
<h2 className="mb-1 text-xl">
<Link href={page.url} className="text-blue-700 hover:text-blue-900 dark:text-blue-400">
{page.title}
</Link>
</h2>
<time dateTime={page.lastUpdatedDate} className="mb-2 block text-xs text-gray-600">
{format(parseISO(page.lastUpdatedDate), 'LLLL d, yyyy')}
</time>
</div>
);
}

export default function Home() {
const posts = allPages.sort(
(a: Page, b: Page) => compareDesc(new Date(a.lastUpdatedDate), new Date(b.lastUpdatedDate)),
);

return (
<div>
<Heading>SOE Centennial</Heading>
<ShapeAnimation />
<TimelineBanner heading='Headline lorem ipsum dolar sit' superhead='1983' body="Cras felis tortor, bibendum quis porttitor at, ullamcorper eu diam. Aenean iaculis efficitur quam, quis dignissim lacus. Cras nec dui id mi blandit lobortis eget in enim." />
<h1 className="mb-8 text-center text-2xl font-black">Next.js + Contentlayer Example</h1>
{posts.map((page, idx) => (
<PostCard key={idx} {...page} />
))}
</div>
);
}
}
13 changes: 13 additions & 0 deletions content/index.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
title: Homepage
lastUpdatedDate: 2024-10-15T12:00:00.000Z
---
Hello World

Donec elit libero, sodales nec, volutpat a, suscipit non, turpis. Nam pretium turpis et arcu. Etiam sollicitudin, ipsum eu pulvinar rutrum, tellus ipsum laoreet sapien, quis venenatis ante odio sit amet eros. Nunc sed turpis.

In ac felis quis tortor malesuada pretium. Curabitur blandit mollis lacus. Pellentesque commodo eros a enim. Vestibulum facilisis, purus nec pulvinar iaculis, ligula mi congue nunc, vitae euismod ligula urna in dolor.

Fusce fermentum odio nec arcu. Cras sagittis. Suspendisse potenti. Phasellus viverra nulla ut metus varius laoreet.

Curabitur ligula sapien, tincidunt non, euismod vitae, posuere imperdiet, leo. In hac habitasse platea dictumst. Aliquam lobortis. Etiam sit amet orci eget eros faucibus tincidunt.
22 changes: 22 additions & 0 deletions contentlayer.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { defineDocumentType, makeSource } from 'contentlayer2/source-files';

export const Page = defineDocumentType(() => ({
name: 'Page',
filePathPattern: '**/*.md*',
contentType: 'mdx',
fields: {
title: { type: 'string', required: true },
lastUpdatedDate: { type: 'date', required: true },
},
computedFields: {
url: {
type: 'string',
resolve: (post) => (post._raw.sourceFileName === 'index.mdx' ? '/' : `/${post._raw.flattenedPath}`),
},
},
}));

export default makeSource({
contentDirPath: 'content',
documentTypes: [Page],
});
5 changes: 4 additions & 1 deletion next.config.mjs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
/** @type {import('next').NextConfig} */
import { withContentlayer } from 'next-contentlayer2';

const nextConfig = {
basePath: '/soe-centennial-nextjs',
output: 'export',
reactStrictMode: true,
swcMinify: true,
};

export default nextConfig;
export default withContentlayer(nextConfig);
2 changes: 1 addition & 1 deletion out/404.html

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions out/_next/static/chunks/117-5377ba29bd5b0f84.js

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions out/_next/static/chunks/117-a6c8e98d841a3aab.js

This file was deleted.

1 change: 1 addition & 0 deletions out/_next/static/chunks/309-a94e03e12a05aec3.js

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion out/_next/static/chunks/478-eac99a7724af0e69.js

This file was deleted.

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

1 change: 1 addition & 0 deletions out/_next/static/chunks/app/page-5a49473c1af42b99.js

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

1 change: 0 additions & 1 deletion out/_next/static/chunks/app/page-937f4062d99f74ca.js

This file was deleted.

1 change: 1 addition & 0 deletions out/_next/static/chunks/main-b570324c46a7da8f.js

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion out/_next/static/chunks/main-f87ef28a00b0f8a6.js

This file was deleted.

Loading
Loading