From 19d5f3d6c32fcf9065af78f5c1b966a3c74ba5f7 Mon Sep 17 00:00:00 2001 From: takker99 <37929109+takker99@users.noreply.github.com> Date: Tue, 1 Mar 2022 07:07:28 +0900 Subject: [PATCH 1/2] :sparkles: preserve the letter type of links --- browser/websocket/makeChanges.ts | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/browser/websocket/makeChanges.ts b/browser/websocket/makeChanges.ts index 2dd0758..9e5887d 100644 --- a/browser/websocket/makeChanges.ts +++ b/browser/websocket/makeChanges.ts @@ -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.linksLc.length !== links.length || + !head.linksLc.every((link) => links.includes(link)) ) { - changes.push({ links: linksLc }); + changes.push({ links }); } if (head.image !== image) { changes.push({ image }); @@ -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(); + 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") @@ -103,7 +114,7 @@ function findLinksAndImage(text: string): [string[], string | null] { lookup(node); } - return [linksLc, image]; + return [links, image]; } function* blocksToNodes(blocks: Iterable) { From b20054e62225aa8c75ff6680d14ef7b17b2bb1c7 Mon Sep 17 00:00:00 2001 From: takker99 <37929109+takker99@users.noreply.github.com> Date: Tue, 1 Mar 2022 07:10:12 +0900 Subject: [PATCH 2/2] =?UTF-8?q?:+1:=20case=20sensitive=E3=81=AB=E3=83=AA?= =?UTF-8?q?=E3=83=B3=E3=82=AF=E3=81=AE=E5=B7=AE=E5=88=86=E3=82=92=E5=88=A4?= =?UTF-8?q?=E5=AE=9A=E3=81=99=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- browser/websocket/makeChanges.ts | 4 ++-- browser/websocket/pull.ts | 5 ++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/browser/websocket/makeChanges.ts b/browser/websocket/makeChanges.ts index 9e5887d..ea1b8fd 100644 --- a/browser/websocket/makeChanges.ts +++ b/browser/websocket/makeChanges.ts @@ -41,8 +41,8 @@ export function makeChanges( // リンクと画像の差分を入れる const [links, image] = findLinksAndImage(right_.join("\n")); if ( - head.linksLc.length !== links.length || - !head.linksLc.every((link) => links.includes(link)) + head.links.length !== links.length || + !head.links.every((link) => links.includes(link)) ) { changes.push({ links }); } diff --git a/browser/websocket/pull.ts b/browser/websocket/pull.ts index bd1dcfb..e974137 100644 --- a/browser/websocket/pull.ts +++ b/browser/websocket/pull.ts @@ -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 { @@ -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 { @@ -25,7 +24,7 @@ export async function pull(project: string, title: string): Promise { pageId: id, persistent, image, - linksLc: links.map((link) => toTitleLc(link)), + links, pin, lines, };