Skip to content

Commit 9dc8288

Browse files
committed
metadata extension
1 parent 9335d4b commit 9dc8288

File tree

6 files changed

+29
-19
lines changed

6 files changed

+29
-19
lines changed

src/command/render/project.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,8 @@ const getProjectRenderScripts = async (
238238
);
239239
}
240240
extensions.forEach((extension) => {
241-
if (extension.contributes.project?.project) {
242-
const project = extension.contributes.project.project as Record<
241+
if (extension.contributes.metadata?.project) {
242+
const project = extension.contributes.metadata.project as Record<
243243
string,
244244
unknown
245245
>;

src/extension/extension.ts

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,7 @@ function validateExtension(extension: Extension) {
625625
extension.contributes.formats,
626626
extension.contributes.project,
627627
extension.contributes[kRevealJSPlugins],
628+
extension.contributes.metadata,
628629
];
629630
contribs.forEach((contrib) => {
630631
if (contrib) {
@@ -783,23 +784,30 @@ async function readExtension(
783784
return resolveFilterPath(extensionDir, filter);
784785
},
785786
);
786-
const project = (contributes?.project || {}) as Record<string, unknown>;
787-
// resolve project pre- and post-render scripts to their full path
787+
const project = contributes?.project as Record<string, unknown> | undefined;
788+
const metadata = contributes?.metadata as Record<string, unknown> | undefined;
789+
790+
// resolve metadata/project pre- and post-render scripts to their full path
788791
for (const key of ["pre-render", "post-render"]) {
789-
if (
790-
project.project &&
791-
(project.project as Record<string, unknown>)[key]
792-
) {
793-
const t = (project.project as Record<string, unknown>)[key];
794-
const value = (Array.isArray(t) ? t : [t]) as string[];
795-
const resolved = resolvePathGlobs(
796-
extensionDir,
797-
value as string[],
798-
[],
799-
);
800-
if (resolved.include.length > 0) {
801-
(project.project as Record<string, unknown>)[key] = resolved
802-
.include;
792+
for (const object of [metadata, project]) {
793+
if (!object?.project || typeof object.project !== "object") {
794+
continue;
795+
}
796+
// object.project is truthy and typeof object.project is object
797+
// so we can safely cast object.project to Record<string, unknown>
798+
// the TypeScript checker doesn't appear to recognize this
799+
const t = (object.project as Record<string, unknown>)[key];
800+
if (t) {
801+
const value = (Array.isArray(t) ? t : [t]) as string[];
802+
const resolved = resolvePathGlobs(
803+
extensionDir,
804+
value as string[],
805+
[],
806+
);
807+
if (resolved.include.length > 0) {
808+
(object.project as Record<string, unknown>)[key] = resolved
809+
.include;
810+
}
803811
}
804812
}
805813
}
@@ -818,6 +826,7 @@ async function readExtension(
818826
id: extensionId,
819827
path: extensionDir,
820828
contributes: {
829+
metadata,
821830
shortcodes,
822831
filters,
823832
formats,

src/extension/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ export interface Extension extends Record<string, unknown> {
3333
quartoVersion?: Range;
3434
path: string;
3535
contributes: {
36+
metadata?: Metadata;
3637
project?: Record<string, unknown>;
3738
shortcodes?: string[];
3839
filters?: QuartoFilter[];

tests/docs/project/prepost/extension/_extensions/prerender/_extension.yml renamed to tests/docs/project/prepost/extension/_extensions/author/prerender/_extension.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ author: cscheid
33
version: 1.0.0
44
quarto-required: ">=1.2.0"
55
contributes:
6-
project:
6+
metadata:
77
project:
88
pre-render:
99
- pre-render.ts

tests/docs/project/prepost/extension/_extensions/prerender/post-render.ts renamed to tests/docs/project/prepost/extension/_extensions/author/prerender/post-render.ts

File renamed without changes.

tests/docs/project/prepost/extension/_extensions/prerender/pre-render.ts renamed to tests/docs/project/prepost/extension/_extensions/author/prerender/pre-render.ts

File renamed without changes.

0 commit comments

Comments
 (0)