Skip to content

Commit 0b8d95f

Browse files
authored
Reorg files (#15)
* top categories * questions all as individual files * fix basepath on include js * big reorg * semi working report, has bugs
1 parent 8a965a5 commit 0b8d95f

File tree

68 files changed

+1067
-717
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+1067
-717
lines changed

.eleventy.js

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
const govukEleventyPlugin = require("@x-govuk/govuk-eleventy-plugin");
2-
const markdownItinput = require("./plugins/inputs");
2+
const tagFilter = require("./plugins/tagFilter");
3+
const hashFilter = require("./plugins/hashFilter");
4+
const getContentsAfterTags = require("./plugins/getContentsAfterTags");
35
const fs = require("fs");
6+
const util = require("util");
47

58
function gitRev() {
69
const rev = fs.readFileSync(".git/HEAD").toString().trim();
@@ -11,6 +14,9 @@ function gitRev() {
1114
.toString()
1215
.trim();
1316
}
17+
function gitSHA() {
18+
return gitRev().slice(0, 8);
19+
}
1420

1521
module.exports = function (eleventyConfig) {
1622
eleventyConfig.addPlugin(govukEleventyPlugin, {
@@ -19,15 +25,20 @@ module.exports = function (eleventyConfig) {
1925
},
2026
footer: {
2127
meta: {
22-
text: `Page built from <a href="https://github.com/co-cddo/cloudmaturity/commit/${gitRev()}">${gitRev().slice(
23-
0,
24-
8,
25-
)}</a> at ${new Date().toISOString()}`,
28+
text: `Page built from <a href="https://github.com/co-cddo/cloudmaturity/commit/${gitRev()}">${gitSHA()}</a> at ${new Date().toISOString()}`,
2629
},
2730
},
2831
});
2932

30-
eleventyConfig.amendLibrary("md", (mdLib) => mdLib.use(markdownItinput, {}));
33+
eleventyConfig.addFilter("tagfilter", tagFilter);
34+
eleventyConfig.addFilter("hash", hashFilter);
35+
eleventyConfig.addFilter("getContentsAfterTags", getContentsAfterTags);
36+
37+
eleventyConfig.addFilter("console", function (value) {
38+
const str = util.inspect(value);
39+
return `<code style="white-space: pre-wrap;">${unescape(str)}</code>;`;
40+
});
41+
3142
eleventyConfig.addPassthroughCopy("./src/assets");
3243
eleventyConfig.addPassthroughCopy("./src/robots.txt");
3344
eleventyConfig.addPassthroughCopy({

plugins/getContentsAfterTags.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
function getContentsAfterTags(htmlString, tagName) {
2+
if (!htmlString.trim()) return [];
3+
return htmlString
4+
.split(`<${tagName}`)
5+
.map((v, i) => (i === 0 ? v : `<${tagName}${v}`))
6+
.filter((v) => v.trim());
7+
}
8+
if (typeof module === "object" && module.exports)
9+
module.exports = getContentsAfterTags;

plugins/hashFilter.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
const { createHash } = require("crypto");
2+
3+
function hash(string) {
4+
return createHash("sha256").update(string).digest("hex");
5+
}
6+
if (typeof module === "object" && module.exports) module.exports = hash;

plugins/inputs.js

Lines changed: 0 additions & 313 deletions
This file was deleted.

plugins/tagFilter.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
"use strict";
2+
3+
// Filters passed in html content by tag
4+
function extractContentByTag(htmlString, tagName) {
5+
const regex = new RegExp(`<${tagName}[^>]*>(.*?)</${tagName}>`, "gi");
6+
let matches = [];
7+
let match;
8+
9+
while ((match = regex.exec(htmlString)) !== null) {
10+
matches.push(match[1]);
11+
}
12+
13+
return matches;
14+
}
15+
16+
if (typeof module === "object" && module.exports)
17+
module.exports = extractContentByTag;

0 commit comments

Comments
 (0)