Skip to content

Commit 078f4ff

Browse files
committed
content plugin logs
1 parent f628fa9 commit 078f4ff

File tree

6 files changed

+62
-10
lines changed

6 files changed

+62
-10
lines changed

.changeset/upset-hats-poke.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@bluecadet/launchpad-content": patch
3+
---
4+
5+
Ensure all content plugins log on start and success.

packages/content/src/plugins/md-to-html.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,11 @@ export default function mdToHtml(options: z.input<typeof mdToHtmlSchema>) {
2626
return defineContentPlugin({
2727
name: "md-to-html",
2828
hooks: {
29-
onContentFetchDone(ctx) {
30-
return applyTransformToFiles({
29+
async onContentFetchDone(ctx) {
30+
let transformCount = 0;
31+
ctx.logger.info("Transforming Markdown strings to HTML...");
32+
33+
await applyTransformToFiles({
3134
dataStore: ctx.data,
3235
path,
3336
keys,
@@ -44,10 +47,16 @@ export default function mdToHtml(options: z.input<typeof mdToHtmlSchema>) {
4447
md.use(markdownItItalicBold);
4548
return md.renderInline(sanitizedStr);
4649
}
50+
51+
transformCount++;
4752

4853
return md.render(sanitizedStr);
4954
},
5055
});
56+
57+
ctx.logger.info(
58+
`Transformed ${transformCount} Markdown strings.`,
59+
);
5160
},
5261
},
5362
});

packages/content/src/plugins/sanity-image-url-transform.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,14 @@ export default function sanityImageUrlTransform(
5050
return defineContentPlugin({
5151
name: "sanity-to-html",
5252
hooks: {
53-
onContentFetchDone(ctx) {
54-
return applyTransformToFiles({
53+
async onContentFetchDone(ctx) {
54+
let transformCount = 0;
55+
56+
ctx.logger.info(
57+
"Transforming URLs using Sanity Image URL Transform...",
58+
);
59+
60+
await applyTransformToFiles({
5561
dataStore: ctx.data,
5662
path,
5763
keys,
@@ -62,13 +68,18 @@ export default function sanityImageUrlTransform(
6268
}
6369

6470
const transformedUrl = buildUrl(builder.image(content)).url();
71+
transformCount++;
6572

6673
return {
6774
...content,
6875
[newProperty]: transformedUrl,
6976
};
7077
},
7178
});
79+
80+
ctx.logger.info(
81+
`Transformed ${transformCount} URLs.`,
82+
);
7283
},
7384
},
7485
});

packages/content/src/plugins/sanity-to-html.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,11 @@ export default function sanityToHtml(options: z.input<typeof sanityToHtmlSchema>
1919
return defineContentPlugin({
2020
name: "sanity-to-html",
2121
hooks: {
22-
onContentFetchDone(ctx) {
23-
return applyTransformToFiles({
22+
async onContentFetchDone(ctx) {
23+
let transformCount = 0;
24+
ctx.logger.info("Transforming sanity blocks to HTML...");
25+
26+
await applyTransformToFiles({
2427
dataStore: ctx.data,
2528
path,
2629
keys,
@@ -30,9 +33,15 @@ export default function sanityToHtml(options: z.input<typeof sanityToHtmlSchema>
3033
throw new Error(`Content is not a valid Sanity text block: ${content}`);
3134
}
3235

36+
transformCount++;
37+
3338
return toHTML(content);
3439
},
3540
});
41+
42+
ctx.logger.info(
43+
`Transformed ${transformCount} Sanity blocks to HTML.`,
44+
);
3645
},
3746
},
3847
});

packages/content/src/plugins/sanity-to-markdown.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,11 @@ export default function sanityToMd(options: z.input<typeof sanityToMdSchema>) {
1919
return defineContentPlugin({
2020
name: "sanity-to-markdown",
2121
hooks: {
22-
onContentFetchDone(ctx) {
23-
return applyTransformToFiles({
22+
async onContentFetchDone(ctx) {
23+
let transformCount = 0;
24+
ctx.logger.info("Transforming sanity blocks to markdown...");
25+
26+
await applyTransformToFiles({
2427
dataStore: ctx.data,
2528
path,
2629
keys,
@@ -30,9 +33,15 @@ export default function sanityToMd(options: z.input<typeof sanityToMdSchema>) {
3033
throw new Error(`Content is not a valid Sanity text block: ${content}`);
3134
}
3235

36+
transformCount++;
37+
3338
return toMarkdown(content);
3439
},
3540
});
41+
42+
ctx.logger.info(
43+
`Transformed ${transformCount} Sanity blocks to markdown.`,
44+
);
3645
},
3746
},
3847
});

packages/content/src/plugins/sanity-to-plain.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,11 @@ export default function sanityToPlain(options: z.input<typeof sanityToPlainSchem
1717
return defineContentPlugin({
1818
name: "sanity-to-plain",
1919
hooks: {
20-
onContentFetchDone(ctx) {
21-
return applyTransformToFiles({
20+
async onContentFetchDone(ctx) {
21+
let transformCount = 0;
22+
ctx.logger.info("Transforming sanity blocks to plain text...");
23+
24+
await applyTransformToFiles({
2225
dataStore: ctx.data,
2326
path,
2427
keys,
@@ -28,9 +31,15 @@ export default function sanityToPlain(options: z.input<typeof sanityToPlainSchem
2831
throw new Error(`Content is not a valid Sanity text block: ${content}`);
2932
}
3033

34+
transformCount++;
35+
3136
return content.children.map((child) => child.text).join("");
3237
},
3338
});
39+
40+
ctx.logger.info(
41+
`Transformed ${transformCount} Sanity blocks to plain text.`,
42+
);
3443
},
3544
},
3645
});

0 commit comments

Comments
 (0)