Skip to content

Commit b020895

Browse files
committed
prepare docs for cloudflare
1 parent d109c58 commit b020895

File tree

3 files changed

+53
-1
lines changed

3 files changed

+53
-1
lines changed

dist/main.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1708,6 +1708,36 @@ async function get_docs(
17081708
);
17091709
}
17101710

1711+
function transform_cloudflare(
1712+
docs,
1713+
{ project, type, keyby, version = "latest" }
1714+
) {
1715+
const keys = [
1716+
{
1717+
key: `${project}@${version}:${type}:content`,
1718+
value: JSON.stringify(docs.full),
1719+
},
1720+
];
1721+
1722+
for (let i = 0; i < docs.full.length; i++) {
1723+
// const { content, ...rest } = docs[i];
1724+
1725+
const item_key = docs.full[i][keyby];
1726+
1727+
keys.push({
1728+
key: `${project}@${version}:${type}:${item_key}`,
1729+
value: JSON.stringify(docs.full[i]),
1730+
});
1731+
}
1732+
1733+
keys.push({
1734+
key: `${project}@${version}:${type}:list`,
1735+
value: JSON.stringify(docs.list),
1736+
});
1737+
1738+
return keys;
1739+
}
1740+
17111741
var escapeStringRegexp$1 = string => {
17121742
if (typeof string !== 'string') {
17131743
throw new TypeError('Expected a string');
@@ -26103,6 +26133,17 @@ async function run() {
2610326133

2610426134
console.log(JSON.stringify(transformed_docs, null, 2));
2610526135

26136+
const ready_for_cf = transformed_docs
26137+
.map((d) =>
26138+
d.map(({ content, project, type }) =>
26139+
//@ts-ignore
26140+
transform_cloudflare(content, { project, type, keyby: "slug" })
26141+
)
26142+
)
26143+
.flat();
26144+
26145+
console.log(JSON.stringify(ready_for_cf, null, 2));
26146+
2610626147
// if (docs.length) {
2610726148
// docs.forEach(([project, docs]) => {
2610826149
// for (const type in docs) {

src/main.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,17 @@ async function run() {
8787

8888
console.log(JSON.stringify(transformed_docs, null, 2));
8989

90+
const ready_for_cf = transformed_docs
91+
.map((d) =>
92+
d.map(({ content, project, type }) =>
93+
//@ts-ignore
94+
transform_cloudflare(content, { project, type, keyby: "slug" })
95+
)
96+
)
97+
.flat();
98+
99+
console.log(JSON.stringify(ready_for_cf, null, 2));
100+
90101
// if (docs.length) {
91102
// docs.forEach(([project, docs]) => {
92103
// for (const type in docs) {

src/transform/docs.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ interface Docs {
344344
}
345345

346346
interface TransformedDocs {
347-
content: unknown;
347+
content: Record<string, unknown>;
348348
project: string;
349349
type: string;
350350
}

0 commit comments

Comments
 (0)