Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse cookie consent form as html #1163

Merged
merged 1 commit into from
Sep 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
});
Loading