Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 21 additions & 10 deletions browser/websocket/makeChanges.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ export function makeChanges(
}

// リンクと画像の差分を入れる
const [linksLc, image] = findLinksAndImage(right_.join("\n"));
const [links, image] = findLinksAndImage(right_.join("\n"));
if (
head.linksLc.length !== linksLc.length ||
!head.linksLc.every((link) => linksLc.includes(link))
head.links.length !== links.length ||
!head.links.every((link) => links.includes(link))
) {
changes.push({ links: linksLc });
changes.push({ links });
}
if (head.image !== image) {
changes.push({ image });
Expand All @@ -67,19 +67,30 @@ function findLinksAndImage(text: string): [string[], string | null] {
}
});

const linksLc = [] as string[];
/** 重複判定用map
*
* bracket link とhashtagを区別できるようにしている
* - bracket linkならtrue
*
* linkの形状はbracket linkを優先している
*/
const linksLc = new Map<string, boolean>();
const links = [] as string[];
let image: string | null = null;

const lookup = (node: Node) => {
switch (node.type) {
case "hashTag":
linksLc.push(toTitleLc(node.href));
if (linksLc.has(toTitleLc(node.href))) return;
linksLc.set(toTitleLc(node.href), false);
links.push(node.href);
return;
case "link": {
case "link":
if (node.pathType !== "relative") return;
linksLc.push(toTitleLc(node.href));
if (linksLc.get(toTitleLc(node.href))) return;
linksLc.set(toTitleLc(node.href), true);
links.push(node.href);
return;
}
case "image":
case "strongImage": {
image ??= node.src.endsWith("/thumb/1000")
Expand All @@ -103,7 +114,7 @@ function findLinksAndImage(text: string): [string[], string | null] {
lookup(node);
}

return [linksLc, image];
return [links, image];
}

function* blocksToNodes(blocks: Iterable<Block>) {
Expand Down
5 changes: 2 additions & 3 deletions browser/websocket/pull.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { Line } from "../../deps/scrapbox.ts";
import { toTitleLc } from "../../title.ts";
import { getPage } from "../../rest/pages.ts";

export interface HeadData {
Expand All @@ -8,7 +7,7 @@ export interface HeadData {
persistent: boolean;
image: string | null;
pin: number;
linksLc: string[];
links: string[];
lines: Line[];
}
export async function pull(project: string, title: string): Promise<HeadData> {
Expand All @@ -25,7 +24,7 @@ export async function pull(project: string, title: string): Promise<HeadData> {
pageId: id,
persistent,
image,
linksLc: links.map((link) => toTitleLc(link)),
links,
pin,
lines,
};
Expand Down