Skip to content

Commit

Permalink
处理循环引用问题
Browse files Browse the repository at this point in the history
  • Loading branch information
2234839 committed Sep 19, 2023
1 parent dad5df9 commit 48f5319
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 12 deletions.
28 changes: 19 additions & 9 deletions apps/frontend/src/fs/build.ts
Expand Up @@ -38,12 +38,14 @@ export async function* build(
yield `=== 开始编译 ${book.name} ===`;
let process = processPercentage(0.4);
/** 查询所有文档级block */
// TODO 需要更换成能够完全遍历一个笔记本的写法
const r: DB_block[] = await API.query_sql({
stmt: `
SELECT *
from blocks
WHERE box = '${book.id}'
AND type = 'd'
limit 1500 OFFSET 0
`,
});
yield `=== 查询文档级block完成 ===`;
Expand All @@ -61,14 +63,19 @@ export async function* build(
const arr = Object.entries(docTree);
for (let i = 0; i < arr.length; i++) {
const [path, { sy }] = arr[i];
docHTML[path + ".html"] = await htmlTemplate(
{
title: sy.Properties?.title || "",
htmlContent: await renderHTML(sy),
level: path.split("/").length - 2 /** 最开头有一个 / 还有一个 data 目录所以减二 */,
},
config.cdn,
);
try {
docHTML[path + ".html"] = await htmlTemplate(
{
title: sy.Properties?.title || "",
htmlContent: await renderHTML(sy),
level: path.split("/").length - 2 /** 最开头有一个 / 还有一个 data 目录所以减二 */,
},
config.cdn,
);
} catch (error) {
console.log(path, "渲染失败", error);
}

process(i / arr.length);
yield `渲染: ${path}`;
}
Expand Down Expand Up @@ -123,7 +130,10 @@ async function writeFileSystem(docTree: { [htmlPath: string]: string }, dir_ref:
await writeFile(dir_ref, path, html);
}),
);

// for (const [path, html] of Object.entries(docTree)) {
// await writeFile(dir_ref, path, html);
// console.log("写出", path);
// }
async function writeFile(dir_ref: any, name: string, data: string) {
const pathArr = name.split("/");
/** 如果路径中的目录不存在则创建 */
Expand Down
8 changes: 6 additions & 2 deletions apps/frontend/src/fs/render.ts
Expand Up @@ -16,7 +16,11 @@ export async function renderHTML(
/** 避免让所有的 renderInstance.nodeStack 是同一个对象 ,所以这里创建一个新 [] */
nodeStack: [...renderInstance.nodeStack],
};

if (renderInstance.nodeStack.includes(sy)) {
// TODO 需要返回一个更好的提示
console.log("=== 递归渲染了相同的节点 ===", renderInstance.nodeStack);
return "=== 递归渲染了相同的节点 ===";
}
if (sy.Type in render) {
if (renderObj[sy.Type] === undefined) {
return `=== 没有找到对应的渲染器 ${sy.Type} ${renderObj.nodeStack[0].Properties?.title}===`;
Expand Down Expand Up @@ -313,7 +317,7 @@ const render: { [key in keyof typeof NodeType]?: (sy: S_Node) => Promise<string>
if (node === undefined) {
// 一般来说是跨笔记引用
// TODO 待处理跨笔记引用问题
console.log("跨笔记引用", block.id, sql,node);
console.log("跨笔记引用", block.id, sql, node);
return "";
}
htmlStr += await renderHTML(node, this);
Expand Down
2 changes: 1 addition & 1 deletion readme.md
Expand Up @@ -2,6 +2,6 @@

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

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

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

0 comments on commit 48f5319

Please sign in to comment.