-
Notifications
You must be signed in to change notification settings - Fork 474
Markdown Example #603
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
base: main
Are you sure you want to change the base?
Markdown Example #603
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this related to Hono? I think this is just a description of Markdown and Frontmatter. Not integrated to Hono.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, skipped most important part (after multiple variations, my mind just skipped hono part) - showing example on Hono route. Will add. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| # Markdown + Frontmatter | ||
|
|
||
| Markdown is a popular lightweight markup language that is widely used for creating website content and documentation. Its simple and readable syntax makes it an excellent choice for writing web pages, blog posts, and technical documentation. | ||
|
|
||
| Here's an example of how to handle Markdown content with Hono: | ||
|
|
||
| ## 🛠️ Installation | ||
| ```sh | ||
| npm install unified remark-parse remark-extract-frontmatter remark-rehype remark-frontmatter rehype-stringify yaml | ||
| ``` | ||
|
|
||
| ## 🚀 Setup | ||
|
|
||
| ```ts | ||
| import remarkParse from "remark-parse"; | ||
| import remarkRehype from "remark-rehype"; | ||
| import rehypeStringify from "rehype-stringify"; | ||
| import { parse as parseYaml } from "yaml"; | ||
|
|
||
| const parse = (markdownContent: string) => { | ||
| const { value } = await unified() | ||
| .use(remarkParse) | ||
| .use(remarkRehype) | ||
| .use(rehypeStringify) | ||
| .process(markdownContent); | ||
| return { value }; | ||
| } | ||
| ``` | ||
|
|
||
| ## 📝 Frontmatter | ||
| Frontmatter is a section at the beginning of a Markdown file that contains metadata about the content. It's typically written in YAML format and enclosed between triple-dashes (`---`). This metadata can include information like title, date, author, tags, or any other custom fields you want to define. | ||
|
|
||
| Here's how you can extract Frontmatter | ||
|
|
||
| 1. First install additionll dependencies | ||
| ```sh | ||
| npm install remark-extract-frontmatter remark-frontmatter | ||
| ``` | ||
|
|
||
| 2. Use `remark` plugins: | ||
| ```ts | ||
| import remarkParse from "remark-parse"; | ||
| import remarkExtractFrontmatter from "remark-extract-frontmatter"; | ||
| import remarkFrontmatter from "remark-frontmatter"; | ||
| import remarkRehype from "remark-rehype"; | ||
| import rehypeStringify from "rehype-stringify"; | ||
| import { parse as parseYaml } from "yaml"; | ||
|
|
||
| const parse = (markdownContent: string) => { | ||
| const { data, value } = await unified() | ||
| .use(remarkParse) | ||
| .use(remarkExtractFrontmatter, { yaml: parseYaml }) | ||
| .use(remarkFrontmatter) | ||
| .use(remarkRehype) | ||
| .use(rehypeStringify) | ||
| .process(markdownContent); | ||
| return { data, value }; // { data: {}; value: string } | ||
| } | ||
| ``` | ||
|
|
||
| ## 💡 Example usage | ||
| ```tsx | ||
| const markdownContent = `--- | ||
| title: Hello World | ||
| description: Hello World example page for hono documentation | ||
| nested: | ||
| foo: bar | ||
| --- | ||
|
|
||
| ## Section A | ||
| Hello | ||
| `; | ||
|
|
||
| const parsedContent = parse(markdownContent); | ||
|
|
||
| console.log(parsedContent); | ||
| /* { | ||
| data: { | ||
| title: "Hello World", | ||
| description: "Hello World example page for hono documentation", | ||
| nested: { | ||
| foo: "bar", | ||
| }, | ||
| }, | ||
| value: "<h2>Section A</h2>\n<p>Hello</p>", | ||
| } */ | ||
| ``` | ||
|
|
||
| ## 🔗 See Also | ||
| - https://github.com/remarkjs/remark | ||
| - https://github.com/rehypejs/rehype | ||
| - https://github.com/unifiedjs/unified | ||
| - https://jekyllrb.com/docs/front-matter/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you update
.vitepress/config.ts?website/.vitepress/config.ts
Line 233 in 55af01b
I think putting it into the
Integrationssection is proper.