@nera-static/plugin-canonical-links
v2.0.1
Published
A plugin for Nera static site generator to create canonical links in to be used in the head.
Downloads
24
Maintainers
Readme
@nera-static/plugin-canonical-links
A plugin for the Nera static site generator to generate canonical and alternate <link> tags for SEO in the document <head>. Helps search engines correctly index content across domains and languages.
✨ Features
- Adds
<link rel="canonical">for SEO - Supports multilingual alternate links
- Easy Pug template integration
- Configurable origin and slug mapping
🚀 Installation
Install the plugin in the root of your Nera project:
npm install @nera-static/plugin-canonical-linksThen create a config file in your project’s config/ directory:
config/
└── canonical-links.yamlNera will automatically detect the plugin and apply it during the build.
⚙️ Configuration
Create config/canonical-links.yaml:
app_origin: https://your-domain.com
page_identifier: slug
available_languages:
- en
- es
- frapp_origin: The canonical base URL (overridesapp.origin).page_identifier: Shared key to match localized versions (defaults toslug).available_languages: List of supported language codes (used to create alternate links).
📄 Usage in Templates
Include the plugin’s view in your layout head:
head
include /node_modules/@nera-static/plugin-canonical-links/views/indexThis will generate:
<link href="https://example.com/index.html" rel="canonical" />
<link href="https://example.com/es/index.html" hreflang="es" rel="alternate" />
<link href="https://example.com/fr/index.html" hreflang="fr" rel="alternate" />🗂️ Content Structure
To use alternate links, provide a shared identifier (e.g., slug) across translations:
pages/
├── index.md
├── es/
│ └── index.md
└── fr/
└── index.mdExample frontmatter for each:
pages/index.md
lang: en
slug: homepages/es/index.md
lang: es
slug: homepages/fr/index.md
lang: fr
slug: home🧩 Rendering Details
The plugin provides a view file that includes two partials:
views/index.puginclude partials/canonical-link include partials/alternate-linksviews/partials/canonical-link.pugif (meta.canonicalLink) link(href=meta.canonicalLink.href, rel=meta.canonicalLink.rel)views/partials/alternate-links.pugif (meta.alternateLinks && meta.alternateLinks.length > 0) each alternate in meta.alternateLinks link(href=alternate.href, hreflang=alternate.hreflang, rel=alternate.rel)
You can copy or customize these templates for full control.
🧪 Development
npm install
npm run testIncludes unit and integration tests using Vitest and Pug.
🧑💻 Author
Michael Becker
https://github.com/seebaermichi
🔗 Links
� Compatibility
- Nera: v4.1.0+
- Node.js: >= 18
- Plugin API: Uses
getMetaData()for optimal performance
�📦 License
MIT
