noblog 0.0.10 → 0.0.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +25 -23
- package/dist/cmds/generate.js +28 -0
- package/dist/cmds/generate.js.map +1 -0
- package/dist/generate.cjs +463 -38
- package/dist/generate.cjs.map +1 -1
- package/dist/generate.js +463 -38
- package/dist/generate.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +28 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/nomd/format.d.ts +1 -0
- package/dist/lib/nomd/format.d.ts.map +1 -1
- package/dist/lib/nomd/format.js +137 -0
- package/dist/lib/nomd/format.js.map +1 -0
- package/dist/lib/nomd/nomd.d.ts +8 -3
- package/dist/lib/nomd/nomd.d.ts.map +1 -1
- package/dist/lib/nomd/nomd.js +473 -0
- package/dist/lib/nomd/nomd.js.map +1 -0
- package/dist/lib/nomd/utils.d.ts +6 -0
- package/dist/lib/nomd/utils.d.ts.map +1 -0
- package/dist/lib/nomd/utils.js +2 -0
- package/dist/lib/nomd/utils.js.map +1 -0
- package/dist/lib/notion/client.d.ts +12 -3
- package/dist/lib/notion/client.d.ts.map +1 -1
- package/dist/lib/notion/client.js +98 -0
- package/dist/lib/notion/client.js.map +1 -0
- package/dist/lib/notion/object.d.ts.map +1 -1
- package/dist/lib/notion/object.js +2 -0
- package/dist/lib/notion/object.js.map +1 -0
- package/dist/lib/notion/request.d.ts.map +1 -1
- package/dist/lib/notion/request.js +2 -0
- package/dist/lib/notion/request.js.map +1 -0
- package/package.json +44 -37
|
@@ -0,0 +1,473 @@
|
|
|
1
|
+
import * as path from "path";
|
|
2
|
+
import * as fs from "fs/promises";
|
|
3
|
+
import * as fmt from "./format.js";
|
|
4
|
+
import { GetPageMeta, GetBlockChildren, client as notion_client, } from "../notion/client.js";
|
|
5
|
+
export class Noblog {
|
|
6
|
+
Posts = [];
|
|
7
|
+
CurrPage = "";
|
|
8
|
+
SavePath = "./src/pages/posts/";
|
|
9
|
+
ChildPath = "nob_children/";
|
|
10
|
+
MdCollection = {};
|
|
11
|
+
CustomTransformers = {};
|
|
12
|
+
constructor(posts, save_path, child_path) {
|
|
13
|
+
this.Posts = posts;
|
|
14
|
+
if (child_path != undefined) {
|
|
15
|
+
this.ChildPath = child_path;
|
|
16
|
+
}
|
|
17
|
+
if (save_path != undefined) {
|
|
18
|
+
this.SavePath = save_path;
|
|
19
|
+
}
|
|
20
|
+
this.CustomTransformers["child_page"] = async (block) => {
|
|
21
|
+
const page = block;
|
|
22
|
+
if (!page?.id) {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
let sub_path;
|
|
26
|
+
// if (curr_page.id in this.Post) and (page.id in this.Post) ||
|
|
27
|
+
// (curr_page.id not in this.Post) and (page.id not in this.Post)
|
|
28
|
+
// * path should be "../pageid"
|
|
29
|
+
// if (curr_page.id in this.Post) and (page.id not in this.Post)
|
|
30
|
+
// * path should be "../save_path/pageid"
|
|
31
|
+
// if (curr_page.id not in this.Post) and (page.id in this.Post)
|
|
32
|
+
// * path should be "../../pageid"
|
|
33
|
+
const parent_surface = this.Posts.filter((post) => post.id === this.CurrPage).length > 0;
|
|
34
|
+
const child_surface = this.Posts.filter((post) => post.id === page.id).length > 0;
|
|
35
|
+
if (parent_surface === child_surface) {
|
|
36
|
+
sub_path = "";
|
|
37
|
+
}
|
|
38
|
+
else if (parent_surface) {
|
|
39
|
+
sub_path = this.ChildPath;
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
sub_path = "..";
|
|
43
|
+
}
|
|
44
|
+
const full_path = path.join("../", sub_path, page.id);
|
|
45
|
+
return `&[${page.child_page.title}](${full_path})`;
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
async Collect(recur = true) {
|
|
49
|
+
const save_dir = this.SavePath;
|
|
50
|
+
const sub_dir = path.join(save_dir, this.ChildPath);
|
|
51
|
+
for (const page of this.Posts) {
|
|
52
|
+
await this.FromPageid(page.id, recur);
|
|
53
|
+
}
|
|
54
|
+
try {
|
|
55
|
+
for (const pageid of Object.keys(this.MdCollection)) {
|
|
56
|
+
let fpath = sub_dir;
|
|
57
|
+
if (this.Posts.find((page) => page.id === pageid))
|
|
58
|
+
fpath = save_dir;
|
|
59
|
+
await this.SaveJelly(pageid + ".md", fpath, this.MdCollection[pageid]);
|
|
60
|
+
}
|
|
61
|
+
console.log(`success: finish dump all files to "${save_dir}"`);
|
|
62
|
+
}
|
|
63
|
+
catch (error) {
|
|
64
|
+
if (error instanceof Error) {
|
|
65
|
+
console.log(`failed: consider run verbose with v=true - ${error.message}`);
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
console.log("failed: an unknown error occurred");
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
async FromBlocks(blocks, recursive) {
|
|
73
|
+
const jelly = { content: "", children: [] };
|
|
74
|
+
for (const block of blocks) {
|
|
75
|
+
const subjelly = await this.FromBlocks(block.children, recursive);
|
|
76
|
+
if (block.type === "toggle") {
|
|
77
|
+
jelly.content += fmt.toggle(block.parent, subjelly.content);
|
|
78
|
+
jelly.children = [...jelly.children, ...subjelly.children];
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
let line_wrap = "";
|
|
82
|
+
if (block.type !== "to_do" &&
|
|
83
|
+
block.type !== "bulleted_list_item" &&
|
|
84
|
+
block.type !== "numbered_list_item") {
|
|
85
|
+
line_wrap = "\n";
|
|
86
|
+
}
|
|
87
|
+
jelly.content +=
|
|
88
|
+
line_wrap + `${fmt.addTabSpace(block.parent, 0)}\n` + line_wrap;
|
|
89
|
+
if (block.type === "child_page") {
|
|
90
|
+
jelly.children = [...jelly.children, block.blockId];
|
|
91
|
+
if (recursive)
|
|
92
|
+
await this.FromPageid(block.blockId, recursive);
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
jelly.content += subjelly.content;
|
|
96
|
+
jelly.children = [...jelly.children, ...subjelly.children];
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return jelly;
|
|
100
|
+
}
|
|
101
|
+
async FromPageid(page_id, recursive = true) {
|
|
102
|
+
// preserve the curr page info
|
|
103
|
+
const prev_page = this.CurrPage;
|
|
104
|
+
this.CurrPage = page_id;
|
|
105
|
+
if (this.MdCollection.hasOwnProperty(page_id)) {
|
|
106
|
+
return this.MdCollection[page_id];
|
|
107
|
+
}
|
|
108
|
+
const blocks = await this.PageToMarkdown(page_id);
|
|
109
|
+
const jelly = await this.FromBlocks(blocks, recursive);
|
|
110
|
+
const meta = await GetPageMeta(page_id);
|
|
111
|
+
const astro_meta = await this.AssembleAstroFrontmatter(meta);
|
|
112
|
+
jelly.content = astro_meta + jelly.content;
|
|
113
|
+
this.MdCollection[page_id] = jelly;
|
|
114
|
+
// restore the prev page info
|
|
115
|
+
this.CurrPage = prev_page;
|
|
116
|
+
return jelly;
|
|
117
|
+
}
|
|
118
|
+
async PageToMarkdown(id, totalPage) {
|
|
119
|
+
if (!notion_client) {
|
|
120
|
+
throw new Error("notion client is not provided, for more details check out https://github.com/souvikinator/notion-to-md");
|
|
121
|
+
}
|
|
122
|
+
const blocks = await GetBlockChildren(id, totalPage);
|
|
123
|
+
const parsedData = await this.BlocksToMarkdown(blocks);
|
|
124
|
+
return parsedData;
|
|
125
|
+
}
|
|
126
|
+
async BlocksToMarkdown(blocks, totalPage = null, mdBlocks = []) {
|
|
127
|
+
if (!notion_client) {
|
|
128
|
+
throw new Error("notion client is not provided, for more details check out https://github.com/souvikinator/notion-to-md");
|
|
129
|
+
}
|
|
130
|
+
if (!mdBlocks)
|
|
131
|
+
mdBlocks = [];
|
|
132
|
+
if (!blocks)
|
|
133
|
+
return mdBlocks;
|
|
134
|
+
for (let i = 0; i < blocks.length; i++) {
|
|
135
|
+
const block = blocks[i];
|
|
136
|
+
if (
|
|
137
|
+
// @ts-ignore
|
|
138
|
+
block.type === "unsupported") {
|
|
139
|
+
continue;
|
|
140
|
+
}
|
|
141
|
+
if ("has_children" in block && block.has_children) {
|
|
142
|
+
const block_id = block.type == "synced_block" &&
|
|
143
|
+
block.synced_block?.synced_from?.block_id
|
|
144
|
+
? block.synced_block.synced_from.block_id
|
|
145
|
+
: block.id;
|
|
146
|
+
// Get children of this block.
|
|
147
|
+
const child_blocks = await GetBlockChildren(block_id, totalPage);
|
|
148
|
+
// Recursively call BlocksToMarkdown to get children of this block.
|
|
149
|
+
// check for custom transformer before parsing child
|
|
150
|
+
if (!(block.type in this.CustomTransformers) &&
|
|
151
|
+
!this.CustomTransformers[block.type]) {
|
|
152
|
+
const l = mdBlocks.length;
|
|
153
|
+
if (mdBlocks !== undefined) {
|
|
154
|
+
await this.BlocksToMarkdown(child_blocks, totalPage, mdBlocks[l - 1]?.children);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
// Push this block to mdBlocks.
|
|
158
|
+
mdBlocks.push({
|
|
159
|
+
type: block.type,
|
|
160
|
+
blockId: block.id,
|
|
161
|
+
parent: await this.BlockToMarkdown(block),
|
|
162
|
+
children: [],
|
|
163
|
+
});
|
|
164
|
+
continue;
|
|
165
|
+
}
|
|
166
|
+
const tmp = await this.BlockToMarkdown(block);
|
|
167
|
+
mdBlocks.push({
|
|
168
|
+
// @ts-ignore
|
|
169
|
+
type: block.type,
|
|
170
|
+
blockId: block.id,
|
|
171
|
+
parent: tmp,
|
|
172
|
+
children: [],
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
return mdBlocks;
|
|
176
|
+
}
|
|
177
|
+
async BlockToMarkdown(block) {
|
|
178
|
+
if (typeof block !== "object" || !("type" in block))
|
|
179
|
+
return "";
|
|
180
|
+
let parsedData = "";
|
|
181
|
+
const { type } = block;
|
|
182
|
+
if (type in this.CustomTransformers && !!this.CustomTransformers[type]) {
|
|
183
|
+
const transformer = this.CustomTransformers[type];
|
|
184
|
+
const customTransformerValue = transformer(block);
|
|
185
|
+
if (typeof customTransformerValue === "string")
|
|
186
|
+
return customTransformerValue;
|
|
187
|
+
}
|
|
188
|
+
switch (type) {
|
|
189
|
+
case "image":
|
|
190
|
+
const blockContent = block.image;
|
|
191
|
+
let image_title = "image";
|
|
192
|
+
const image_caption_plain = blockContent.caption
|
|
193
|
+
.map((item) => item.plain_text)
|
|
194
|
+
.join("");
|
|
195
|
+
let link = "";
|
|
196
|
+
const image_type = blockContent.type;
|
|
197
|
+
if (image_type === "external") {
|
|
198
|
+
link = blockContent.external.url;
|
|
199
|
+
}
|
|
200
|
+
if (image_type === "file") {
|
|
201
|
+
link = blockContent.file.url;
|
|
202
|
+
}
|
|
203
|
+
// image caption with high priority
|
|
204
|
+
if (image_caption_plain.trim().length > 0) {
|
|
205
|
+
image_title = image_caption_plain;
|
|
206
|
+
}
|
|
207
|
+
else if (image_type === "file" || image_type === "external") {
|
|
208
|
+
const matches = link.match(/[^\/\\&\?]+\.\w{3,4}(?=([\?&].*$|$))/);
|
|
209
|
+
image_title = matches ? matches[0] : image_title;
|
|
210
|
+
}
|
|
211
|
+
return await fmt.image(image_title, link, false);
|
|
212
|
+
case "divider":
|
|
213
|
+
return fmt.divider();
|
|
214
|
+
case "equation":
|
|
215
|
+
return fmt.equation(block.equation.expression);
|
|
216
|
+
case "pdf":
|
|
217
|
+
case "file":
|
|
218
|
+
case "video":
|
|
219
|
+
{
|
|
220
|
+
let blockContent;
|
|
221
|
+
let title = type;
|
|
222
|
+
if (type === "pdf")
|
|
223
|
+
blockContent = block.pdf;
|
|
224
|
+
if (type === "file")
|
|
225
|
+
blockContent = block.file;
|
|
226
|
+
if (type === "video")
|
|
227
|
+
blockContent = block.video;
|
|
228
|
+
const caption = blockContent?.caption
|
|
229
|
+
.map((item) => item.plain_text)
|
|
230
|
+
.join("");
|
|
231
|
+
if (blockContent) {
|
|
232
|
+
const file_type = blockContent.type;
|
|
233
|
+
let link = "";
|
|
234
|
+
if (file_type === "file")
|
|
235
|
+
link = blockContent.file.url;
|
|
236
|
+
if (file_type === "external")
|
|
237
|
+
link = blockContent.external.url;
|
|
238
|
+
if (caption && caption.trim().length > 0) {
|
|
239
|
+
title = caption;
|
|
240
|
+
}
|
|
241
|
+
else if (link) {
|
|
242
|
+
const matches = link.match(/[^\/\\&\?]+\.\w{3,4}(?=([\?&].*$|$))/);
|
|
243
|
+
title = matches ? matches[0] : type;
|
|
244
|
+
}
|
|
245
|
+
return fmt.link(title, link);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
break;
|
|
249
|
+
case "embed":
|
|
250
|
+
case "bookmark":
|
|
251
|
+
case "link_preview":
|
|
252
|
+
case "link_to_page":
|
|
253
|
+
{
|
|
254
|
+
let blockContent;
|
|
255
|
+
const title = type;
|
|
256
|
+
if (type === "embed")
|
|
257
|
+
blockContent = block.embed;
|
|
258
|
+
if (type === "bookmark")
|
|
259
|
+
blockContent = block.bookmark;
|
|
260
|
+
if (type === "link_preview")
|
|
261
|
+
blockContent = block.link_preview;
|
|
262
|
+
if (type === "link_to_page" &&
|
|
263
|
+
block.link_to_page.type === "page_id") {
|
|
264
|
+
blockContent = {
|
|
265
|
+
url: `https://www.notion.so/${block.link_to_page.page_id}`,
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
if (blockContent)
|
|
269
|
+
return fmt.link(title, blockContent.url);
|
|
270
|
+
}
|
|
271
|
+
break;
|
|
272
|
+
case "child_page": {
|
|
273
|
+
const pageTitle = block.child_page.title;
|
|
274
|
+
return fmt.heading2(pageTitle);
|
|
275
|
+
}
|
|
276
|
+
case "child_database": {
|
|
277
|
+
const pageTitle = block.child_database.title || `child_database`;
|
|
278
|
+
return fmt.heading2(pageTitle);
|
|
279
|
+
}
|
|
280
|
+
case "table": {
|
|
281
|
+
const { id, has_children } = block;
|
|
282
|
+
const tableArr = [];
|
|
283
|
+
if (has_children) {
|
|
284
|
+
const tableRows = await GetBlockChildren(id, 100);
|
|
285
|
+
const rowsPromise = tableRows?.map(async (row) => {
|
|
286
|
+
const { type } = row;
|
|
287
|
+
const cells = row[type]["cells"];
|
|
288
|
+
/**
|
|
289
|
+
* this is more like a hack since matching the type text was
|
|
290
|
+
* difficult. So converting each cell to paragraph type to
|
|
291
|
+
* reuse the BlockToMarkdown function
|
|
292
|
+
*/
|
|
293
|
+
const cellStringPromise = cells.map(async (cell) => await this.BlockToMarkdown({
|
|
294
|
+
type: "paragraph",
|
|
295
|
+
paragraph: { rich_text: cell },
|
|
296
|
+
}));
|
|
297
|
+
const cellStringArr = await Promise.all(cellStringPromise);
|
|
298
|
+
tableArr.push(cellStringArr);
|
|
299
|
+
});
|
|
300
|
+
await Promise.all(rowsPromise || []);
|
|
301
|
+
}
|
|
302
|
+
return fmt.table(tableArr);
|
|
303
|
+
}
|
|
304
|
+
// Rest of the types:
|
|
305
|
+
// "paragraph" "heading_1" "heading_2" "heading_3"
|
|
306
|
+
// "bulleted_list_item" "numbered_list_item"
|
|
307
|
+
// "quote" "to_do" "template" "synced_block"
|
|
308
|
+
// "child_page" "child_database" "code" "callout" "breadcrumb"
|
|
309
|
+
// "table_of_contents" "link_to_page" "audio" "unsupported"
|
|
310
|
+
default: {
|
|
311
|
+
// @ts-ignore
|
|
312
|
+
const blockContent = block[type].text || block[type].rich_text || [];
|
|
313
|
+
const bucket = [];
|
|
314
|
+
const code_range = [];
|
|
315
|
+
const bold_range = [];
|
|
316
|
+
const italic_range = [];
|
|
317
|
+
const underline_range = [];
|
|
318
|
+
const strikethrough_range = [];
|
|
319
|
+
const push_or_merge = (arr, idx) => {
|
|
320
|
+
if (arr.length == 0) {
|
|
321
|
+
return;
|
|
322
|
+
}
|
|
323
|
+
// @ts-ignore
|
|
324
|
+
if (arr[arr.length - 1][1] === idx) {
|
|
325
|
+
// @ts-ignore
|
|
326
|
+
arr[arr.length - 1][1] += 1;
|
|
327
|
+
}
|
|
328
|
+
else {
|
|
329
|
+
arr.push([idx, idx + 1]);
|
|
330
|
+
}
|
|
331
|
+
};
|
|
332
|
+
for (let i = 0; i < blockContent.length; i++) {
|
|
333
|
+
const content = blockContent[i];
|
|
334
|
+
if (content.type === "equation") {
|
|
335
|
+
bucket.push(fmt.inlineEquation(content.equation.expression));
|
|
336
|
+
continue;
|
|
337
|
+
}
|
|
338
|
+
let plain_text = content.plain_text;
|
|
339
|
+
if (content["href"])
|
|
340
|
+
plain_text = fmt.link(plain_text, content["href"]);
|
|
341
|
+
bucket.push(plain_text);
|
|
342
|
+
const annotations = content.annotations;
|
|
343
|
+
if (annotations.code)
|
|
344
|
+
push_or_merge(code_range, i);
|
|
345
|
+
if (annotations.bold)
|
|
346
|
+
push_or_merge(bold_range, i);
|
|
347
|
+
if (annotations.italic)
|
|
348
|
+
push_or_merge(italic_range, i);
|
|
349
|
+
if (annotations.underline)
|
|
350
|
+
push_or_merge(underline_range, i);
|
|
351
|
+
if (annotations.strikethrough)
|
|
352
|
+
push_or_merge(strikethrough_range, i);
|
|
353
|
+
}
|
|
354
|
+
const annoed_bucket = [];
|
|
355
|
+
for (const range of code_range)
|
|
356
|
+
annoed_bucket.push({ range: range, type: "code" });
|
|
357
|
+
for (const range of bold_range)
|
|
358
|
+
annoed_bucket.push({ range: range, type: "bold" });
|
|
359
|
+
for (const range of italic_range)
|
|
360
|
+
annoed_bucket.push({ range: range, type: "italic" });
|
|
361
|
+
for (const range of underline_range)
|
|
362
|
+
annoed_bucket.push({ range: range, type: "underline" });
|
|
363
|
+
for (const range of strikethrough_range)
|
|
364
|
+
annoed_bucket.push({ range: range, type: "strikethrough" });
|
|
365
|
+
annoed_bucket.sort(
|
|
366
|
+
// @ts-ignore
|
|
367
|
+
(a, b) => a.range[1] - a.range[0] - (b.range[1] - b.range[0]));
|
|
368
|
+
for (const annoed of annoed_bucket) {
|
|
369
|
+
const type = annoed.type;
|
|
370
|
+
const [from, to] = annoed.range;
|
|
371
|
+
let panno, sanno = fmt.GetPrefixSuffix(type);
|
|
372
|
+
// @ts-ignore
|
|
373
|
+
bucket[from] = panno + bucket[from];
|
|
374
|
+
// @ts-ignore
|
|
375
|
+
bucket[to - 1] = bucket[to - 1] + sanno;
|
|
376
|
+
}
|
|
377
|
+
bucket.forEach((x) => (parsedData += x));
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
switch (type) {
|
|
381
|
+
case "code":
|
|
382
|
+
parsedData = fmt.codeBlock(parsedData, block[type].language);
|
|
383
|
+
break;
|
|
384
|
+
case "heading_1":
|
|
385
|
+
parsedData = fmt.heading1(parsedData);
|
|
386
|
+
break;
|
|
387
|
+
case "heading_2":
|
|
388
|
+
parsedData = fmt.heading2(parsedData);
|
|
389
|
+
break;
|
|
390
|
+
case "heading_3":
|
|
391
|
+
parsedData = fmt.heading3(parsedData);
|
|
392
|
+
break;
|
|
393
|
+
case "quote":
|
|
394
|
+
parsedData = fmt.quote(parsedData);
|
|
395
|
+
break;
|
|
396
|
+
case "callout":
|
|
397
|
+
const { id, has_children } = block;
|
|
398
|
+
let callout_string = "";
|
|
399
|
+
if (!has_children) {
|
|
400
|
+
return fmt.callout(parsedData, block[type].icon);
|
|
401
|
+
}
|
|
402
|
+
const callout_children_object = await GetBlockChildren(id, 100);
|
|
403
|
+
const callout_children = await this.BlocksToMarkdown(callout_children_object);
|
|
404
|
+
callout_string += `${parsedData}\n`;
|
|
405
|
+
callout_children.map((child) => {
|
|
406
|
+
callout_string += `${child.parent}\n\n`;
|
|
407
|
+
});
|
|
408
|
+
parsedData = fmt.callout(callout_string.trim(), block[type].icon);
|
|
409
|
+
break;
|
|
410
|
+
case "bulleted_list_item":
|
|
411
|
+
parsedData = fmt.bullet(parsedData);
|
|
412
|
+
break;
|
|
413
|
+
case "numbered_list_item":
|
|
414
|
+
parsedData = fmt.bullet(parsedData, block.numbered_list_item.number);
|
|
415
|
+
break;
|
|
416
|
+
case "to_do":
|
|
417
|
+
parsedData = fmt.todo(parsedData, block.to_do.checked);
|
|
418
|
+
break;
|
|
419
|
+
}
|
|
420
|
+
return parsedData;
|
|
421
|
+
}
|
|
422
|
+
async SaveJelly(fname, dir, jelly) {
|
|
423
|
+
if (jelly === undefined)
|
|
424
|
+
return `failed: ${fname} has empty jelly: `;
|
|
425
|
+
try {
|
|
426
|
+
await fs.mkdir(dir, { recursive: true });
|
|
427
|
+
const filePath = path.join(dir, fname);
|
|
428
|
+
await fs.writeFile(filePath, jelly.content, "utf-8");
|
|
429
|
+
return `success: ${fname} saved to ${filePath}`;
|
|
430
|
+
}
|
|
431
|
+
catch (error) {
|
|
432
|
+
if (error instanceof Error) {
|
|
433
|
+
return `failed: ${fname} - ${error.message}`;
|
|
434
|
+
}
|
|
435
|
+
else {
|
|
436
|
+
return "failed: an unknown error occurred";
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
async AssembleAstroFrontmatter(page) {
|
|
441
|
+
let frontmatter = "";
|
|
442
|
+
// default layout
|
|
443
|
+
const ischild = this.Posts.filter((post) => post.id === page.id).length > 0 ? "" : "../";
|
|
444
|
+
frontmatter +=
|
|
445
|
+
"layout: " + ischild + "../../layouts/MarkdownPostLayout.astro" + "\n";
|
|
446
|
+
// get title
|
|
447
|
+
frontmatter +=
|
|
448
|
+
"title: " +
|
|
449
|
+
JSON.stringify(page.properties.title?.title?.[0]?.plain_text ?? "") +
|
|
450
|
+
"\n";
|
|
451
|
+
// get tags
|
|
452
|
+
frontmatter +=
|
|
453
|
+
"tags: " +
|
|
454
|
+
JSON.stringify((page.properties.tags?.multi_select ?? []).map((tag) => tag.name)) +
|
|
455
|
+
"\n";
|
|
456
|
+
// get date
|
|
457
|
+
frontmatter +=
|
|
458
|
+
"pubDate: " +
|
|
459
|
+
(page.properties.date?.date?.start ??
|
|
460
|
+
new Date().toISOString().split("T")[0]) +
|
|
461
|
+
"\n";
|
|
462
|
+
// get archived
|
|
463
|
+
frontmatter +=
|
|
464
|
+
"archived: " + (page.properties.archived ? "true" : "false") + "\n";
|
|
465
|
+
// get description
|
|
466
|
+
frontmatter +=
|
|
467
|
+
"description: " +
|
|
468
|
+
JSON.stringify(page.properties.description?.rich_text?.[0]?.plain_text ?? "") +
|
|
469
|
+
"\n";
|
|
470
|
+
return "---\n" + frontmatter + "---\n";
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
//# sourceMappingURL=nomd.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nomd.js","sourceRoot":"","sources":["../../../src/lib/nomd/nomd.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,KAAK,EAAE,MAAM,aAAa,CAAC;AAClC,OAAO,KAAK,GAAG,MAAM,aAAa,CAAC;AAEnC,OAAO,EACL,WAAW,EACX,gBAAgB,EAChB,MAAM,IAAI,aAAa,GAGxB,MAAM,qBAAqB,CAAC;AAqB7B,MAAM,OAAO,MAAM;IACjB,KAAK,GAAW,EAAE,CAAC;IACnB,QAAQ,GAAW,EAAE,CAAC;IACtB,QAAQ,GAAW,oBAAoB,CAAC;IACxC,SAAS,GAAW,eAAe,CAAC;IACpC,YAAY,GAA4B,EAAE,CAAC;IAC3C,kBAAkB,GAAsC,EAAE,CAAC;IAE3D,YAAY,KAAa,EAAE,SAAkB,EAAE,UAAmB;QAChE,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,UAAU,IAAI,SAAS,EAAE,CAAC;YAC5B,IAAI,CAAC,SAAS,GAAG,UAAU,CAAC;QAC9B,CAAC;QACD,IAAI,SAAS,IAAI,SAAS,EAAE,CAAC;YAC3B,IAAI,CAAC,QAAQ,GAAG,SAAS,CAAC;QAC5B,CAAC;QAED,IAAI,CAAC,kBAAkB,CAAC,YAAY,CAAC,GAAG,KAAK,EAAE,KAAK,EAAE,EAAE;YACtD,MAAM,IAAI,GAAG,KAAY,CAAC;YAC1B,IAAI,CAAC,IAAI,EAAE,EAAE,EAAE,CAAC;gBACd,OAAO,KAAK,CAAC;YACf,CAAC;YAED,IAAI,QAAQ,CAAC;YAEb,+DAA+D;YAC/D,oEAAoE;YACpE,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YAAY,GAAG,CAAC,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC;QACtE,kBAAkB;QAClB,WAAW;YACT,eAAe;gBACf,IAAI,CAAC,SAAS,CACZ,IAAI,CAAC,UAAU,CAAC,WAAW,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC,EAAE,UAAU,IAAI,EAAE,CAC9D;gBACD,IAAI,CAAC;QACP,OAAO,OAAO,GAAG,WAAW,GAAG,OAAO,CAAC;IACzC,CAAC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/lib/nomd/utils.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,KAAK,GAAG,CAAC,MAAM,GAAG,KAAK,EAAE,MAAM,GAAG,KAAK,CAAC,CAAC;AACrD,MAAM,MAAM,cAAc,GAAG;IAC3B,KAAK,EAAE,KAAK,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/lib/nomd/utils.ts"],"names":[],"mappings":""}
|
|
@@ -1,7 +1,16 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { Client } from
|
|
3
|
-
import type { Page } from
|
|
1
|
+
import "dotenv/config";
|
|
2
|
+
import { Client } from "@notionhq/client";
|
|
3
|
+
import type { Page } from "./object.js";
|
|
4
|
+
import type { ListBlockChildrenResponse } from "@notionhq/client/build/src/api-endpoints.js";
|
|
4
5
|
export declare const client: Client;
|
|
5
6
|
export declare function GetAllPosts(): Promise<Page[]>;
|
|
6
7
|
export declare function GetPageMeta(page_id: string): Promise<Page>;
|
|
8
|
+
export declare function GetBlockChildren(block_id: string, totalPage: number | null | undefined): Promise<ListBlockChildrenResponseResults>;
|
|
9
|
+
export type BlockAttributes = {
|
|
10
|
+
numbered_list_item?: {
|
|
11
|
+
number?: number;
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
export type ListBlockChildrenResponseResult = ListBlockChildrenResponseResults[0] & BlockAttributes;
|
|
15
|
+
export type ListBlockChildrenResponseResults = ListBlockChildrenResponse["results"] & BlockAttributes;
|
|
7
16
|
//# sourceMappingURL=client.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../src/lib/notion/client.ts"],"names":[],"mappings":"AAAA,OAAO,eAAe,
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../src/lib/notion/client.ts"],"names":[],"mappings":"AAAA,OAAO,eAAe,CAAC;AAEvB,OAAO,EAAE,MAAM,EAAoB,MAAM,kBAAkB,CAAC;AAG5D,OAAO,KAAK,EAAE,IAAI,EAAyB,MAAM,aAAa,CAAC;AAC/D,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,6CAA6C,CAAC;AAK7F,eAAO,MAAM,MAAM,QAEjB,CAAC;AAIH,wBAAsB,WAAW,IAAI,OAAO,CAAC,IAAI,EAAE,CAAC,CAgDnD;AAED,wBAAsB,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAiBhE;AAED,wBAAsB,gBAAgB,CACpC,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,6CAsBrC;AAGD,MAAM,MAAM,eAAe,GAAG;IAC5B,kBAAkB,CAAC,EAAE;QACnB,MAAM,CAAC,EAAE,MAAM,CAAC;KACjB,CAAC;CACH,CAAC;AAEF,MAAM,MAAM,+BAA+B,GACzC,gCAAgC,CAAC,CAAC,CAAC,GAAG,eAAe,CAAC;AAExD,MAAM,MAAM,gCAAgC,GAC1C,yBAAyB,CAAC,SAAS,CAAC,GAAG,eAAe,CAAC"}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import "dotenv/config";
|
|
2
|
+
import retry from "async-retry";
|
|
3
|
+
import { Client, APIResponseError } from "@notionhq/client";
|
|
4
|
+
const NOTION_API_SECRET = process.env.NOTION_API_SECRET ?? "";
|
|
5
|
+
const NOBLOG_DATABASE_ID = process.env.NOBLOG_DATABASE_ID ?? "";
|
|
6
|
+
export const client = new Client({
|
|
7
|
+
auth: NOTION_API_SECRET,
|
|
8
|
+
});
|
|
9
|
+
const numberOfRetry = 2;
|
|
10
|
+
export async function GetAllPosts() {
|
|
11
|
+
const params = {
|
|
12
|
+
database_id: NOBLOG_DATABASE_ID,
|
|
13
|
+
filter: {
|
|
14
|
+
and: [
|
|
15
|
+
{
|
|
16
|
+
property: "publish",
|
|
17
|
+
checkbox: { equals: true },
|
|
18
|
+
},
|
|
19
|
+
],
|
|
20
|
+
},
|
|
21
|
+
sorts: [
|
|
22
|
+
{
|
|
23
|
+
property: "date",
|
|
24
|
+
direction: "descending",
|
|
25
|
+
},
|
|
26
|
+
],
|
|
27
|
+
page_size: 100,
|
|
28
|
+
};
|
|
29
|
+
let results = [];
|
|
30
|
+
while (true) {
|
|
31
|
+
const res = await retry(async (bail) => {
|
|
32
|
+
try {
|
|
33
|
+
return (await client.databases.query(params));
|
|
34
|
+
}
|
|
35
|
+
catch (error) {
|
|
36
|
+
if (error instanceof APIResponseError) {
|
|
37
|
+
if (error.status && error.status >= 400 && error.status < 500) {
|
|
38
|
+
bail(error);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
throw error;
|
|
42
|
+
}
|
|
43
|
+
}, { retries: numberOfRetry });
|
|
44
|
+
results = results.concat(res.results);
|
|
45
|
+
if (!res.has_more) {
|
|
46
|
+
break;
|
|
47
|
+
}
|
|
48
|
+
params["start_cursor"] = res.next_cursor;
|
|
49
|
+
}
|
|
50
|
+
return results;
|
|
51
|
+
}
|
|
52
|
+
export async function GetPageMeta(page_id) {
|
|
53
|
+
const result = await retry(async (bail) => {
|
|
54
|
+
try {
|
|
55
|
+
return (await client.pages.retrieve({ page_id: page_id }));
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
if (error instanceof APIResponseError) {
|
|
59
|
+
if (error.status && error.status >= 400 && error.status < 500) {
|
|
60
|
+
bail(error);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
throw error;
|
|
64
|
+
}
|
|
65
|
+
}, { retries: numberOfRetry });
|
|
66
|
+
return result;
|
|
67
|
+
}
|
|
68
|
+
export async function GetBlockChildren(block_id, totalPage) {
|
|
69
|
+
const result = [];
|
|
70
|
+
let pageCount = 0;
|
|
71
|
+
let start_cursor = undefined;
|
|
72
|
+
do {
|
|
73
|
+
const response = (await client.blocks.children.list({
|
|
74
|
+
start_cursor: start_cursor,
|
|
75
|
+
block_id: block_id,
|
|
76
|
+
}));
|
|
77
|
+
result.push(...response.results);
|
|
78
|
+
start_cursor = response?.next_cursor;
|
|
79
|
+
pageCount += 1;
|
|
80
|
+
} while (start_cursor != null &&
|
|
81
|
+
(totalPage == null || pageCount < totalPage));
|
|
82
|
+
ModifyNumberedListObject(result);
|
|
83
|
+
return result;
|
|
84
|
+
}
|
|
85
|
+
function ModifyNumberedListObject(blocks) {
|
|
86
|
+
let numberedListIndex = 0;
|
|
87
|
+
for (const block of blocks) {
|
|
88
|
+
if ("type" in block && block.type === "numbered_list_item") {
|
|
89
|
+
// add numbers
|
|
90
|
+
// @ts-ignore
|
|
91
|
+
block.numbered_list_item.number = ++numberedListIndex;
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
numberedListIndex = 0;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../../src/lib/notion/client.ts"],"names":[],"mappings":"AAAA,OAAO,eAAe,CAAC;AACvB,OAAO,KAAK,MAAM,aAAa,CAAC;AAChC,OAAO,EAAE,MAAM,EA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