Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function key(context, { logger }) {
const cont = setdefault(context, 'content', {});
const res = setdefault(context, 'response', {});
const headers = setdefault(res, 'headers', {});
// somebody already set a surrogate key
if (headers['Surrogate-Key'] || !(type(cont.sources) === Array)) {
logger.debug('Keeping existing Surrogate-Key header');
return;
}
logger.debug('Setting Surrogate-Key header');
headers['Surrogate-Key'] = join(' ')(map(cont.sources, computeSurrogateKey));
}
} else if (src.match(re(`\\n${hspace}*\\n`)) && fst.idx > 0) {
return warn(null,
'Found ambigous frontmatter fence: Block contains empty line! '
+ 'Make sure your mid-document YAML blocks contain no empty lines '
+ 'and your horizontal rules have an empty line before AND after them.');
}
const txt = str.slice(fst.offEnd, !last ? undefined : last.offStart);
let data;
try {
data = yaml.safeLoad(txt);
} catch (e) {
return warn(e, `Exception ocurred while parsing yaml: ${e}`);
}
if (type(data) !== Object) {
return warn(null,
'Found ambigous frontmatter block: Block contains valid yaml, but '
+ `it's data type is ${type(data)} instead of Object.`
+ 'Make sure your yaml blocks contain only key-value pairs at the root level!');
}
return {
type: 'frontmatter',
payload: data,
start: fst.idx,
end: last.idx,
};
});
each(sections, (section) => {
const meta = setdefault(section, 'meta', {});
const strainList = type(meta.strain) === Array ? meta.strain : [meta.strain];
meta.hidden = Boolean(meta.strain && meta.strain !== [] && !strainList.includes(strain));
});
}
+ 'Make sure your mid-document YAML blocks contain no empty lines '
+ 'and your horizontal rules have an empty line before AND after them.');
}
const txt = str.slice(fst.offEnd, !last ? undefined : last.offStart);
let data;
try {
data = yaml.safeLoad(txt);
} catch (e) {
return warn(e, `Exception ocurred while parsing yaml: ${e}`);
}
if (type(data) !== Object) {
return warn(null,
'Found ambigous frontmatter block: Block contains valid yaml, but '
+ `it's data type is ${type(data)} instead of Object.`
+ 'Make sure your yaml blocks contain only key-value pairs at the root level!');
}
return {
type: 'frontmatter',
payload: data,
start: fst.idx,
end: last.idx,
};
});