+
+
+
+
+
diff --git a/docs/content/en/advanced.md b/docs/content/en/advanced.md
index 73a50f99c..441f87bc5 100644
--- a/docs/content/en/advanced.md
+++ b/docs/content/en/advanced.md
@@ -73,7 +73,7 @@ The module adds some hooks you can use:
Allows you to modify the contents of a file before it is handled by the parsers.
Arguments:
-- `data`
+- `file`
- Type: `Object`
- Properties:
- path: `String`
@@ -147,6 +147,31 @@ export default {
}
```
+### `content:options`
+
+Extend the content options, useful for modules that wants to read content options when normalized and apply updated to it.
+
+Arguments:
+- `options`
+ - Type: `Object`
+ - Properties:
+ - See [configuration](/configuration#properties)
+
+**Example**
+
+```js{}[nuxt.config.js]
+export default {
+ modules: [,
+ '@nuxt/content'
+ ],
+ hooks: {
+ 'content:options': (options) => {
+ console.log('Content options:', options)
+ }
+ }
+}
+```
+
## Handling Hot Reload
diff --git a/docs/content/en/configuration.md b/docs/content/en/configuration.md
index 21054ac11..c07695f0a 100644
--- a/docs/content/en/configuration.md
+++ b/docs/content/en/configuration.md
@@ -213,6 +213,14 @@ export default {
}
```
+### `markdown.tocDepth`
+
+- Type: `Number`
+- Default: `3`
+- Version: **>= v1.11.0**
+
+You can change maximum heading depth to include in the table of contents.
+
### `markdown.remarkPlugins`
- Type: `Array`
diff --git a/docs/content/en/displaying.md b/docs/content/en/displaying.md
index 6b18d1658..ab3a71ba5 100644
--- a/docs/content/en/displaying.md
+++ b/docs/content/en/displaying.md
@@ -52,7 +52,7 @@ Depending on what you're using to design your app, you may need to write some st
}
```
-You can find an example in the [docs directory](https://github.com/nuxt/content/blob/master/docs/pages/_slug.vue).
+> You can find an example in the theme-docs [main.css](https://github.com/nuxt/content/blob/master/packages/theme-docs/src/assets/css/main.css) file. You can also take a look at the [TailwindCSS Typography plugin](https://tailwindcss.com/docs/typography-plugin) to style your markdown content like we do in the `@nuxt/content-theme-docs`.
## Live Editing
diff --git a/docs/content/en/fetching.md b/docs/content/en/fetching.md
index f071570a0..67a43f306 100644
--- a/docs/content/en/fetching.md
+++ b/docs/content/en/fetching.md
@@ -206,9 +206,9 @@ Check out [this snippet](/snippets#prev-and-next) on how to implement prev and n
Ends the chain sequence and collects data.
-## Catch()
+### catch()
-Checks if the `.md` file is exist in content directory or not.
+Checks if the `.md` file exists in content directory or not.
It should be inserted after the `fetch()`.
diff --git a/docs/content/en/themes/docs.md b/docs/content/en/themes/docs.md
index 0a86d7b44..4f6ace562 100644
--- a/docs/content/en/themes/docs.md
+++ b/docs/content/en/themes/docs.md
@@ -6,7 +6,24 @@ description: 'Create your documentation with @nuxt/content docs theme in seconds
category: Themes
position: 8
version: 1.2
-badge: 'v0.7.0'
+badge: 'v0.7.1'
+showcases:
+ - https://strapi.nuxtjs.org
+ - https://tailwindcss.nuxtjs.org
+ - https://storybook.nuxtjs.org
+ - https://firebase.nuxtjs.org
+ - https://pwa.nuxtjs.org
+ - https://image.nuxtjs.org
+ - https://http.nuxtjs.org
+ - https://cloudinary.nuxtjs.org
+ - https://i18n.nuxtjs.org
+ - https://snipcart.nuxtjs.org
+ - https://prismic.nuxtjs.org
+ - https://google-analytics.nuxtjs.org
+ - https://color-mode.nuxtjs.org
+ - https://mdx.nuxtjs.org
+ - https://sanity.nuxtjs.org
+ - https://speedcurve.nuxtjs.org
---
@@ -176,7 +193,9 @@ Don't forget to install the dependencies of the modules you add in your `nuxt.co
You can override the [default theme config](https://github.com/nuxt/content/blob/dev/packages/theme-docs/src/tailwind.config.js) by creating your own `tailwind.config.js`.
-The theme design is based on a `primary` color to make it easy to override. Default colors are generated using [theme-colors](https://github.com/nuxt-contrib/theme-colors) with `docs.primaryColor` as base.
+The theme design is based on a `primary` color to make it easy to override.
+
+> Default colors are generated using [theme-colors](https://github.com/nuxt-contrib/theme-colors) with `docs.primaryColor` as base. v0.7.0+
**Example**
@@ -449,11 +468,11 @@ Check out an info alert with a `codeblock` and a [link](/themes/docs)!
- `items`
- Type: `Array`
- Default: `[]`
-- `type`
+- `type` v0.7.0+
- Type: `String`
- Default: `'primary'`
- Values: `['primary', 'info', 'success', 'warning', 'danger']`
-- `icon`
+- `icon` v0.7.0+
- Type: `String`
- *Can be used to override the default `type` icon, check out the [icons available](https://github.com/nuxt/content/tree/dev/packages/theme-docs/src/components/global/icons)*
@@ -570,47 +589,4 @@ link: https://codesandbox.io/embed/nuxt-content-l164h?hidenavigation=1&theme=dar
## Showcases
-
+
diff --git a/docs/content/en/writing.md b/docs/content/en/writing.md
index d86ad9946..b29bd7362 100644
--- a/docs/content/en/writing.md
+++ b/docs/content/en/writing.md
@@ -51,6 +51,46 @@ description: Learn how to use @nuxt/content.
These variables will be injected into the document:
+```json
+{
+ body: Object
+ excerpt: Object
+ title: "Introduction"
+ description: "Learn how to use @nuxt/content."
+ dir: "/"
+ extension: ".md"
+ path: "/index"
+ slug: "index"
+ toc: Array
+ createdAt: DateTime
+ updatedAt: DateTime
+}
+```
+
+### Excerpt
+
+Content excerpt or summary can be extracted from the content using `` as a divider.
+
+```md
+---
+title: Introduction
+---
+
+Learn how to use @nuxt/content.
+
+Full amount of content beyond the more divider.
+```
+
+Description property will contain the excerpt content unless defined within the Front Matter props.
+
+
+
+Be careful to enter <!--more--> exactly; i.e., all lowercase and with no whitespace.
+
+
+
+Example variables will be injected into the document:
+
```json
{
body: Object
@@ -620,4 +660,4 @@ Will be transformed into:
"title": "Home",
"description": "Welcome!"
}
-```
\ No newline at end of file
+```
diff --git a/docs/content/fr/advanced.md b/docs/content/fr/advanced.md
index 07d8588f6..c54f1aaf9 100644
--- a/docs/content/fr/advanced.md
+++ b/docs/content/fr/advanced.md
@@ -71,7 +71,7 @@ Arguments:
- `document`
- Type: `Object`
- Propriétés:
- - Voir [écrire du contenu](/writing)
+ - Voir [écrire du contenu](/fr/writing)
**Exemple**
diff --git a/docs/content/fr/configuration.md b/docs/content/fr/configuration.md
index 18f5e5a08..c019c0bd5 100644
--- a/docs/content/fr/configuration.md
+++ b/docs/content/fr/configuration.md
@@ -51,7 +51,7 @@ content: {
- Type: `Array`
- Défaut: `['title', 'description', 'slug', 'text']`
-Les champs qui ont besoin d'être indexés afin d'être recherchables, vous pouvez en apprendre plus sur les recherches [ici](/fetching#searchfield-value).
+Les champs qui ont besoin d'être indexés afin d'être recherchables, vous pouvez en apprendre plus sur les recherches [ici](/fr/fetching#searchfield-value).
`text` est une propriété spéciale qui contient votre Markdown avant qu'il soit converti en AST.
diff --git a/docs/content/fr/displaying.md b/docs/content/fr/displaying.md
index 5e0467fe0..4acf9a969 100644
--- a/docs/content/fr/displaying.md
+++ b/docs/content/fr/displaying.md
@@ -38,7 +38,7 @@ export default {
- Type: `Object`
- `requis`
-Vous pouvez en apprendre davantage au sujet de ce que vous pouvez écrire dans vos fichiers Markdown dans la section [écrire du contenu](/writing#markdown).
+Vous pouvez en apprendre davantage au sujet de ce que vous pouvez écrire dans vos fichiers Markdown dans la section [écrire du contenu](/fr/writing#markdown).
## Style
diff --git a/docs/content/fr/fetching.md b/docs/content/fr/fetching.md
index c6e246115..42568e967 100644
--- a/docs/content/fr/fetching.md
+++ b/docs/content/fr/fetching.md
@@ -75,7 +75,7 @@ const articles = await this.$content('articles').where({ age: { $gt: 18 } }).fet
const articles = await this.$content('articles').where({ name: { $in: ['odin', 'thor'] } }).fetch()
```
-Pour filtrer des objets et des tableaux, vous devez configurer la propritété `nestedProperties`, voir la partie [configuration](/configuration#nestedproperties).
+Pour filtrer des objets et des tableaux, vous devez configurer la propritété `nestedProperties`, voir la partie [configuration](/fr/configuration#nestedproperties).
```js
const produits = await this.$content('produits').where({ 'categories.slug': { $contains: 'haut' } }).fetch()
@@ -139,7 +139,7 @@ const articles = await this.$content('articles').skip(5).limit(5).fetch()
Effectue une recherche plein texte sur un champ. Le paramètre `value` est optionnel, dans ce cas `field` devient la `value` et la recherche est alors effectuée sur tous les champs définis en tant que champ de recherche plein texte.
-Le champ sur lequel vous voulez effectuer la recherche doit être défini dans les options afin d'être indexé, voir [configuration](/configuration#fulltextsearchfields).
+Le champ sur lequel vous voulez effectuer la recherche doit être défini dans les options afin d'être indexé, voir [configuration](/fr/configuration#fulltextsearchfields).
```js
// Search on field title
@@ -207,7 +207,7 @@ const articles = await this.$content('articles')
## API
-Lorsque vous développez, ce module expose une API qui vous permet facilement de consulter les données de chaque répertoire ou fichier au format JSON, à l'adresse http://localhost:3000/_content/. Par défaut, le préfixe est `_content` mais il peut être configuré à l'aide la la propriété [apiPrefix](/configuration#apiprefix).
+Lorsque vous développez, ce module expose une API qui vous permet facilement de consulter les données de chaque répertoire ou fichier au format JSON, à l'adresse http://localhost:3000/_content/. Par défaut, le préfixe est `_content` mais il peut être configuré à l'aide la la propriété [apiPrefix](/fr/configuration#apiprefix).
Exemple:
diff --git a/docs/content/fr/writing.md b/docs/content/fr/writing.md
index 10a108df2..81c88de69 100644
--- a/docs/content/fr/writing.md
+++ b/docs/content/fr/writing.md
@@ -32,7 +32,7 @@ Ce module analysera les fichiers `.md`, `.yaml`, `.csv`, `.json`, `.json5` et g
Ce module convertit vos fichiers `.md` en une arborescence JSON AST, stockée dans une variable `body`.
-Assurez-vous d'utiliser le composant `` afin d'afficher le `body` de votre contenu Markdown, voir [afficher du contenu](/displaying).
+Assurez-vous d'utiliser le composant `` afin d'afficher le `body` de votre contenu Markdown, voir [afficher du contenu](/fr/displaying).
> Vous pouvez consulter le [guide syntaxique de base](https://www.markdownguide.org/basic-syntax) pour apprendre à maîtriser le Markdown.
@@ -64,6 +64,43 @@ Ces variables seront injectées au sein du document:
}
```
+### Extrait
+
+L'extrait ou le résumé du contenu peut être extrait du contenu en utilisant `` comme diviseur.
+
+```md
+---
+title: Introduction
+---
+
+Apprenez comment utiliser @nuxt/content.
+
+Quantité totale de contenu au-delà du plus diviseur.
+```
+
+La propriété Description contiendra le contenu de l'extrait à moins qu'elle ne soit définie dans les accessoires Front Matter.
+
+
+
+Veillez à saisir exactement <!--more-->; c'est-à-dire, tout en minuscules et sans espace.
+
+
+Des exemples de variables seront injectés dans le document:
+```json
+{
+ body: Object
+ title: "Introduction"
+ description: "Apprenez comment utiliser @nuxt/content."
+ dir: "/"
+ extension: ".md"
+ path: "/index"
+ slug: "index"
+ toc: Array
+ createdAt: DateTime
+ updatedAt: DateTime
+}
+```
+
### Titres
Ce module associe automatiquement un `id` et un `lien` à chaque titre.
@@ -92,7 +129,7 @@ Il sera transformé en une structure JSON AST, et en utilisant le composant `nux
### Liens
-Les liens sont transformés afin d'y ajouter des attributs `target` et `rel` valides. Vous pouvez modifier ce comportement, voir [configuration](/configuration#markdownexternallinks). Les liens relatifs sont eux aussi transformés automatiquement en `nuxt-link` afin d'apporter une navigation entre pages plus performante à l'aide du smart prefetching.
+Les liens sont transformés afin d'y ajouter des attributs `target` et `rel` valides. Vous pouvez modifier ce comportement, voir [configuration](/fr/configuration#markdownexternallinks). Les liens relatifs sont eux aussi transformés automatiquement en `nuxt-link` afin d'apporter une navigation entre pages plus performante à l'aide du smart prefetching.
Voici un exemple illustrant l'utilisation de liens externes et relatifs, en utilisant les syntaxes Markdown et HTML:
@@ -107,7 +144,7 @@ title: Accueil
Lien Html vers le Blog
-[Lien Markdown vers le Blog](/articles)
+[Lien Markdown vers le Blog](/fr/articles)
Lien Html externe
@@ -138,7 +175,7 @@ Voici une note de bas de page basique,[^1] et en voici une longue.[^bignote]
### Blocs de code
-Ce module enveloppe automatiquement les blocs de code et leur applique des classes propres à [PrismJS](https://prismjs.com) (voir [coloration syntaxique](/writing#syntax-highlighting)).
+Ce module enveloppe automatiquement les blocs de code et leur applique des classes propres à [PrismJS](https://prismjs.com) (voir [coloration syntaxique](/fr/writing#syntax-highlighting)).
Dans du Markdown, les blocs de code sont entourés de 3 backticks. Vous pouvez éventuellement définir le langage du bloc de code pour activer la coloration syntaxique associée.
@@ -177,7 +214,7 @@ Voici le résultat après que le composant `nuxt-content` ait généré le rendu
### Coloration syntaxique
-La coloration syntaxique est prise en charge par défaut grâce à [PrismJS](https://prismjs.com), en injectant le thème défini dans les options de votre application Nuxt.js, voir [configuration](/configuration#markdownprismtheme).
+La coloration syntaxique est prise en charge par défaut grâce à [PrismJS](https://prismjs.com), en injectant le thème défini dans les options de votre application Nuxt.js, voir [configuration](/fr/configuration#markdownprismtheme).
### HTML
@@ -279,7 +316,7 @@ multiselectOptions:
-Ces composants seront rendus en utilisant le composant ``, voir [afficher du contenu](/displaying#component).
+Ces composants seront rendus en utilisant le composant ``, voir [afficher du contenu](/fr/displaying#component).
@@ -362,9 +399,9 @@ Sera transformé en:
}
```
-En interne, nous associons une clé `text` avec le corps du Markdown afin de pouvoir l'utiliser pour la [recherche](/fetching#searchfield-value) ou pour créer des [hooks](/advanced#contentfilebeforeinsert).
+En interne, nous associons une clé `text` avec le corps du Markdown afin de pouvoir l'utiliser pour la [recherche](/fr/fetching#searchfield-value) ou pour créer des [hooks](/fr/advanced#contentfilebeforeinsert).
-Vous pouvez découvrir la façon d'afficher du Markdown au sein de vos applications dans la section [afficher du contenu](/displaying).
+Vous pouvez découvrir la façon d'afficher du Markdown au sein de vos applications dans la section [afficher du contenu](/fr/displaying).
## CSV
diff --git a/docs/content/ja/writing.md b/docs/content/ja/writing.md
index f0583fc4f..b6127af75 100644
--- a/docs/content/ja/writing.md
+++ b/docs/content/ja/writing.md
@@ -64,6 +64,43 @@ description: Learn how to use @nuxt/content.
}
```
+### 抜粋
+
+コンテンツの抜粋または要約は、``を仕切りとして使用してコンテンツから抽出できます。
+
+```md
+---
+title: Introduction
+---
+
+@nuxt/contentの使用方法を学びます。
+
+より多くの仕切りを超えたコンテンツの全量。
+```
+
+Description プロパティには、フロントマター プロップ内で定義されていない限り、抜粋コンテンツが含まれます。
+
+
+
+<!--more--> を正確に入力するように注意してください。 つまり、すべて小文字で、空白はありません。
+
+
+変数の例がドキュメントに挿入されます。
+```json
+{
+ body: Object
+ title: "Introduction"
+ description: "@nuxt/contentの使用方法を学びます。"
+ dir: "/"
+ extension: ".md"
+ path: "/index"
+ slug: "index"
+ toc: Array
+ createdAt: DateTime
+ updatedAt: DateTime
+}
+```
+
### 見出し
このモジュールは自動的に`id`と`link`を各見出しに追加します。
diff --git a/docs/content/ru/writing.md b/docs/content/ru/writing.md
index 55a95a216..ac51cc991 100644
--- a/docs/content/ru/writing.md
+++ b/docs/content/ru/writing.md
@@ -64,6 +64,43 @@ description: Изучите как использовать @nuxt/content.
}
```
+### отрывок
+
+Отрывок или резюме содержания можно извлечь из содержания, используя `` в качестве разделителя.
+
+```md
+---
+title: Вступление
+---
+
+Изучите как использовать @nuxt/content.
+
+Полный объем содержимого за пределами разделителя more.
+```
+
+Свойство Description будет содержать содержимое отрывка, если оно не определено в свойствах Front Matter.
+
+
+
+Будьте внимательны при вводе <!--more--> точно; т.е. все строчные и без пробелов.
+
+
+Пример переменных будет вставлен в документ:
+```json
+{
+ body: Object
+ title: "Вступление"
+ description: "Изучите как использовать @nuxt/content."
+ dir: "/"
+ extension: ".md"
+ path: "/index"
+ slug: "index"
+ toc: Array
+ createdAt: DateTime
+ updatedAt: DateTime
+}
+```
+
### Заголовки
Этот модуль автоматически добавит `id` и `link` к каждому заголовку.
diff --git a/docs/package.json b/docs/package.json
index 4e4259517..398b5ba82 100644
--- a/docs/package.json
+++ b/docs/package.json
@@ -11,8 +11,8 @@
"generate": "nuxt generate"
},
"dependencies": {
- "@nuxt/content-theme-docs": "^0.6.1",
- "nuxt": "^2.14.6",
+ "@nuxt/content-theme-docs": "^0.7.2",
+ "nuxt": "^2.14.7",
"nuxt-ackee": "^2.0.0",
"vue-multiselect": "^2.1.6"
}
diff --git a/example/content/articles/2020/04/excerpt.md b/example/content/articles/2020/04/excerpt.md
new file mode 100644
index 000000000..a67410214
--- /dev/null
+++ b/example/content/articles/2020/04/excerpt.md
@@ -0,0 +1,17 @@
+---
+title: "Excerpt example hello world"
+date: 2020-10-28
+# description: "hello world, description"
+---
+
+
+### aheraasdf lasdf
+
+
+as
+this is the summary
+
+
+
+
+this is full content
diff --git a/example/pages/articles/_year/_month/_slug.vue b/example/pages/articles/_year/_month/_slug.vue
index 67d47ccff..31f17ff46 100644
--- a/example/pages/articles/_year/_month/_slug.vue
+++ b/example/pages/articles/_year/_month/_slug.vue
@@ -22,6 +22,13 @@ export default {
return {
article
}
+ },
+ head () {
+ return {
+ meta: [
+ { name: 'description', content: this.article.description }
+ ]
+ }
}
}
diff --git a/example/pages/articles/_year/_month/index.vue b/example/pages/articles/_year/_month/index.vue
index 005afe73a..9b7c08b20 100644
--- a/example/pages/articles/_year/_month/index.vue
+++ b/example/pages/articles/_year/_month/index.vue
@@ -13,7 +13,6 @@
diff --git a/example/pages/articles/index.vue b/example/pages/articles/index.vue
index a9a6b6ab6..c2a336963 100644
--- a/example/pages/articles/index.vue
+++ b/example/pages/articles/index.vue
@@ -15,7 +15,6 @@
diff --git a/example/pages/products/index.vue b/example/pages/products/index.vue
index e45d370ae..83b889265 100644
--- a/example/pages/products/index.vue
+++ b/example/pages/products/index.vue
@@ -14,7 +14,6 @@
diff --git a/package.json b/package.json
index de30b1a96..3960f1475 100755
--- a/package.json
+++ b/package.json
@@ -25,24 +25,24 @@
"test:packages:create-nuxt-content-docs": "jest packages/create-nuxt-content-docs"
},
"devDependencies": {
- "@babel/core": "^7.11.6",
- "@babel/preset-env": "^7.11.5",
- "@nuxtjs/eslint-config": "^3.1.0",
+ "@babel/core": "^7.12.3",
+ "@babel/preset-env": "^7.12.1",
+ "@nuxtjs/eslint-config": "^5.0.0",
"@nuxt/typescript-build": "^2.0.3",
"@nuxt/typescript-runtime": "^2.0.0",
- "@nuxtjs/eslint-config-typescript": "^3.0.0",
+ "@nuxtjs/eslint-config-typescript": "^5.0.0",
"@nuxtjs/module-test-utils": "^1.6.3",
"babel-eslint": "^10.1.0",
- "babel-jest": "^26.5.2",
- "codecov": "^3.8.0",
- "eslint": "^7.11.0",
- "highlight.js": "^10.2.1",
+ "babel-jest": "^26.6.3",
+ "codecov": "^3.8.1",
+ "eslint": "^7.13.0",
+ "highlight.js": "^10.4.0",
"husky": "^4.3.0",
- "jest": "^26.5.3",
+ "jest": "^26.6.3",
"lerna": "^3.22.1",
- "nuxt": "^2.14.6",
- "puppeteer": "^5.3.1",
- "shiki": "^0.2.6",
+ "nuxt": "^2.14.7",
+ "puppeteer": "^5.5.0",
+ "shiki": "^0.2.7",
"shiki-twoslash": "^0.8.1",
"tib": "^0.7.4"
}
diff --git a/packages/content/CHANGELOG.md b/packages/content/CHANGELOG.md
index 7d8457276..52be80a9c 100644
--- a/packages/content/CHANGELOG.md
+++ b/packages/content/CHANGELOG.md
@@ -3,6 +3,26 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
+# [1.11.0](https://github.com/nuxt/content/compare/@nuxt/content@1.10.0...@nuxt/content@1.11.0) (2020-11-19)
+
+
+### Bug Fixes
+
+* **content:** add missing types ([#625](https://github.com/nuxt/content/issues/625)) ([43e5a81](https://github.com/nuxt/content/commit/43e5a819e55fa65b3b9ffc0610e3a2206a356e48))
+* **content:** update highlighter spec ([8108f84](https://github.com/nuxt/content/commit/8108f84bf94727d7cb9d786c775e0b9c502d4d0f))
+* set header to empty string if undefined ([#620](https://github.com/nuxt/content/issues/620)) ([5bffdf1](https://github.com/nuxt/content/commit/5bffdf11d5b499829fcb389db29c9c0f316be3ac)), closes [#136](https://github.com/nuxt/content/issues/136)
+* **content:** support space after codeblock for filename ([#621](https://github.com/nuxt/content/issues/621)) ([9d900ff](https://github.com/nuxt/content/commit/9d900ff648c96aa0454986819cb31b374b451ecc))
+
+
+### Features
+
+* support dynamic table of contents ([#600](https://github.com/nuxt/content/issues/600)) ([5cf18c4](https://github.com/nuxt/content/commit/5cf18c41b3b383a4989db5eae775feb9ddf409d0))
+* **lib:** support markdown excerpt ([#607](https://github.com/nuxt/content/issues/607)) ([b453ea8](https://github.com/nuxt/content/commit/b453ea8e22258a664de93ec29c71229b17bf9fd1))
+
+
+
+
+
# [1.10.0](https://github.com/nuxt/content/compare/@nuxt/content@1.9.0...@nuxt/content@1.10.0) (2020-10-12)
diff --git a/packages/content/lib/index.js b/packages/content/lib/index.js
index 899e57eaf..fbc50fadd 100644
--- a/packages/content/lib/index.js
+++ b/packages/content/lib/index.js
@@ -55,7 +55,6 @@ module.exports = async function (moduleOptions) {
const relativeDir = options.dir
options.dir = resolve(this.options.srcDir, options.dir)
- // Load markdown plugins
processMarkdownOptions(options, this.nuxt.resolver.resolvePath)
options.apiPrefixWithBase = options.apiPrefix
@@ -69,6 +68,8 @@ module.exports = async function (moduleOptions) {
options.apiPrefixWithBase = baseRouter + options.apiPrefix
}
+ nuxt.callHook('content:options', options)
+
// Nuxt hooks
const globalComponents = resolve(this.options.srcDir, 'components/global')
const dirStat = await fs.stat(globalComponents).catch(() => null)
diff --git a/packages/content/lib/utils.js b/packages/content/lib/utils.js
index 374b07f03..c6253d280 100644
--- a/packages/content/lib/utils.js
+++ b/packages/content/lib/utils.js
@@ -10,6 +10,7 @@ const getDefaults = ({ dev = false } = {}) => ({
fullTextSearchFields: ['title', 'description', 'slug', 'text'],
nestedProperties: [],
markdown: {
+ tocDepth: 3,
remarkPlugins: [
'remark-squeeze-paragraphs',
'remark-slug',
@@ -32,6 +33,26 @@ const getDefaults = ({ dev = false } = {}) => ({
extendParser: {}
})
+const processMarkdownTocDepth = (markdown) => {
+ const { tocDepth } = markdown
+ const tocTags = []
+
+ if (tocDepth < 1) {
+ logger.info(`content.markdown.tocDepth is set as ${tocDepth}. Table of contents of markdown files will be empty.`)
+ return tocTags
+ }
+
+ if (tocDepth > 6) {
+ logger.info(`content.markdown.tocDepth is set as ${tocDepth}. Table of contents of markdown files will include all the headings.`)
+ }
+
+ for (let i = 2; i <= tocDepth; i++) {
+ tocTags.push(`h${i}`)
+ }
+
+ return tocTags
+}
+
const processMarkdownPlugins = (type, markdown, resolvePath) => {
const plugins = []
@@ -63,6 +84,7 @@ const processMarkdownOptions = (options, resolvePath) => {
if (!resolvePath) {
resolvePath = path => path
}
+ options.markdown.tocTags = processMarkdownTocDepth(options.markdown)
options.markdown.remarkPlugins = processMarkdownPlugins('remark', options.markdown, resolvePath)
options.markdown.rehypePlugins = processMarkdownPlugins('rehype', options.markdown, resolvePath)
}
diff --git a/packages/content/lib/ws.js b/packages/content/lib/ws.js
index a73f386a3..fa5fbafe1 100644
--- a/packages/content/lib/ws.js
+++ b/packages/content/lib/ws.js
@@ -17,7 +17,7 @@ class WS extends Hookable {
this.handleUpgrade(req, req.socket, undefined)
}
- handleUpgrade (request, socket, head) {
+ handleUpgrade (request, socket, head = '') {
return this.wss.handleUpgrade(request, socket, head, (client) => {
this.wss.emit('connection', client, request)
})
diff --git a/packages/content/package.json b/packages/content/package.json
index a3201e156..4911ac639 100644
--- a/packages/content/package.json
+++ b/packages/content/package.json
@@ -1,6 +1,6 @@
{
"name": "@nuxt/content",
- "version": "1.10.0",
+ "version": "1.11.0",
"repository": "nuxt/content",
"license": "MIT",
"types": "types/index.d.ts",
@@ -14,42 +14,42 @@
"dependencies": {
"@lokidb/full-text-search": "^2.1.0",
"@lokidb/loki": "^2.1.0",
- "@nuxt/types": "^2.14.6",
+ "@nuxt/types": "^2.14.7",
"@types/js-yaml": "^3.12.5",
- "@types/xml2js": "^0.4.5",
+ "@types/xml2js": "^0.4.7",
"change-case": "^4.1.1",
- "chokidar": "^3.4.2",
+ "chokidar": "^3.4.3",
"consola": "^2.15.0",
"csvtojson": "^2.0.10",
- "defu": "^3.1.0",
- "detab": "^2.0.3",
+ "defu": "^3.2.2",
+ "detab": "^2.0.4",
"escape-html": "^1.0.3",
"graceful-fs": "^4.2.4",
"gray-matter": "^4.0.2",
"hasha": "^5.2.2",
- "hookable": "^4.1.2",
+ "hookable": "^4.3.1",
"html-tags": "^3.1.0",
"js-yaml": "3.14.0",
- "mdast-util-to-hast": "^10.0.0",
+ "mdast-util-to-hast": "^10.0.1",
"mkdirp": "^1.0.4",
"node-req": "^2.1.2",
"node-res": "^5.0.1",
"p-queue": "6.6.2",
"prismjs": "^1.22.0",
- "property-information": "^5.5.0",
+ "property-information": "^5.6.0",
"rehype-raw": "^5.0.0",
"rehype-sort-attribute-values": "^3.0.2",
"rehype-sort-attributes": "^3.0.2",
"remark-autolink-headings": "^6.0.1",
"remark-external-links": "^8.0.0",
"remark-footnotes": "^3.0.0",
- "remark-parse": "^8.0.3",
+ "remark-parse": "^9.0.0",
"remark-rehype": "^8.0.0",
"remark-slug": "^6.0.0",
"remark-squeeze-paragraphs": "^4.0.0",
"unified": "^9.2.0",
"unist-builder": "^2.0.3",
- "ws": "^7.3.1",
+ "ws": "^7.4.0",
"xml2js": "^0.4.23"
},
"publishConfig": {
diff --git a/packages/content/parsers/markdown/handlers/code.js b/packages/content/parsers/markdown/handlers/code.js
index f6b73be57..e6f20b3d2 100644
--- a/packages/content/parsers/markdown/handlers/code.js
+++ b/packages/content/parsers/markdown/handlers/code.js
@@ -56,7 +56,8 @@ const toAst = (h, node) => (highlighted) => {
}
module.exports = highlighter => (h, node) => {
- const { language, lineHighlights, fileName } = parseThematicBlock(node.lang)
+ const lang = node.lang + (node.meta || '')
+ const { language, lineHighlights, fileName } = parseThematicBlock(lang)
const code = node.value ? detab(node.value + '\n') : ''
if (!highlighter) {
diff --git a/packages/content/parsers/markdown/index.js b/packages/content/parsers/markdown/index.js
index 9c2598dcc..a1e494e3a 100644
--- a/packages/content/parsers/markdown/index.js
+++ b/packages/content/parsers/markdown/index.js
@@ -35,13 +35,17 @@ class Markdown {
* @returns {array} List of headers
*/
generateToc (body) {
- // Returns only h2 and h3 from body root children
- return body.children.filter(node => ['h2', 'h3'].includes(node.tag)).map((node) => {
+ const { tocTags } = this.options
+
+ return body.children.filter(node => tocTags.includes(node.tag)).map((node) => {
const id = node.props.id
const depth = ({
h2: 2,
- h3: 3
+ h3: 3,
+ h4: 4,
+ h5: 5,
+ h6: 6
})[node.tag]
const text = this.flattenNodeText(node)
@@ -87,24 +91,42 @@ class Markdown {
})
}
+ /**
+ * Generate text excerpt summary
+ * @param {string} excerptContent - JSON AST generated from excerpt markdown.
+ * @returns {string} concatinated excerpt
+ */
+ generateDescription (excerptContent) {
+ return this.flattenNodeText(excerptContent)
+ }
+
/**
* Converts markdown document to it's JSON structure.
* @param {string} file - Markdown file
* @return {Object}
*/
async toJSON (file) {
- const { data, content } = matter(file)
+ const { data, content, ...rest } = matter(file, { excerpt: true, excerpt_separator: '' })
// Compile markdown from file content to JSON
const body = await this.generateBody(content)
// Generate toc from body
const toc = this.generateToc(body)
+ let excerpt
+ let description
+ if (rest.excerpt) {
+ excerpt = await this.generateBody(rest.excerpt)
+ description = this.generateDescription(excerpt)
+ }
+
return {
+ description,
...data,
toc,
body,
- text: content
+ text: content,
+ excerpt
}
}
}
diff --git a/packages/content/templates/nuxt-content.js b/packages/content/templates/nuxt-content.js
index b2bfcfaf0..f7cf1b9fc 100644
--- a/packages/content/templates/nuxt-content.js
+++ b/packages/content/templates/nuxt-content.js
@@ -94,7 +94,7 @@ function isTemplate (node) {
function getSlotName (node) {
let name = ''
for (const propName of Object.keys(node.props)) {
- if (!propName.startsWith('#') && !propName.startsWith('v-slot:')) { return }
+ if (!propName.startsWith('#') && !propName.startsWith('v-slot:')) { continue }
name = propName.split(/[:#]/, 2)[1]
break
}
diff --git a/packages/content/test/component.test.js b/packages/content/test/component.test.js
index 69677c4d5..347ba5776 100644
--- a/packages/content/test/component.test.js
+++ b/packages/content/test/component.test.js
@@ -42,6 +42,7 @@ describe('component', () => {
const html = await page.getHtml()
expect(html).toMatch(
+ // eslint-disable-next-line prefer-regex-literals
new RegExp(/