Skip to content

Commit

Permalink
Parse cookie consent form as html
Browse files Browse the repository at this point in the history
  • Loading branch information
hanbyul-here committed Sep 20, 2024
1 parent 01b7443 commit 84d3d62
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions parcel-resolver-veda/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const dedent = require('dedent');
const _ = require('lodash');
const { Resolver } = require('@parcel/plugin');

const markdownit = require('markdown-it');
const stringifyYmlWithFns = require('./stringify-yml-func');
const { loadVedaConfig } = require('./config');
const { getFrontmatterData } = require('./frontmatter');
Expand All @@ -19,6 +20,8 @@ const {
} = require('./taxonomies');
const { withDefaultStrings } = require('./defaults');

const md = markdownit();

async function loadOptionalContent(logger, root, globPath, type) {
try {
const loadPath = path.resolve(root, globPath);
Expand Down Expand Up @@ -80,6 +83,15 @@ function generateMdxDataObject(data) {
}`;
}

function getCookieConsentForm(result) {
if (!result.cookieConsentForm) return undefined;
else {
const parsedCopy = md.render(result.cookieConsentForm.copy)
const trimmedCopy = parsedCopy.replace(/(\r\n|\n|\r)/gm, '');
return JSON.stringify({ title: result.cookieConsentForm.title, copy: trimmedCopy});
}
}

// Using all the "key: path" combinations under config.pageOverrides, load the
// file at the given path, and return an object with a data object and a
// content.
Expand Down Expand Up @@ -197,7 +209,7 @@ module.exports = new Resolver({
booleans: ${JSON.stringify(withDefaultStrings(result.booleans))},
banner: ${JSON.stringify(result.banner)},
navItems: ${JSON.stringify(result.navItems)},
cookieConsentForm: ${JSON.stringify(result.cookieConsentForm)}
cookieConsentForm: ${getCookieConsentForm(result)}
};
export const theme = ${JSON.stringify(result.theme) || null};
Expand Down Expand Up @@ -258,9 +270,5 @@ module.exports = new Resolver({
// console.log('resolved', resolved);
return resolved;
}

// Let the next resolver in the pipeline handle
// this dependency.
return null;
}
});

0 comments on commit 84d3d62

Please sign in to comment.