This repository has been archived by the owner on Mar 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
876 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -60,3 +60,5 @@ typings/ | |
# css files | ||
*.css | ||
*.css.map | ||
|
||
app/views/includes/header-items.nunjucks |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,5 +2,5 @@ check: | |
global: | ||
statements: 80 | ||
lines: 80 | ||
branches: 37 | ||
branches: 55 | ||
functions: 80 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
const cleanHeaderUrl = require('./cleanHeaderUrl'); | ||
|
||
const seperator = ''; | ||
|
||
function getAnchor(item) { | ||
return `<a href="${cleanHeaderUrl(item.URL)}">${item.Title}</a>`; | ||
} | ||
|
||
function getSubmenu(submenus) { | ||
// eslint-disable-next-line no-use-before-define | ||
return submenus ? `<ul>${buildLinkTags(submenus)}</ul>` : ''; | ||
} | ||
|
||
function buildLinkTags(menus) { | ||
return menus.map(item => `<li>${getAnchor(item)}${getSubmenu(item.Submenus)}</li>`).join(seperator); | ||
} | ||
|
||
function buildHeaderItems(menus) { | ||
return buildLinkTags(menus); | ||
} | ||
|
||
module.exports = buildHeaderItems; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
const siteToReplace = 'http://site'; | ||
const nhsukDomain = 'https://www.nhs.uk'; | ||
|
||
function getUrl(item) { | ||
return item ? item.split(',')[0] : ''; | ||
} | ||
|
||
function replaceSpaces(url) { | ||
// encodeURIComponent can't be used as the source URLs are already partially encoded | ||
return url.replace(/ /g, '%20'); | ||
} | ||
|
||
function cleanHeaderUrl(item) { | ||
return replaceSpaces(getUrl(item).replace(siteToReplace, nhsukDomain)); | ||
} | ||
|
||
module.exports = cleanHeaderUrl; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
const request = require('request'); | ||
|
||
async function getHeaderContent(url) { | ||
return new Promise((resolve, reject) => { | ||
request(url, (error, response, body) => { | ||
if (!error && response.statusCode === 200) { | ||
resolve(body); | ||
} else { | ||
reject(error); | ||
} | ||
}); | ||
}); | ||
} | ||
|
||
async function getHeader(url) { | ||
const body = await getHeaderContent(url); | ||
return JSON.parse(body); | ||
} | ||
|
||
module.exports = getHeader; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
const fs = require('fs'); | ||
const getHeader = require('./app/lib/header/getHeader'); | ||
const buildHeaderItems = require('./app/lib/header/buildHeaderItems'); | ||
const log = require('./app/lib/logger'); | ||
const config = require('./config/config'); | ||
|
||
const headerFileName = 'app/views/includes/header-items.nunjucks'; | ||
|
||
function saveFile(output, filename) { | ||
fs.writeFileSync(filename, output, (err) => { | ||
if (err) { | ||
throw err; | ||
} | ||
log.info(`${headerFileName} written.`); | ||
}); | ||
} | ||
|
||
async function saveHeaderItems() { | ||
try { | ||
log.info(`Building '${headerFileName}'`); | ||
const response = await getHeader(config.headerApiUrl); | ||
const headerItems = buildHeaderItems(response); | ||
saveFile(headerItems, headerFileName); | ||
log.info('Build complete.'); | ||
} catch (ex) { | ||
log.error(ex); | ||
} | ||
} | ||
|
||
saveHeaderItems(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.