tangled
alpha
login
or
join now
leaflet.pub
/
leaflet
289
fork
atom
a tool for shared writing and social publishing
289
fork
atom
overview
issues
28
pulls
pipelines
support canvas titles on homepage
awarm.space
3 months ago
5ee7a1ae
6e3be6af
+25
-4
1 changed file
expand all
collapse all
unified
split
app
api
rpc
[command]
getFactsFromHomeLeaflets.ts
+25
-4
app/api/rpc/[command]/getFactsFromHomeLeaflets.ts
···
4
4
import { makeRoute } from "../lib";
5
5
import type { Env } from "./route";
6
6
import { scanIndexLocal } from "src/replicache/utils";
7
7
-
import { getBlocksWithTypeLocal } from "src/hooks/queries/useBlocks";
8
7
import * as base64 from "base64-js";
9
8
import { YJSFragmentToString } from "components/Blocks/TextBlock/RenderYJSFragment";
10
9
import { applyUpdate, Doc } from "yjs";
···
35
34
let scan = scanIndexLocal(facts[token]);
36
35
let [root] = scan.eav(token, "root/page");
37
36
let rootEntity = root?.data.value || token;
38
38
-
let [title] = getBlocksWithTypeLocal(facts[token], rootEntity).filter(
39
39
-
(b) => b.type === "text" || b.type === "heading",
40
40
-
);
37
37
+
38
38
+
// Check page type to determine which blocks to look up
39
39
+
let [pageType] = scan.eav(rootEntity, "page/type");
40
40
+
let isCanvas = pageType?.data.value === "canvas";
41
41
+
42
42
+
// Get blocks and sort by position
43
43
+
let rawBlocks = isCanvas
44
44
+
? scan.eav(rootEntity, "canvas/block").sort((a, b) => {
45
45
+
if (a.data.position.y === b.data.position.y)
46
46
+
return a.data.position.x - b.data.position.x;
47
47
+
return a.data.position.y - b.data.position.y;
48
48
+
})
49
49
+
: scan.eav(rootEntity, "card/block").sort((a, b) => a.data.position - b.data.position);
50
50
+
51
51
+
// Map to get type and filter for text/heading
52
52
+
let blocks = rawBlocks
53
53
+
.map((b) => {
54
54
+
let type = scan.eav(b.data.value, "block/type")[0];
55
55
+
if (!type || (type.data.value !== "text" && type.data.value !== "heading")) return null;
56
56
+
return b.data;
57
57
+
})
58
58
+
.filter((b) => b !== null);
59
59
+
60
60
+
let title = blocks[0];
61
61
+
41
62
if (!title) titles[token] = "Untitled";
42
63
else {
43
64
let [content] = scan.eav(title.value, "block/text");