Skip to content

Commit d109c58

Browse files
committed
update cf transform fn
1 parent a77e084 commit d109c58

File tree

2 files changed

+65
-34
lines changed

2 files changed

+65
-34
lines changed

src/transform/cloudflare.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,33 +10,36 @@ interface CF_Key {
1010
value: string;
1111
}
1212

13+
export interface Docs {
14+
list: Array<Record<string, unknown>>;
15+
full: Array<Record<string, unknown>>;
16+
}
17+
1318
export function transform_cloudflare(
14-
docs: Array<Record<string, unknown>>,
19+
docs: Docs,
1520
{ project, type, keyby, version = "latest" }: Transform_Options
1621
) {
17-
const _list = [];
1822
const keys: CF_Key[] = [
1923
{
2024
key: `${project}@${version}:${type}:content`,
21-
value: JSON.stringify(docs),
25+
value: JSON.stringify(docs.full),
2226
},
2327
];
2428

25-
for (let i = 0; i < docs.length; i++) {
26-
const { content, ...rest } = docs[i];
27-
_list.push(rest);
29+
for (let i = 0; i < docs.full.length; i++) {
30+
// const { content, ...rest } = docs[i];
2831

29-
const item_key = docs[i][keyby];
32+
const item_key = docs.full[i][keyby];
3033

3134
keys.push({
3235
key: `${project}@${version}:${type}:${item_key}`,
33-
value: JSON.stringify(docs[i]),
36+
value: JSON.stringify(docs.full[i]),
3437
});
3538
}
3639

3740
keys.push({
3841
key: `${project}@${version}:${type}:list`,
39-
value: JSON.stringify(_list),
42+
value: JSON.stringify(docs.list),
4043
});
4144

4245
return keys;

src/transform/fixtures/cloudflare.ts

Lines changed: 53 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { Docs } from "../cloudflare";
2+
13
type FormattedFile = {
24
content: string;
35
title: string;
@@ -6,8 +8,14 @@ type FormattedFile = {
68
sections: section[];
79
};
810

9-
const one: FormattedFile = {
10-
content: "test",
11+
export type ListItem = {
12+
title: string;
13+
slug: string;
14+
file: string;
15+
sections: section[];
16+
};
17+
18+
const one = <ListItem>{
1119
title: "Introduction",
1220
slug: "Introduction",
1321
file: "00-introduction.md",
@@ -77,8 +85,7 @@ const one: FormattedFile = {
7785
},
7886
],
7987
};
80-
const two: FormattedFile = {
81-
content: "test2",
88+
const two = <ListItem>{
8289
title: "Introduction2",
8390
slug: "Introduction_2",
8491
file: "00-introduction-2.md",
@@ -149,8 +156,7 @@ const two: FormattedFile = {
149156
],
150157
};
151158

152-
export const three: FormattedFile = {
153-
content: "test3",
159+
export const three = <ListItem>{
154160
title: "Introduction3",
155161
slug: "Introduction_3",
156162
file: "00-introduction-3.md",
@@ -220,16 +226,17 @@ export const three: FormattedFile = {
220226
},
221227
],
222228
};
223-
export const base: FormattedFile[] = [one, two, three];
224229

225-
type section = { slug: string; title: string; sections: section[] };
230+
export const base: Docs = {
231+
full: [
232+
{ ...one, content: "test" },
233+
{ ...two, content: "test2" },
234+
{ ...three, content: "test3" },
235+
],
236+
list: [one, two, three],
237+
};
226238

227-
export interface ListItem {
228-
title: string;
229-
slug: string;
230-
file: string;
231-
sections: section[];
232-
}
239+
type section = { slug: string; title: string; sections: section[] };
233240

234241
export const list: ListItem[] = [
235242
{
@@ -446,42 +453,63 @@ export const list: ListItem[] = [
446453

447454
export const cf_full = {
448455
key: "svelte@latest:docs:content",
449-
value: JSON.stringify(base),
456+
value: JSON.stringify(base.full),
450457
};
451458
export const cf_list = {
452459
key: "svelte@latest:docs:list",
453460
value: JSON.stringify(list),
454461
};
455462

456463
export const cf_contents_keyby_slug = [
457-
{ key: "svelte@latest:docs:Introduction", value: JSON.stringify(one) },
458-
{ key: "svelte@latest:docs:Introduction_2", value: JSON.stringify(two) },
459-
{ key: "svelte@latest:docs:Introduction_3", value: JSON.stringify(three) },
464+
{
465+
key: "svelte@latest:docs:Introduction",
466+
value: JSON.stringify({ ...one, content: "test" }),
467+
},
468+
{
469+
key: "svelte@latest:docs:Introduction_2",
470+
value: JSON.stringify({ ...two, content: "test2" }),
471+
},
472+
{
473+
key: "svelte@latest:docs:Introduction_3",
474+
value: JSON.stringify({ ...three, content: "test3" }),
475+
},
460476
];
461477

462478
export const cf_contents_keyby_file = [
463-
{ key: "svelte@latest:docs:00-introduction.md", value: JSON.stringify(one) },
479+
{
480+
key: "svelte@latest:docs:00-introduction.md",
481+
value: JSON.stringify({ ...one, content: "test" }),
482+
},
464483
{
465484
key: "svelte@latest:docs:00-introduction-2.md",
466-
value: JSON.stringify(two),
485+
value: JSON.stringify({ ...two, content: "test2" }),
467486
},
468487
{
469488
key: "svelte@latest:docs:00-introduction-3.md",
470-
value: JSON.stringify(three),
489+
value: JSON.stringify({ ...three, content: "test3" }),
471490
},
472491
];
473492

474493
export const cf_full_next = {
475494
key: "svelte@next:docs:content",
476-
value: JSON.stringify(base),
495+
value: JSON.stringify(base.full),
477496
};
478497
export const cf_list_next = {
479498
key: "svelte@next:docs:list",
480499
value: JSON.stringify(list),
481500
};
482501

483502
export const cf_contents_keyby_slug_next = [
484-
{ key: "svelte@next:docs:Introduction", value: JSON.stringify(one) },
485-
{ key: "svelte@next:docs:Introduction_2", value: JSON.stringify(two) },
486-
{ key: "svelte@next:docs:Introduction_3", value: JSON.stringify(three) },
503+
{
504+
key: "svelte@next:docs:Introduction",
505+
value: JSON.stringify({ ...one, content: "test" }),
506+
},
507+
{
508+
key: "svelte@next:docs:Introduction_2",
509+
value: JSON.stringify({ ...two, content: "test2" }),
510+
},
511+
{
512+
key: "svelte@next:docs:Introduction_3",
513+
value: JSON.stringify({ ...three, content: "test3" }),
514+
},
487515
];

0 commit comments

Comments
 (0)