Skip to content

Commit

Permalink
Fix bug with invalid example IDs
Browse files Browse the repository at this point in the history
This reverts a hotfix #809
that removed the changes in favour of a proper fix for
#620

Generating example IDs from example titles can be brittle if there
are unexpected characters in titles. Use the IDs and
fall back to default ones and uses the solution from #620 to fix
duplicate IDs
  • Loading branch information
hannalaakso committed Mar 1, 2019
1 parent 82bfeeb commit 3522fc1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
3 changes: 1 addition & 2 deletions lib/metalsmith.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,7 @@ module.exports = metalsmith(__dirname) // __dirname defined by node.js: name of
getMacroOptions: getMacroOptions
},
filters: {
highlight: highlighter,
kebabCase: string => string.replace(/\s+/g, '-').toLowerCase()
highlight: highlighter
},

// Markdown engine options
Expand Down
7 changes: 6 additions & 1 deletion views/partials/_example.njk
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@
{% endif %}
{% set exampleTitle = exampleTitle + " example" %}

{% set exampleId = exampleTitle | kebabCase %}
{% set exampleId = params.id | default("example-" + params.example) %}

{% if params.titleSuffix %}
{% set exampleId = exampleId + '-' + params.titleSuffix %}
{% endif %}

{% if params.open %}
{% set exampleId = exampleId + '-open' %}
{% endif %}
Expand Down

0 comments on commit 3522fc1

Please sign in to comment.