UNPKG

@x-govuk/govuk-eleventy-plugin

Version:

Write documentation using Markdown and publish it using GOV.UK styles

70 lines (65 loc) 1.43 kB
import Nunjucks from 'nunjucks' /** * Creates a new tags template * * @class */ export class TagsTemplate { constructor(options) { this.title = options?.title || 'Tags' this.permalink = options?.permalink || '/tags/' } /** * Get template data for tags * * @returns {object} Template data */ data() { return { eleventyExcludeFromCollections: true, eleventyNavigation: { key: '_tags' }, layout: 'tags', title: this.title, permalink: this.permalink } } } /** * Creates a new tag template * * @class */ export class TagTemplate { constructor(options) { this.slugify = options?.slugify || ((string) => string) this.permalink = options?.permalink || '/tags/' this.caption = options?.title || 'Tags' this.title = (data) => Nunjucks.renderString( options?.tagTitle || 'Posts tagged ‘{{ tag }}’', data ) } /** * Get template data for tag * * @returns {object} Template data */ data() { return { eleventyExcludeFromCollections: true, eleventyNavigation: { parent: '_tags' }, eleventyComputed: { title: this.title }, layout: 'tag', caption: this.caption, pagination: { alias: 'tag', data: 'collections.tags', size: 1 }, permalink: (data) => `${this.permalink}${this.slugify(data.tag)}/` } } }