Skip to content

Commit 36a62bb

Browse files
committed
add cloudflare key transform
1 parent cdc7e39 commit 36a62bb

File tree

7 files changed

+690
-14
lines changed

7 files changed

+690
-14
lines changed

dist/main.js

Lines changed: 60 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7884,6 +7884,38 @@ function increment_headings(source) {
78847884
return source.replace(RE_HEADING, "##$1");
78857885
}
78867886

7887+
function transform_cloudflare(
7888+
docs,
7889+
{ project, type, keyby, version = "latest" }
7890+
) {
7891+
const _list = [];
7892+
const keys = [
7893+
{
7894+
key: `${project}@${version}:${type}:content`,
7895+
value: JSON.stringify(docs),
7896+
},
7897+
];
7898+
7899+
for (let i = 0; i < docs.length; i++) {
7900+
const { content, ...rest } = docs[i];
7901+
_list.push(rest);
7902+
7903+
const item_key = docs[i][keyby];
7904+
7905+
keys.push({
7906+
key: `${project}@${version}:${type}:${item_key}`,
7907+
value: JSON.stringify(docs[i]),
7908+
});
7909+
}
7910+
7911+
keys.push({
7912+
key: `${project}@${version}:${type}:list`,
7913+
value: JSON.stringify(_list),
7914+
});
7915+
7916+
return keys;
7917+
}
7918+
78877919
async function get_repo(
78887920
target_repo,
78897921
target_branch,
@@ -7961,21 +7993,43 @@ async function run() {
79617993
core$1.setFailed("Failed to read documentation files.");
79627994
}
79637995

7964-
const formatted_pkg_docs = pkg_docs.map(([name, content]) => [
7996+
// format them
7997+
const formatted_pkg_docs
7998+
7999+
= pkg_docs.map(([name, content]) => [
79658000
name,
79668001
format_api(name, increment_headings(content), name),
79678002
]);
79688003

79698004
console.log(formatted_pkg_docs, null, 2);
79708005

7971-
const formatted_base_docs = base_docs.api.map(([name, content]) => [
7972-
name,
7973-
format_api(name, content),
7974-
]);
8006+
const formatted_base_docs = base_docs.api.map(([name, content]) =>
8007+
format_api(name, content)
8008+
);
79758009
console.log(JSON.stringify(formatted_base_docs, null, 2));
79768010

7977-
// format them
79788011
// transform to cf format (batch keys)
8012+
8013+
const docs = transform_cloudflare(formatted_base_docs, {
8014+
project: target_repo,
8015+
type: "docs",
8016+
keyby: "slug",
8017+
});
8018+
8019+
const pkgs = formatted_pkg_docs.reduce((acc, [name, _docs]) => {
8020+
const cf_doc = transform_cloudflare([_docs], {
8021+
project: name,
8022+
type: "docs",
8023+
keyby: "slug",
8024+
});
8025+
8026+
return acc.concat(cf_doc);
8027+
}, []);
8028+
8029+
console.log(docs);
8030+
console.log("\n");
8031+
console.log(pkgs);
8032+
79798033
// write to cloudflare
79808034
}
79818035

src/format/format_api.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ const make_slug = make_session_slug_processor({
1616
});
1717

1818
type section = { slug: string; title: string; sections: section[] };
19-
interface FormattedFile {
19+
export type FormattedFile = {
2020
content: string;
2121
title: string;
2222
slug: string;
2323
file: string;
2424
sections: section[];
25-
}
25+
};
2626

2727
let block_open = false;
2828

src/main.ts

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import { get_base_documentation, get_package_documentation } from "./fs";
77
import { format_api } from "./format";
88
import { increment_headings } from "./format/increment_headings";
99
import { BaseDocs } from "./fs";
10+
import { transform_cloudflare } from "./transform";
11+
import { FormattedFile } from "./format/format_api";
1012

1113
async function get_repo(
1214
target_repo: string,
@@ -85,21 +87,43 @@ async function run() {
8587
core.setFailed("Failed to read documentation files.");
8688
}
8789

88-
const formatted_pkg_docs = pkg_docs.map(([name, content]) => [
90+
// format them
91+
const formatted_pkg_docs: Array<
92+
[string, FormattedFile]
93+
> = pkg_docs.map(([name, content]) => [
8994
name,
9095
format_api(name, increment_headings(content), name),
9196
]);
9297

9398
console.log(formatted_pkg_docs, null, 2);
9499

95-
const formatted_base_docs = base_docs.api.map(([name, content]) => [
96-
name,
97-
format_api(name, content),
98-
]);
100+
const formatted_base_docs = base_docs.api.map(([name, content]) =>
101+
format_api(name, content)
102+
);
99103
console.log(JSON.stringify(formatted_base_docs, null, 2));
100104

101-
// format them
102105
// transform to cf format (batch keys)
106+
107+
const docs = transform_cloudflare(formatted_base_docs, {
108+
project: target_repo,
109+
type: "docs",
110+
keyby: "slug",
111+
});
112+
113+
const pkgs = formatted_pkg_docs.reduce((acc, [name, _docs]) => {
114+
const cf_doc = transform_cloudflare([_docs], {
115+
project: name,
116+
type: "docs",
117+
keyby: "slug",
118+
});
119+
120+
return acc.concat(cf_doc);
121+
}, []);
122+
123+
console.log(docs);
124+
console.log("\n");
125+
console.log(pkgs);
126+
103127
// write to cloudflare
104128
}
105129

0 commit comments

Comments
 (0)