Skip to content

Commit

Permalink
Merge pull request #49 from digital-land/feat/capitalise_nav
Browse files Browse the repository at this point in the history
add capitalise  function
  • Loading branch information
eveleighoj authored Oct 1, 2024
2 parents ebe031d + db1766c commit d4d5e87
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,8 @@ Staticfile.auth
.bin/
.venv

.idea
.idea

# don't commit node modeuls or the _site folder generated by eleventy
_site
node_modules
12 changes: 9 additions & 3 deletions eleventy.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
const govukEleventyPlugin = require('@x-govuk/govuk-eleventy-plugin')

function capitalizeWords(str) {
return str.replace(/\b\w/g, function(match) {
return match.toUpperCase();
});
}

module.exports = function(eleventyConfig) {
// Register the plugin
eleventyConfig.addPlugin(govukEleventyPlugin,{
Expand All @@ -13,7 +19,7 @@ module.exports = function(eleventyConfig) {
// Sort by URL
return a.url.localeCompare(b.url);
});
});
});

// Register specific options
eleventyConfig.setQuietMode(false)
Expand All @@ -28,7 +34,7 @@ module.exports = function(eleventyConfig) {
pages.forEach(page => {
// Extract file slug and use it as a key
const key = page.fileSlug || 'home'; // Default to 'home' if no slug
const title = page.data.title || key.replace(/-/g, ' '); // Title defaults to slug if none is provided
const title = page.data.title || capitalizeWords(key.replace(/-/g, ' ')); // Title defaults to slug if none is provided
const url = page.url || `/`; // Default URL if none is provided
// Create an object for the page
const pageObject = {
Expand All @@ -54,7 +60,7 @@ module.exports = function(eleventyConfig) {
if (parts.length===1 && parts[0] === 'index.md') {
if (!structure[currentDir]) {
structure[currentDir] = {
title: currentDir.replace(/-/g, ' '),
title: capitalizeWords(currentDir.replace(/-/g, ' ')),
url: pageObj.url,
children: {}
};
Expand Down

0 comments on commit d4d5e87

Please sign in to comment.