Skip to content

Commit f8966dd

Browse files
committed
refactor: Move getHelpfeels function to a separate file
1 parent bed9cdc commit f8966dd

File tree

3 files changed

+32
-34
lines changed

3 files changed

+32
-34
lines changed

websocket/getHelpfeels.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import type { BaseLine } from "@cosense/types/userscript";
2+
3+
/** Extract Helpfeel entries from text
4+
*
5+
* Helpfeel is a Scrapbox notation for questions and help requests.
6+
* Lines starting with "?" are considered Helpfeel entries and are
7+
* used to collect questions and support requests within a project.
8+
*
9+
* ```ts
10+
* import { assertEquals } from "@std/assert/equals";
11+
*
12+
* const text = `test page
13+
* [normal]link
14+
* but \`this [link]\` is not a link
15+
*
16+
* code:code
17+
* Links [link] and images [https://scrapbox.io/files/65f29c0c9045b5002522c8bb.svg] in code blocks should be ignored
18+
*
19+
* ? Need help with setup!!
20+
* `;
21+
*
22+
* assertEquals(getHelpfeels(text.split("\n").map((text) => ({ text }))), [
23+
* "Need help with setup!!",
24+
* ]);
25+
* ```
26+
*/
27+
export const getHelpfeels = (lines: Pick<BaseLine, "text">[]): string[] =>
28+
lines.flatMap(({ text }) =>
29+
/^\s*\? .*$/.test(text) ? [text.trimStart().slice(2)] : []
30+
);

websocket/getPageMetadataFromLines.ts

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { type Node, parse } from "@progfay/scrapbox-parser";
2-
import type { BaseLine } from "@cosense/types/userscript";
32
import { toTitleLc } from "../title.ts";
43
import { parseYoutube } from "../parser/youtube.ts";
54

@@ -279,32 +278,3 @@ const makeInlineCodeForDescription = (text: string): `\`${string}\`` =>
279278
`\`${text.trim().replaceAll("`", "\\`").slice(0, 198)}\``;
280279

281280
const cutId = (link: string): string => link.replace(/#[a-f\d]{24,32}$/, "");
282-
283-
/** Extract Helpfeel entries from text
284-
*
285-
* Helpfeel is a Scrapbox notation for questions and help requests.
286-
* Lines starting with "?" are considered Helpfeel entries and are
287-
* used to collect questions and support requests within a project.
288-
*
289-
* ```ts
290-
* import { assertEquals } from "@std/assert/equals";
291-
*
292-
* const text = `test page
293-
* [normal]link
294-
* but \`this [link]\` is not a link
295-
*
296-
* code:code
297-
* Links [link] and images [https://scrapbox.io/files/65f29c0c9045b5002522c8bb.svg] in code blocks should be ignored
298-
*
299-
* ? Need help with setup!!
300-
* `;
301-
*
302-
* assertEquals(getHelpfeels(text.split("\n").map((text) => ({ text }))), [
303-
* "Need help with setup!!",
304-
* ]);
305-
* ```
306-
*/
307-
export const getHelpfeels = (lines: Pick<BaseLine, "text">[]): string[] =>
308-
lines.flatMap(({ text }) =>
309-
/^\s*\? .*$/.test(text) ? [text.trimStart().slice(2)] : []
310-
);

websocket/makeChanges.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
import { diffToChanges } from "./diffToChanges.ts";
22
import type { Page } from "@cosense/types/rest";
33
import type { ChangeToPush } from "@cosense/types/websocket";
4-
import {
5-
getHelpfeels,
6-
getPageMetadataFromLines,
7-
} from "./getPageMetadataFromLines.ts";
4+
import { getPageMetadataFromLines } from "./getPageMetadataFromLines.ts";
85
import { isSameArray } from "./isSameArray.ts";
96
import { isString } from "@core/unknownutil/is/string";
7+
import { getHelpfeels } from "./getHelpfeels.ts";
108

119
export function* makeChanges(
1210
before: Page,

0 commit comments

Comments
 (0)