Eleventy plugin to generate JSON-LD structured data.
Install the package:
npm install --save @quasibit/eleventy-plugin-schema
Add the plugin to your Eleventy configuration
(usually .eleventy.js
):
const schema = require("@quasibit/eleventy-plugin-schema");
module.exports = function(eleventyConfig) {
eleventyConfig.addPlugin(schema);
};
The plugin adds two shortcodes to generate the JSON-LD script:
-
jsonLdScript
(includes the<script>
tag) -
jsonLd
(just JSON-LD without the<script>
tag)
The shortcodes support the following schema types:
- WebSite.
- BlogPosting.
- WebPage.
- Product (thanks @christopherpickering).
- Organization (thanks @christopherpickering).
- Breadcrumbs (thanks @christopherpickering).
- SearchAction (thanks @christopherpickering).
- FAQPage (thanks @christopherpickering).
- Videos (thanks @christopherpickering).
Add data/front matter to your pages. Please refer to the files in demo. If you already have the value in other properties, you can use computed data to clone them.
Call the shortcode where you want the script to be displayed:
{% jsonLdScript meta, type, tags %}
And if you don't want the <script>
tag, then use this instead:
{% jsonLd meta, type, tags %}
You can validate the structured data using one of the following tools:
- @quasibit/eleventy-plugin-sitemap: generate a sitemap.
Special thanks to @christopherpickering.
MIT. See LICENSE.