Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into task-list-component
Browse files Browse the repository at this point in the history
  • Loading branch information
frankieroberto committed Jul 10, 2023
2 parents 863935c + 75c8b62 commit ac59424
Show file tree
Hide file tree
Showing 116 changed files with 1,915 additions and 1,656 deletions.
57 changes: 49 additions & 8 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,55 @@ updates:
- package-ecosystem: npm
directory: /
open-pull-requests-limit: 10

# Group packages into shared PR
groups:
babel:
patterns:
- '@babel/*'

lint:
patterns:
- 'eslint'
- 'eslint-*'
- 'standard'
- 'stylelint'
- 'stylelint-*'

metalsmith:
patterns:
- '@metalsmith/*'
- 'jstransformer-*'
- 'metalsmith'
- 'metalsmith-*'

postcss:
patterns:
- 'autoprefixer'
- 'postcss'
- 'postcss-*'

rollup:
patterns:
- '@rollup/*'
- 'rollup'

test:
patterns:
- '@axe-core/*'
- 'jest'
- 'jest-*'
- 'puppeteer'

reviewers:
- alphagov/design-system-developers

# Schedule run every Monday, local time
schedule:
# Defaults to weekly on Monday
interval: weekly
time: "10:30"
# Setting a timezone so we let dependabot worry about BST
timezone: "Europe/London"
time: '10:30'
timezone: 'Europe/London'

versioning-strategy: increase

allow:
Expand All @@ -24,9 +65,9 @@ updates:
directory: /
reviewers:
- alphagov/design-system-developers

# Schedule run every Monday, local time
schedule:
# Defaults to weekly on Monday
interval: weekly
time: "10:30"
# Setting a timezone so we let dependabot worry about BST
timezone: "Europe/London"
time: '10:30'
timezone: 'Europe/London'
39 changes: 18 additions & 21 deletions __tests__/search.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,40 +42,37 @@ describe('Site search', () => {
it('returns results where a word in the title begins with the letter "d"', async () => {
await $searchInput.type('d')

const resultsArray = await page.evaluate(
() => [...document.querySelectorAll('.app-site-search__option')]
// ignore any results where a match was found in the alias
.filter(elem => !elem.querySelector('.app-site-search__aliases'))
// only get text, ignore child nodes
.map(elem => elem.firstChild.textContent.toLowerCase())
)
// ignore any results where a match was found in the alias
const resultsArray = await page.$$eval('.app-site-search__option:not(:has(.app-site-search__aliases))', results =>
results.map(result => result.firstChild.textContent.toLowerCase()))

// regex with word boundary, in our case words that begin with 'd'
expect(resultsArray.every(item => (/\b[d]\w*/).test(item))).toBeTruthy()
for (const result of resultsArray) {
expect(result).toMatch(/\b[d]\w*/)
}

expect.assertions()
})

it('returns results that contain aliases that start with the letter "d"', async () => {
await $searchInput.type('d')

const resultsArray = await page.evaluate(
() => [...document.querySelectorAll('.app-site-search__option')]
// only get results where a match was found in the alias
.filter(elem => elem.querySelector('.app-site-search__aliases'))
.map(elem => elem.querySelector('.app-site-search__aliases').textContent)
)
// only get results where a match was found in the alias
const resultsArray = await page.$$eval('.app-site-search__option:has(.app-site-search__aliases)', results =>
results.map(result => result.querySelector('.app-site-search__aliases').textContent))

// regex with word boundary, in our case words that begin with 'd'
expect(resultsArray.every(item => (/\b[d]\w*/).test(item))).toBeTruthy()
for (const result of resultsArray) {
expect(result).toMatch(/\b[d]\w*/)
}

expect.assertions()
})

it('doesn\'t show any aliases if it finds any matches in the title', async () => {
it("doesn't show any aliases if it finds any matches in the title", async () => {
await $searchInput.type('det')

const resultsArray = await page.evaluate(
() => [...document.querySelectorAll('.app-site-search__aliases')]
.map(elem => elem.querySelector('.app-site-search__aliases'))
)

const resultsArray = await page.$$('.app-site-search__aliases')
expect(resultsArray).toHaveLength(0)
})

Expand Down
29 changes: 27 additions & 2 deletions config/navigation.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
/**
* Navigation menu items
*
* @type {NavigationItem[]}
*/
module.exports = [
{
label: 'Get started',
url: 'get-started'
url: 'get-started',
includeInSearch: true
},
{
label: 'Styles',
Expand All @@ -20,6 +26,25 @@ module.exports = [
},
{
label: 'Community',
url: 'community'
url: 'community',
includeInSearch: true
}
]

/**
* @typedef {object} NavigationItem
* @property {string} label - Navigation item text
* @property {string} url - URL path without leading slash
* @property {boolean} includeInSearch - Include in search index
* @property {NavigationSubItem[]} [items] - Navigation sub items
*/

/**
* @typedef {object} NavigationSubItem
* @property {string} label - Navigation item text
* @property {string} url - URL path without leading slash
* @property {string[]} [aliases] - Additional search terms (optional)
* @property {string[]} [headings] - Markdown extracted headings (optional)
* @property {string} [order] - Menu item sort order (optional)
* @property {string} [theme] - Menu heading to group by (optional)
*/
4 changes: 2 additions & 2 deletions docs/contributing/archiving-deleted-urls.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ Along with the pull request to delete or rename the URL you want to change, you
---
title: {Title of the page you are archiving}
layout: layout-archived.njk
ignore_in_sitemap: true
ignoreInSitemap: true
---
```
3. Below the new metadata you’ve added, write some brief content explaining to users that you have archived or renamed the page. As a minimum, you should include:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
---
title: Example with aliases
headingAliases:
Heading level 1: one
Heading level 2: two
Heading level 3: three
Heading level 1: one
Heading level 2: two
Heading level 3: three
---

Contents
Expand Down
20 changes: 0 additions & 20 deletions lib/file-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,23 +109,3 @@ exports.getHTMLCode = path => {
wrap_attributes: 'preserve'
})
}

// This helper function takes a path and
// returns the directories found under that path
exports.getDirectories = itemPath => {
let files
let directories
try {
files = fs.readdirSync(itemPath)
} catch (err) {
if (err.code === 'ENOENT') {
console.log(err.message)
} else {
throw err
}
}
if (files) {
directories = files.filter(filePath => fs.statSync(join(itemPath, filePath)).isDirectory())
}
return directories
}
2 changes: 1 addition & 1 deletion lib/generate-sitemap.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ const plugin = (opts) => {
}

// Ignore files if set to true
if (frontmatter.ignore_in_sitemap) {
if (frontmatter.ignoreInSitemap) {
return false
}
return true
Expand Down
2 changes: 1 addition & 1 deletion lib/metalsmith-lunr-index/fixtures/src/about-larry.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: Larry the cat
section: Cats
show_page_nav: true
showPageNav: true
---

# Larry (cat)
Expand Down
4 changes: 2 additions & 2 deletions lib/metalsmith-lunr-index/fixtures/src/with-page-headings.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
---
title: Page with headings
section: Components
show_page_nav: true
showPageNav: true
headingAliases:
Heading level 2: two
Heading level 2: two
---

# Heading level 1
Expand Down
4 changes: 2 additions & 2 deletions lib/metalsmith-lunr-index/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ module.exports = function lunrPlugin () {
})

const pageHeadingDocuments = documents
// Only include pages in the with show_page_nav: true
// Only include pages in the with showPageNav: true
.filter(path => {
return files[path].show_page_nav
return files[path].showPageNav
})
// Filter out files that don't have extracted headings
.filter(path => files[path].headings)
Expand Down
20 changes: 11 additions & 9 deletions lib/metalsmith.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const renamer = require('metalsmith-renamer') // rename files
const slugger = require('slugger') // generate slugs from titles

// Helpers and config
const { paths } = require('../config')
const { paths, navigation: menuItems } = require('../config')
const colours = require('../lib/colours.js') // get colours data
const extractPageHeadings = require('../lib/extract-page-headings/index.js') // extract page headings into file meta data
const fileHelper = require('../lib/file-helper.js') // helper function to operate on files
Expand Down Expand Up @@ -185,13 +185,13 @@ module.exports = metalsmith(resolve(__dirname, '../'))

// render markdown in source files
.use(markdown({
breaks: true, // Enable line breaks
mangle: false, // Don't mangle emails
smartypants: true, // use "smart" typographic punctuation
highlight: highlighter,

// Markdown renderer
renderer: new DesignSystemRenderer()
engineOptions: {
breaks: true, // Enable line breaks
mangle: false, // Don't mangle emails
smartypants: true, // use "smart" typographic punctuation
highlight: highlighter,
renderer: new DesignSystemRenderer() // Markdown renderer
}
}))

// apply a permalink pattern to files
Expand All @@ -207,7 +207,9 @@ module.exports = metalsmith(resolve(__dirname, '../'))
}))

// apply navigation
.use(navigation())
.use(navigation({
items: menuItems
}))

// generate a search index
.use(lunr())
Expand Down
Loading

0 comments on commit ac59424

Please sign in to comment.