Skip to content

Commit 48f5319

Browse files
committedSep 19, 2023
处理循环引用问题
1 parent dad5df9 commit 48f5319

File tree

3 files changed

+26
-12
lines changed

3 files changed

+26
-12
lines changed
 

‎apps/frontend/src/fs/build.ts

+19-9
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,14 @@ export async function* build(
3838
yield `=== 开始编译 ${book.name} ===`;
3939
let process = processPercentage(0.4);
4040
/** 查询所有文档级block */
41+
// TODO 需要更换成能够完全遍历一个笔记本的写法
4142
const r: DB_block[] = await API.query_sql({
4243
stmt: `
4344
SELECT *
4445
from blocks
4546
WHERE box = '${book.id}'
4647
AND type = 'd'
48+
limit 1500 OFFSET 0
4749
`,
4850
});
4951
yield `=== 查询文档级block完成 ===`;
@@ -61,14 +63,19 @@ export async function* build(
6163
const arr = Object.entries(docTree);
6264
for (let i = 0; i < arr.length; i++) {
6365
const [path, { sy }] = arr[i];
64-
docHTML[path + ".html"] = await htmlTemplate(
65-
{
66-
title: sy.Properties?.title || "",
67-
htmlContent: await renderHTML(sy),
68-
level: path.split("/").length - 2 /** 最开头有一个 / 还有一个 data 目录所以减二 */,
69-
},
70-
config.cdn,
71-
);
66+
try {
67+
docHTML[path + ".html"] = await htmlTemplate(
68+
{
69+
title: sy.Properties?.title || "",
70+
htmlContent: await renderHTML(sy),
71+
level: path.split("/").length - 2 /** 最开头有一个 / 还有一个 data 目录所以减二 */,
72+
},
73+
config.cdn,
74+
);
75+
} catch (error) {
76+
console.log(path, "渲染失败", error);
77+
}
78+
7279
process(i / arr.length);
7380
yield `渲染: ${path}`;
7481
}
@@ -123,7 +130,10 @@ async function writeFileSystem(docTree: { [htmlPath: string]: string }, dir_ref:
123130
await writeFile(dir_ref, path, html);
124131
}),
125132
);
126-
133+
// for (const [path, html] of Object.entries(docTree)) {
134+
// await writeFile(dir_ref, path, html);
135+
// console.log("写出", path);
136+
// }
127137
async function writeFile(dir_ref: any, name: string, data: string) {
128138
const pathArr = name.split("/");
129139
/** 如果路径中的目录不存在则创建 */

‎apps/frontend/src/fs/render.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@ export async function renderHTML(
1616
/** 避免让所有的 renderInstance.nodeStack 是同一个对象 ,所以这里创建一个新 [] */
1717
nodeStack: [...renderInstance.nodeStack],
1818
};
19-
19+
if (renderInstance.nodeStack.includes(sy)) {
20+
// TODO 需要返回一个更好的提示
21+
console.log("=== 递归渲染了相同的节点 ===", renderInstance.nodeStack);
22+
return "=== 递归渲染了相同的节点 ===";
23+
}
2024
if (sy.Type in render) {
2125
if (renderObj[sy.Type] === undefined) {
2226
return `=== 没有找到对应的渲染器 ${sy.Type} ${renderObj.nodeStack[0].Properties?.title}===`;
@@ -313,7 +317,7 @@ const render: { [key in keyof typeof NodeType]?: (sy: S_Node) => Promise<string>
313317
if (node === undefined) {
314318
// 一般来说是跨笔记引用
315319
// TODO 待处理跨笔记引用问题
316-
console.log("跨笔记引用", block.id, sql,node);
320+
console.log("跨笔记引用", block.id, sql, node);
317321
return "";
318322
}
319323
htmlStr += await renderHTML(node, this);

‎readme.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33
参见 [OceanPress_js 版的开发记录 ](https://ld246.com/article/1693989505448)
44

5-
[![](https://data.jsdelivr.com/v1/package/gh/siyuan-note/oceanpress/badge)](https://www.jsdelivr.com/package/gh/siyuan-note/oceanpress)
5+
[![](https://data.jsdelivr.com/v1/package/gh/siyuan-note/oceanpress/badge?style=rounded)](https://www.jsdelivr.com/package/gh/siyuan-note/oceanpress)
66

77
![](./apps/frontend/public/ocean_press-log.png)

0 commit comments

Comments
 (0)