Skip to content

Commit

Permalink
feat: add example
Browse files Browse the repository at this point in the history
  • Loading branch information
sor4chi committed Mar 8, 2024
1 parent 7ab5ce6 commit 0e5d0a1
Show file tree
Hide file tree
Showing 8 changed files with 143 additions and 430 deletions.
51 changes: 51 additions & 0 deletions examples/next-js-blog/content/blog/sample.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
---
title: "This is a sample markdown file"
date: "2021-08-01"
description: "This is a sample markdown file for testing"
---

## Heading 2

This is a paragraph.

- This is a list item
- This is another list item

This is a code block:

```javascript
console.log("Hello, world!");
```

Also supports inline code: `console.log("Hello, world!")`

This is a link: [Google](https://www.google.com)

This is an image:
![Image](https://via.placeholder.com/150)

Support GFM

- [x] Task list item 1
- [ ] Task list item 2
- [ ] Task list item 3

This is a table:

| Header 1 | Header 2 |
| -------- | -------- |
| Cell 1 | Cell 2 |
| Cell 3 | Cell 4 |

This is a blockquote:

> This is a blockquote
> This is another line of the blockquote
This is a horizontal rule:

---

And this is a footnote[^1].

[^1]: This is a footnote.
15 changes: 14 additions & 1 deletion examples/next-js-blog/next.config.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,17 @@
/** @type {import('next').NextConfig} */
const nextConfig = {};
const nextConfig = {
output: "export",
webpack: (config, { webpack }) => {
return {
...config,
plugins: [
...config.plugins,
new webpack.IgnorePlugin({
resourceRegExp: /^electron$/,
}),
],
};
},
};

export default nextConfig;
34 changes: 34 additions & 0 deletions examples/next-js-blog/src/app/blog/[slug]/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { parseMarkdownToHTML } from "@saitamau-maximum/markdown-processor/server";
import Link from "next/link";

import {
getBlogDataFromSlug,
getBlogPathList,
getBlogSlugFromPath,
} from "../../../util/markdown";

export async function generateStaticParams() {
const paths = await getBlogPathList();
const slugs = paths.map(getBlogSlugFromPath);
return slugs.map((slug) => ({ slug }));
}

interface Props {
params: {
slug: string;
};
}

export default async function BlogDetail({ params }: Props) {
const { slug } = params;
const { data, content } = await getBlogDataFromSlug(slug);
const parsed = await parseMarkdownToHTML(content);

return (
<div>
<h1>{data.title}</h1>
<div dangerouslySetInnerHTML={{ __html: parsed.content }} />
<Link href="/">Back to Home</Link>
</div>
);
}
107 changes: 0 additions & 107 deletions examples/next-js-blog/src/app/globals.css

This file was deleted.

4 changes: 2 additions & 2 deletions examples/next-js-blog/src/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Metadata } from "next";
import { Inter } from "next/font/google";
import "./globals.css";

import type { Metadata } from "next";

const inter = Inter({ subsets: ["latin"] });

Expand Down
Loading

0 comments on commit 0e5d0a1

Please sign in to comment.