myst-frontmatter
Advanced tools
Comparing version 1.1.13 to 1.1.14
@@ -7,2 +7,8 @@ import type { Biblio } from '../biblio/types.js'; | ||
import type { Thebe } from '../thebe/types.js'; | ||
type OutputRemovalOptions = 'show' | 'remove' | 'remove-warn' | 'remove-error' | 'warn' | 'error'; | ||
export type ProjectSettings = { | ||
output_stderr?: OutputRemovalOptions; | ||
output_stdout?: OutputRemovalOptions; | ||
output_matplotlib_strings?: OutputRemovalOptions; | ||
}; | ||
export type ProjectAndPageFrontmatter = SiteFrontmatter & { | ||
@@ -28,2 +34,3 @@ date?: string; | ||
exports?: Export[]; | ||
settings?: ProjectSettings; | ||
}; | ||
@@ -39,2 +46,3 @@ export type ProjectFrontmatter = ProjectAndPageFrontmatter & { | ||
}; | ||
export {}; | ||
//# sourceMappingURL=types.d.ts.map |
import type { ValidationOptions } from 'simple-validators'; | ||
import type { ProjectAndPageFrontmatter, ProjectFrontmatter } from './types.js'; | ||
import type { ProjectAndPageFrontmatter, ProjectFrontmatter, ProjectSettings } from './types.js'; | ||
export declare const PROJECT_SETTINGS: string[]; | ||
export declare const PROJECT_SETTINGS_ALIAS: { | ||
stderr_output: string; | ||
stdout_output: string; | ||
}; | ||
export declare const PROJECT_AND_PAGE_FRONTMATTER_KEYS: string[]; | ||
export declare const PROJECT_FRONTMATTER_KEYS: string[]; | ||
export declare function validateProjectAndPageSettings(value: Record<string, any>, opts: ValidationOptions): ProjectSettings | undefined; | ||
export declare function validateProjectAndPageFrontmatterKeys(value: Record<string, any>, opts: ValidationOptions): ProjectAndPageFrontmatter; | ||
@@ -6,0 +12,0 @@ export declare function validateProjectFrontmatterKeys(value: Record<string, any>, opts: ValidationOptions): ProjectFrontmatter; |
@@ -1,2 +0,2 @@ | ||
import { defined, filterKeys, incrementOptions, validateBoolean, validateDate, validateList, validateObject, validateObjectKeys, validateString, validateUrl, } from 'simple-validators'; | ||
import { defined, filterKeys, incrementOptions, validateBoolean, validateChoice, validateDate, validateList, validateObject, validateObjectKeys, validateString, validateUrl, } from 'simple-validators'; | ||
import { validateBiblio } from '../biblio/validators.js'; | ||
@@ -9,2 +9,15 @@ import { validateExportsList } from '../exports/validators.js'; | ||
import { validateBooleanOrObject, validateDoi } from '../utils/validators.js'; | ||
const OUTPUT_REMOVAL_OPTIONS = [ | ||
'show', | ||
'remove', | ||
'remove-warn', | ||
'remove-error', | ||
'warn', | ||
'error', | ||
]; | ||
export const PROJECT_SETTINGS = ['output_stderr', 'output_stdout', 'output_matplotlib_strings']; | ||
export const PROJECT_SETTINGS_ALIAS = { | ||
stderr_output: 'output_stderr', | ||
stdout_output: 'output_stdout', | ||
}; | ||
export const PROJECT_AND_PAGE_FRONTMATTER_KEYS = [ | ||
@@ -27,2 +40,3 @@ 'date', | ||
'exports', | ||
'settings', | ||
// Do not add any project specific keys here! | ||
@@ -39,2 +53,35 @@ ...SITE_FRONTMATTER_KEYS, | ||
]; | ||
export function validateProjectAndPageSettings(value, opts) { | ||
const output = {}; | ||
const settings = validateObjectKeys(value, { optional: PROJECT_SETTINGS, alias: PROJECT_SETTINGS_ALIAS }, opts); | ||
if (!settings) | ||
return undefined; | ||
if (defined(settings.output_stderr)) { | ||
const output_stderr = validateChoice(settings.output_stderr, { | ||
...incrementOptions('output_stderr', opts), | ||
choices: OUTPUT_REMOVAL_OPTIONS, | ||
}); | ||
if (output_stderr) | ||
output.output_stderr = output_stderr; | ||
} | ||
if (defined(settings.output_stdout)) { | ||
const output_stdout = validateChoice(settings.output_stdout, { | ||
...incrementOptions('output_stdout', opts), | ||
choices: OUTPUT_REMOVAL_OPTIONS, | ||
}); | ||
if (output_stdout) | ||
output.output_stdout = output_stdout; | ||
} | ||
if (defined(settings.output_matplotlib_strings)) { | ||
const output_matplotlib_strings = validateChoice(settings.output_matplotlib_strings, { | ||
...incrementOptions('output_matplotlib_strings', opts), | ||
choices: OUTPUT_REMOVAL_OPTIONS, | ||
}); | ||
if (output_matplotlib_strings) | ||
output.output_matplotlib_strings = output_matplotlib_strings; | ||
} | ||
if (Object.keys(output).length === 0) | ||
return undefined; | ||
return output; | ||
} | ||
export function validateProjectAndPageFrontmatterKeys(value, opts) { | ||
@@ -141,2 +188,7 @@ const output = validateSiteFrontmatterKeys(value, opts); | ||
} | ||
if (defined(value.settings)) { | ||
const settings = validateProjectAndPageSettings(value.settings, incrementOptions('settings', opts)); | ||
if (settings) | ||
output.settings = settings; | ||
} | ||
return output; | ||
@@ -143,0 +195,0 @@ } |
@@ -13,3 +13,3 @@ import { fillMissingKeys, incrementOptions, validationWarning } from 'simple-validators'; | ||
export function fillPageFrontmatter(pageFrontmatter, projectFrontmatter, opts) { | ||
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t; | ||
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v; | ||
const frontmatter = fillMissingKeys(pageFrontmatter, projectFrontmatter, USE_PROJECT_FALLBACK); | ||
@@ -40,6 +40,13 @@ // If numbering is an object, combine page and project settings. | ||
} | ||
// Combine all settings defined on page and project | ||
if (projectFrontmatter.settings || pageFrontmatter.settings) { | ||
frontmatter.settings = { | ||
...((_g = projectFrontmatter.settings) !== null && _g !== void 0 ? _g : {}), | ||
...((_h = pageFrontmatter.settings) !== null && _h !== void 0 ? _h : {}), | ||
}; | ||
} | ||
// Gather all contributors and affiliations from funding sources | ||
const contributorIds = new Set(); | ||
const affiliationIds = new Set(); | ||
(_g = frontmatter.funding) === null || _g === void 0 ? void 0 : _g.forEach((fund) => { | ||
(_j = frontmatter.funding) === null || _j === void 0 ? void 0 : _j.forEach((fund) => { | ||
var _a; | ||
@@ -59,9 +66,9 @@ (_a = fund.awards) === null || _a === void 0 ? void 0 : _a.forEach((award) => { | ||
}); | ||
if (((_h = frontmatter.authors) === null || _h === void 0 ? void 0 : _h.length) || contributorIds.size) { | ||
if (((_k = frontmatter.authors) === null || _k === void 0 ? void 0 : _k.length) || contributorIds.size) { | ||
// Gather all people from page/project authors/contributors | ||
const people = [ | ||
...((_j = pageFrontmatter.authors) !== null && _j !== void 0 ? _j : []), | ||
...((_k = projectFrontmatter.authors) !== null && _k !== void 0 ? _k : []), | ||
...((_l = pageFrontmatter.contributors) !== null && _l !== void 0 ? _l : []), | ||
...((_m = projectFrontmatter.contributors) !== null && _m !== void 0 ? _m : []), | ||
...((_l = pageFrontmatter.authors) !== null && _l !== void 0 ? _l : []), | ||
...((_m = projectFrontmatter.authors) !== null && _m !== void 0 ? _m : []), | ||
...((_o = pageFrontmatter.contributors) !== null && _o !== void 0 ? _o : []), | ||
...((_p = projectFrontmatter.contributors) !== null && _p !== void 0 ? _p : []), | ||
]; | ||
@@ -79,3 +86,3 @@ const peopleLookup = {}; | ||
}); | ||
if ((_o = frontmatter.authors) === null || _o === void 0 ? void 0 : _o.length) { | ||
if ((_q = frontmatter.authors) === null || _q === void 0 ? void 0 : _q.length) { | ||
frontmatter.authors = frontmatter.authors.map((auth) => { | ||
@@ -98,3 +105,3 @@ var _a; | ||
// Add affiliations from reconstructed author/contributor lists and explicit page affiliations | ||
[...((_p = frontmatter.authors) !== null && _p !== void 0 ? _p : []), ...((_q = frontmatter.contributors) !== null && _q !== void 0 ? _q : [])].forEach((auth) => { | ||
[...((_r = frontmatter.authors) !== null && _r !== void 0 ? _r : []), ...((_s = frontmatter.contributors) !== null && _s !== void 0 ? _s : [])].forEach((auth) => { | ||
var _a; | ||
@@ -105,3 +112,3 @@ (_a = auth.affiliations) === null || _a === void 0 ? void 0 : _a.forEach((aff) => { | ||
}); | ||
(_r = frontmatter.affiliations) === null || _r === void 0 ? void 0 : _r.forEach((aff) => { | ||
(_t = frontmatter.affiliations) === null || _t === void 0 ? void 0 : _t.forEach((aff) => { | ||
if (aff.id) | ||
@@ -112,4 +119,4 @@ affiliationIds.add(aff.id); | ||
const affiliations = [ | ||
...((_s = pageFrontmatter.affiliations) !== null && _s !== void 0 ? _s : []), | ||
...((_t = projectFrontmatter.affiliations) !== null && _t !== void 0 ? _t : []), | ||
...((_u = pageFrontmatter.affiliations) !== null && _u !== void 0 ? _u : []), | ||
...((_v = projectFrontmatter.affiliations) !== null && _v !== void 0 ? _v : []), | ||
]; | ||
@@ -116,0 +123,0 @@ const affiliationLookup = {}; |
{ | ||
"name": "myst-frontmatter", | ||
"version": "1.1.13", | ||
"version": "1.1.14", | ||
"sideEffects": false, | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
170309
4460