Add docker

This commit is contained in:
2022-10-12 22:31:15 +02:00
parent c449ec250a
commit 276343378d
13 changed files with 90 additions and 9 deletions

View File

@@ -0,0 +1,96 @@
import fs from "fs";
import matter from "gray-matter";
import { MDXRemote } from "next-mdx-remote";
import { serialize } from "next-mdx-remote/serialize";
import dynamic from "next/dynamic";
import Head from "next/head";
import Link from "next/link";
import path from "path";
import CustomLink from "../../../components/CustomLink";
import Layout from "../../../components/Layout";
import { golangPostFilePaths, GOLANG_POSTS_PATH } from "../../../utils/mdxUtils";
// Custom components/renderers to pass to MDX.
// Since the MDX files aren't loaded by webpack, they have no knowledge of how
// to handle import statements. Instead, you must include components in scope
// here.
const components = {
a: CustomLink,
// It also works with dynamically-imported components, which is especially
// useful for conditionally loading components for certain routes.
// See the notes in README.md for more details.
TestComponent: dynamic(() => import("../../../components/TestComponent")),
Head,
};
export default function PostPage({ source, frontMatter }) {
return (
<Layout>
<header>
<nav>
<Link href="/">
<a>👈 Go back home</a>
</Link>
</nav>
</header>
<div className="post-header">
<h1>{frontMatter.title}</h1>
{frontMatter.description && (
<p className="description">{frontMatter.description}</p>
)}
</div>
<main>
<MDXRemote {...source} components={components} />
</main>
<style jsx>{`
.post-header h1 {
margin-bottom: 0;
}
.post-header {
margin-bottom: 2rem;
}
.description {
opacity: 0.6;
}
`}</style>
</Layout>
);
}
export const getStaticProps = async ({ params }) => {
const postFilePath = path.join(GOLANG_POSTS_PATH, `${params.slug}.mdx`);
const source = fs.readFileSync(postFilePath);
const { content, data } = matter(source);
const mdxSource = await serialize(content, {
// Optionally pass remark/rehype plugins
mdxOptions: {
remarkPlugins: [],
rehypePlugins: [],
},
scope: data,
});
return {
props: {
source: mdxSource,
frontMatter: data,
},
};
};
export const getStaticPaths = async () => {
const paths = golangPostFilePaths
// Remove file extensions for page paths
.map((path) => path.replace(/\.mdx?$/, ""))
// Map the path into the static paths object required by Next.js
.map((slug) => ({ params: { slug } }));
return {
paths,
fallback: false,
};
};

45
src/pages/index.tsx Normal file
View File

@@ -0,0 +1,45 @@
import fs from "fs";
import matter from "gray-matter";
import Link from "next/link";
import path from "path";
import Layout from "../components/Layout";
import { golangPostFilePaths, GOLANG_POSTS_PATH } from "../utils/mdxUtils";
export default function Index({ posts }) {
return (
<Layout>
<h1>Home Page</h1>
<p>
Click the link below to navigate to a page generated by{" "}
<code>next-mdx-remote</code>.
</p>
<ul>
{posts.map((post) => (
<li key={post.filePath}>
<Link
as={`/golang/posts/${post.filePath.replace(/\.mdx?$/, "")}`}
href={`/golang/posts/[slug]`}
>
<a>{post.data.title}</a>
</Link>
</li>
))}
</ul>
</Layout>
);
}
export function getStaticProps() {
const posts = golangPostFilePaths.map((filePath) => {
const source = fs.readFileSync(path.join(GOLANG_POSTS_PATH, filePath));
const { content, data } = matter(source);
return {
content,
data,
filePath,
};
});
return { props: { posts } };
}