Security News
38% of CISOs Fear They’re Not Moving Fast Enough on AI
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
@nuxtjs/content
Advanced tools
Write your content inside your Nuxt app
@nuxtjs/content
dependency to your projectyarn add @nuxtjs/content # or npm install @nuxtjs/content
@nuxtjs/content
to the modules
section of nuxt.config.js
{
modules: [
// Simple usage
'@nuxtjs/content'
]
}
Create a content/
directory in your Nuxt project:
content/
articles/
article-1.md
article-2.md
home.md
$content(DirectoryPath: string).fetch()
⇒ [{}]
$content(FilePath: string).fetch()
⇒ {}
content/home.md
----
title: Home page
---
# Home page
> Welcome to my *home page*!
$content('home').fetch()
{
"dir": "",
"slug": "home",
"path": "/home",
"updatedAt": "2017-11-07T12:21:34Z",
"metadata": {
"title": "Home page"
},
"body": {
"type": "root",
"children": [
{
"type": "heading",
"depth": 1,
"children": [
{
"type": "text",
"value": "Home page"
}
]
},
{
"type": "blockquote",
"children": [
{
"type": "paragraph",
"children": [
{
"type": "text",
"value": "Welcome to my ",
},
{
"type": "emphasis",
"children": [
{
"type": "text",
"value": "home page",
}
]
},
{
"type": "text",
"value": "!"
}
]
}
]
}
]
}
}
You can now use this.$content(path)
in your Vue components:
// Listing
const articles = await this.$content('articles')
.only(['title', 'date', 'authors'])
.sortBy('date', 'asc')
.limit(5)
.skip(10)
.where({
tags: 'testing',
isArchived: false,
date: { $gt: new Date(2020) },
rating: { $gte: 3 },
})
.search('welcome')
.fetch()
// Get previous and next article
const [ prev1, prev2, next1, next2, next3 ] = await this.$content('articles')
.only(['title', 'path'])
.sortBy('date')
.surround('article-2', { before: 2, after: 3 })
.where({ isArchived: false })
.fetch()
// Returns
[
null, // no article-0 here
{
title: 'Article 1',
path: 'article-1'
},
null, // no article-3 here
null, // no article-4 here
null // no article-5 here
]
// limit and offset are ineffective when using surround
// if slug is not found, will fill with null value each item
Code example
<template>
<article>
<h1>{{ page.title }}</h1>
<nuxt-content :body="page.body" />
</article>
</template>
<script>
export default {
data() {
page: null,
learn: null
},
fetch () {
this.page = await this.$content(`${this.i18n.locale}/guide/installation`).fetch()
this.learnSection = await this.$content(`${this.i18n.locale}/learn`)
.only(['title', 'metadata'])
.sortBy('updatedAt', 'desc')
}
}
</script>
Using global Vue component in Markdown is supported (see how nuxt press does).
// nuxt.config.js
export default {
modules: ['@nuxtjs/content'],
// Default options
content: {
apiPrefix: '_content', // http://localhost:3000/_content,
dir: 'content',
fullTextSearchFields: ['title', 'description', 'slug'],
markdown: {
// See https://github.com/remarkjs/remark-external-links#api
externalLinks: {},
prism: {
theme: 'prismjs/themes/prism.css'
}
},
yaml: {
// See https://github.com/nodeca/js-yaml
},
csv: {
// See https://github.com/Keyang/node-csvtojson
}
}
}
yarn install
or npm install
yarn dev
or npm run dev
Copyright (c) NuxtJS Company
FAQs
Write your content inside your Nuxt app
We found that @nuxtjs/content demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 7 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.
Security News
Company News
Socket is joining TC54 to help develop standards for software supply chain security, contributing to the evolution of SBOMs, CycloneDX, and Package URL specifications.