Skip to content

Commit 78451d1

Browse files
committed
chore: small improvements
1 parent 5ed5e40 commit 78451d1

File tree

5 files changed

+140
-3
lines changed

5 files changed

+140
-3
lines changed

README.md

Lines changed: 122 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
# Nuxt Compile Markdown
22

3-
43
[![npm version][npm-version-src]][npm-version-href]
54
[![npm downloads][npm-downloads-src]][npm-downloads-href]
65
[![License][license-src]][license-href]
76
[![Nuxt][nuxt-src]][nuxt-href]
87

9-
Nuxt Module to compile markdown files into Vue SFC at **build time**. This enables you to put `.md` files into your `pages` directory as standalone pages, and `.md` under `components` directory as Vue components. With components auto-import built-in in Nuxt, you can also use any components in your markdown files.
8+
Nuxt Module to compile markdown files into Vue SFC at **build time**. This enables you to put `.md` files into your `pages/` directory as standalone pages, and `.md` under `components/` directory as Vue components. With components auto-import built-in in Nuxt, you can also use any components in your markdown files.
9+
10+
- 📚 Write pages & components in Markdown
11+
- 💚 Use Vue components in Markdown.
12+
-
1013

1114
## Install
1215

@@ -33,11 +36,127 @@ export default defineNuxtConfig({
3336
})
3437
```
3538

39+
## Usage
40+
41+
Create your components or pages as Markdown:
42+
43+
```bash
44+
components/
45+
HelloWorld.md
46+
pages/
47+
about.md
48+
index.md
49+
```
50+
51+
## SEO & Page metas
52+
53+
54+
Use the `seo` property in the frontmatter to leverage [`useSeoMeta()`](https://nuxt.com/docs/api/composables/use-seo-meta):
55+
56+
```md
57+
---
58+
seo:
59+
title: My title
60+
description: My description
61+
ogImage: https://example.com/image.png
62+
twitterCard: summary_large_image
63+
---
64+
65+
# My page
66+
```
67+
68+
Will be transformed to:
69+
70+
```vue
71+
<script setup>
72+
useSeoMeta({
73+
title: 'My title',
74+
description: 'My description',
75+
ogImage: 'https://example.com/image.png',
76+
twitterCard: 'summary_large_image'
77+
})
78+
</script>
79+
80+
<-- template --->
81+
```
82+
83+
**Note:** Use `title` and `description` as shortcut for `seo.title` and `seo.description`
84+
85+
Use the `meta` property in the frontmatter to leverage [`definePageMeta()`](https://nuxt.com/docs/api/utils/define-page-meta#definepagemeta) for the `pages/` directory:
86+
87+
```md
88+
---
89+
meta:
90+
layout: dark
91+
middleware: log
92+
---
93+
94+
# My page
95+
```
96+
97+
Will be transformed to:
98+
99+
```vue
100+
<script setup>
101+
definePageMeta({
102+
layout: 'dark',
103+
middleware: 'log'
104+
})
105+
</script>
106+
107+
<-- template --->
108+
```
109+
110+
## Frontmatter
111+
112+
The frontmatter is parsed and injected into Vue's instance data frontmatter field.
113+
114+
```md
115+
---
116+
name: My Page
117+
---
118+
119+
# Hello World
120+
121+
This is {{ frontmatter.name }}
122+
```
123+
124+
## Import Markdown as Vue components
125+
126+
With Nuxt auto-import, all Markdown files inside the `components/` directory will be imported when used:
127+
128+
```
129+
components/
130+
HelloWorld.md
131+
pages/
132+
index.md
133+
```
134+
135+
Then in your `pages/index.md`:
136+
137+
```md
138+
I can use a Markdown component:
139+
140+
<HelloWorld />
141+
```
142+
143+
If the Markdown is not inside the `components/` directory, you can import it and use it as a normal Vue component:
144+
145+
```vue
146+
<script setup>
147+
import Readme from '../README.md'
148+
</script>
149+
150+
<template>
151+
<Readme />
152+
</template>
153+
```
154+
36155
## FAQ
37156

38157
### How does this compare to [@nuxt/content](https://content.nuxtjs.org/)?
39158

40-
159+
`nuxt-compile-markdown` works at built time and converts the Markdown files to Vue files for maximum performance. This module does not have the ability to query content like [Nuxt Content Query Builder](https://content.nuxtjs.org/guide/displaying/querying). Also `nuxt-compile-markdown` does not support the MDC syntax (for now).
41160

42161
<!-- Badges -->
43162
[npm-version-src]: https://img.shields.io/npm/v/nuxt-compile-markdown/latest.svg?style=flat&colorA=18181B&colorB=28CF8D

playground/nuxt.config.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
export default defineNuxtConfig({
22
modules: ['../src'],
33
devtools: { enabled: true },
4+
nitro: {
5+
prerender: {
6+
ignore: ['/redirect'],
7+
},
8+
},
49
// builder: 'webpack',
510
})

playground/pages/index.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ Nuxt Page as Markdown
99
- Go to [/blog](/blog)
1010
- Go to [/about](/about)
1111
- Go to [/dynamic/hello](/dynamic/hello)
12+
- Go to [/readme](/readme)
13+
- Go to [/redirect](/redirect)
1214

1315
---
1416

playground/pages/readme.vue

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<script setup>
2+
import Readme from '../../README.md'
3+
</script>
4+
5+
<template>
6+
<Readme />
7+
</template>

playground/pages/redirect.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
meta:
3+
redirect: /about
4+
---

0 commit comments

Comments
 (0)