Skip to content

Commit

Permalink
update config of navigation
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickpatrickpatrick committed Dec 18, 2024
1 parent d18d80c commit a7fb2d3
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 36 deletions.
24 changes: 6 additions & 18 deletions config/navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,40 +5,28 @@
*/
const config = [
{
label: 'Get started',
url: 'get-started',
text: 'Get started',
href: '/get-started'
href: 'get-started'
},
{
label: 'Styles',
url: 'styles',
text: 'Styles',
href: '/styles'
href: 'styles'
},
{
label: 'Components',
url: 'components',
text: 'Components',
href: '/components'
href: 'components'
},
{
label: 'Patterns',
url: 'patterns',
text: 'Patterns',
href: '/patterns'
href: 'patterns'
},
{
label: 'Community',
url: 'community',
text: 'Community',
href: '/community'
href: 'community'
},
{
label: 'Accessibility',
url: 'accessibility',
text: 'Accessibility',
href: '/accessibility'
href: 'accessibility'
}
]

Expand Down
8 changes: 5 additions & 3 deletions lib/navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ module.exports = (config) => (files, metalsmith, done) => {
for (const item of items) {
// Match navigation item child directories
// (for example, ['components/breadcrumbs/index.html', 'components/checkboxes/index.html', ...])
const itemPaths = metalsmith.match(`${item.url}/*/index.html`, paths)
const itemPaths = metalsmith.match(`${item.href}/*/index.html`, paths)

// No sub items required for this path
if (!itemPaths.length) {
Expand All @@ -47,8 +47,8 @@ module.exports = (config) => (files, metalsmith, done) => {

// Add subitem to navigation
item.items.push({
url: dirname(itemPath),
label: frontmatter.title,
href: `${dirname(itemPath)}`,
text: frontmatter.title,
order: frontmatter.order,
theme: frontmatter.theme,

Expand All @@ -65,6 +65,8 @@ module.exports = (config) => (files, metalsmith, done) => {

// Sort navigation sub items using 'order' (optional)
item.items?.sort((a, b) => compare(a.order, b.order))

item.href = `/${item.href}`
}

// Add navigation to global variables
Expand Down
4 changes: 2 additions & 2 deletions views/partials/_mobile-navigation.njk
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
<ul class="app-navigation__list">
{% for item in params.items %}
<li class="app-navigation__subnav-item">
<a class="govuk-link govuk-link--no-visited-state govuk-link--no-underline" href="{{ item.url }}">
{{ item.label }}
<a class="govuk-link govuk-link--no-visited-state govuk-link--no-underline" href="{{ item.href }}">
{{ item.text }}
</a>
</li>
{% endfor %}
Expand Down
13 changes: 0 additions & 13 deletions views/partials/_sub-navigation-items.njk

This file was deleted.

0 comments on commit a7fb2d3

Please sign in to comment.