Skip to content

Commit

Permalink
Prefer Marked slugger instance to slugger
Browse files Browse the repository at this point in the history
Use the filter name `slugify` to match GOV.UK Frontend
  • Loading branch information
colinrotherham committed Aug 7, 2023
1 parent 59f5347 commit a1cfc85
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 17 deletions.
5 changes: 2 additions & 3 deletions lib/get-macro-options/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const { dirname, join } = require('path')

const { marked } = require('marked')
const slugger = require('slugger')
const { Slugger, marked } = require('marked')

// Get reference to marked.js
const renderer = new marked.Renderer()
Expand All @@ -20,7 +19,7 @@ function addSlugs (option) {
}

// Add URL-safe slugs for hrefs and IDs
option.slug = slugger(option.name)
option.slug = new Slugger().slug(option.name)

return option
}
Expand Down
4 changes: 2 additions & 2 deletions lib/metalsmith.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ const permalinks = require('@metalsmith/permalinks') // apply a permalink patter
const postcss = require('@metalsmith/postcss')
const sass = require('@metalsmith/sass') // convert Sass files to CSS using Dart Sass
const { glob } = require('glob') // Match files using glob patterns
const { Slugger } = require('marked') // generate slugs from titles
const Metalsmith = require('metalsmith') // static site generator
const canonical = require('metalsmith-canonical') // add a canonical url property to pages
const slugger = require('slugger') // generate slugs from titles

// Helpers and config
const { paths, navigation: menuItems } = require('../config')
Expand Down Expand Up @@ -60,7 +60,7 @@ const nunjucksOptions = {
},

filters: {
slugger
slugify: (string) => new Slugger().slug(string)
}
}

Expand Down
10 changes: 0 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@
"serve-static": "^1.15.0",
"sitemap": "^7.1.1",
"slash": "^3.0.0",
"slugger": "^1.0.1",
"standard": "^17.1.0",
"stylelint": "^14.16.1",
"stylelint-config-gds": "^0.3.0",
Expand Down
2 changes: 1 addition & 1 deletion views/partials/_example.njk
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
{% if params.id %}
{% set exampleId = params.id %}
{% else %}
{% set exampleId = (exampleTitle + " example") | slugger %}
{% set exampleId = (exampleTitle + " example") | slugify %}
{% endif %}

{% if params.open %}
Expand Down

0 comments on commit a1cfc85

Please sign in to comment.