From e198c5ed8d5748f4d2b95d5cd609f324bb29df98 Mon Sep 17 00:00:00 2001 From: "Brady Stroud [SSW]" Date: Tue, 10 Sep 2024 15:14:20 +1000 Subject: [PATCH 1/2] Fix a few bugs with the Markdown sanitizing --- gatsby-node.js | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/gatsby-node.js b/gatsby-node.js index 6bf23a0..4df73ea 100644 --- a/gatsby-node.js +++ b/gatsby-node.js @@ -492,7 +492,9 @@ exports.createPages = async function ({ actions, graphql }) { toPath: `/${person.path}`, isPermanent: true, }); - console.log('Creating redirect from ' + nicknamePath + ' to ' + person.path); + console.log( + 'Creating redirect from ' + nicknamePath + ' to ' + person.path + ); } if (person.path.includes('alumni')) { @@ -515,14 +517,19 @@ exports.createPages = async function ({ actions, graphql }) { const sanitisedMarkdown = (input) => { const lines = input.split('\n'); - const filteredLines = lines.filter((x) => { + const filteredLines = lines.filter((line) => { const imgRegex = /!\[.*\](.*)/; + const emptyLineRegex = /^\s*$/; // this gets rid of '\r' lines + return ( - !imgRegex.test(x) && - !x.trim().includes('[[imgBadge]]') && - !x.trim().includes('[Editing profiles]') && - !x.trim().includes('
') && - x.length !== 0 + !imgRegex.test(line) && + !line.trim().includes('[[imgBadge]]') && + !line.trim().includes('[Editing profiles]') && + !line.trim().includes('
') && + !line.trim().includes('---') && + !line.trim().startsWith('#') && + !emptyLineRegex.test(line) && + line.length !== 0 ); }); @@ -532,6 +539,7 @@ exports.createPages = async function ({ actions, graphql }) { var profileData = { skills: skills.join(' | '), + position: person.dataCRM.jobTitle.trim(), presenter: { name: person.dataCRM.fullName, peopleProfileURL: 'https://www.ssw.com.au/people/' + person.path, @@ -539,6 +547,8 @@ exports.createPages = async function ({ actions, graphql }) { about: sanitisedMarkdown(person.rawMarkdown), }; + console.log(profileData); + fs.writeFileSync( `${filePath}/profile.md`, matter.stringify('', profileData) From 391c1b8bd963ec4a8d68d93b577c9fd04cfdb4e8 Mon Sep 17 00:00:00 2001 From: "Brady Stroud [SSW]" Date: Tue, 10 Sep 2024 15:18:43 +1000 Subject: [PATCH 2/2] Update gatsby-node.js --- gatsby-node.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/gatsby-node.js b/gatsby-node.js index 4df73ea..f216176 100644 --- a/gatsby-node.js +++ b/gatsby-node.js @@ -547,8 +547,6 @@ exports.createPages = async function ({ actions, graphql }) { about: sanitisedMarkdown(person.rawMarkdown), }; - console.log(profileData); - fs.writeFileSync( `${filePath}/profile.md`, matter.stringify('', profileData)