Skip to content

Commit 488d288

Browse files
committed
TinyCodeBlockの拡張と、それに伴うupdateCodeFileの破壊的変更
1 parent 42cea00 commit 488d288

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

browser/websocket/getCodeBlocks.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ export interface TinyCodeBlock {
1717

1818
/** コードブロックの真下の行(無ければ`null`) */
1919
nextLine: Line | null;
20+
21+
/** コードブロックが存在するページの情報 */
22+
pageInfo: { projectName: string; pageTitle: string };
2023
}
2124

2225
/** `getCodeBlocks()`に渡すfilter */
@@ -39,12 +42,12 @@ interface CodeTitle {
3942
* ファイル単位ではなく、コードブロック単位で返り値を生成する \
4043
* そのため、同じページ内に同名のコードブロックが複数あったとしても、分けた状態で返す
4144
*
42-
* @param target ページタイトル、または取得済みの行データ
45+
* @param target 取得するページの情報(linesを渡せば内部のページ取得処理を省略する)
4346
* @param filter 取得するコードブロックを絞り込むfilter
4447
* @return コードブロックの配列
4548
*/
4649
export const getCodeBlocks = async (
47-
target: { project: string; title: string } | { lines: Line[] },
50+
target: { project: string; title: string; lines?: Line[] },
4851
filter?: GetCodeBlocksFilter,
4952
): Promise<TinyCodeBlock[]> => {
5053
const lines = await getLines(target);
@@ -89,6 +92,10 @@ export const getCodeBlocks = async (
8992
titleLine: line,
9093
bodyLines: [],
9194
nextLine: null,
95+
pageInfo: {
96+
projectName: target.project,
97+
pageTitle: target.title,
98+
},
9299
});
93100
}
94101
}
@@ -97,9 +104,9 @@ export const getCodeBlocks = async (
97104

98105
/** targetを`Line[]`に変換する */
99106
async function getLines(
100-
target: { project: string; title: string } | { lines: Line[] },
107+
target: { project: string; title: string; lines?: Line[] },
101108
): Promise<Line[]> {
102-
if ("lines" in target) {
109+
if (target.lines !== undefined) {
103110
return target.lines;
104111
} else {
105112
const head = await pull(target.project, target.title);
@@ -127,7 +134,7 @@ function extractFromCodeTitle(lineText: string): CodeTitle | null {
127134
return null;
128135
} else {
129136
// `code:foo.ext`
130-
lang = ext[1];
137+
lang = ext[1].slice(1, -1).trim();
131138
}
132139
} else {
133140
lang = matched[3];

browser/websocket/updateCodeFile.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ export const updateCodeFile = async (
7777
const head = await pull(project, title);
7878
const lines: Line[] = head.lines;
7979
const codeBlocks = await getCodeBlocks({
80+
project,
81+
title,
8082
lines: lines,
8183
}, {
8284
filename: codeFile.filename,

0 commit comments

Comments
 (0)