Skip to content

Commit 33a9668

Browse files
authored
Merge pull request #91 from zenn-dev/canary
release v0.1.2
2 parents 25a22e9 + f30db1e commit 33a9668

File tree

11 files changed

+83
-29
lines changed

11 files changed

+83
-29
lines changed

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
Resolves #<issue-url>
66

7-
### :clipboard: Tasks
7+
## :clipboard: Tasks
88

99
プルリクエストを作成いただく際、お手数ですが以下の内容についてご確認をお願いします。
1010

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,11 @@ settings.json に以下の設定を追加してください。
7070

7171
```json
7272
"[markdown]": {
73-
"editor.quickSuggestions": true
73+
"editor.quickSuggestions": {
74+
"comments": true,
75+
"strings": true,
76+
"other": true
77+
}
7478
}
7579
```
7680

examples/articles/local-image-test.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,14 @@ published: true
5050
![1st](/images/example-images/zenn-editor.png)
5151

5252
![2nd](/images/example-images/zenn-editor.png)
53+
54+
## 不同画像の連続表示
55+
56+
```md
57+
![1st](/images/example-images/zenn-editor.png)
58+
![2nd](/images/example-images/zenn-icon.png)
59+
```
60+
61+
![1st](/images/example-images/zenn-editor.png)
62+
63+
![2nd](/images/example-images/zenn-icon.png)
1.68 KB
Loading

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@
44
"displayName": "Zenn Preview for github.dev",
55
"description": "Zenn のコンテンツを github.dev でプレビューできるようにする VSCode 拡張",
66
"icon": "public/assets/zenn-icon.png",
7+
"homepage": "https://marketplace.visualstudio.com/items?itemName=zenn.zenn-preview",
78
"repository": {
89
"type": "git",
910
"url": "https://github.com/zenn-dev/zenn-vscode-extension.git"
1011
},
1112
"license": "MIT",
12-
"version": "0.1.1",
13+
"version": "0.1.2",
1314
"pricing": "Free",
1415
"engines": {
1516
"vscode": "^1.72.0"
@@ -157,7 +158,7 @@
157158
"editor/title": [
158159
{
159160
"command": "zenn-preview.preview-zenn",
160-
"when": "resourceLangId == markdown",
161+
"when": "resourceLangId == markdown && zenn-preview.active-document-can-preview",
161162
"group": "navigation"
162163
}
163164
]

src/commands/newArticle.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const generateArticleTemplate = () =>
2323
* 記事の新規作成コマンドの実装
2424
*/
2525
export const newArticleCommand = (context?: AppContext) => {
26-
const generator = async (): Promise<boolean> => {
26+
const generator = async (): Promise<vscode.Uri | null> => {
2727
if (!context) throw new Error("コマンドを実行できません");
2828

2929
const aritcleSlug = await vscode.window.showInputBox({
@@ -46,7 +46,7 @@ export const newArticleCommand = (context?: AppContext) => {
4646
},
4747
});
4848

49-
if (!aritcleSlug) return false;
49+
if (!aritcleSlug) return null;
5050

5151
const { articlesFolderUri } = context;
5252
const text = new TextEncoder().encode(generateArticleTemplate());
@@ -57,14 +57,15 @@ export const newArticleCommand = (context?: AppContext) => {
5757

5858
await vscode.workspace.fs.writeFile(fileUri, text);
5959

60-
return true;
60+
return fileUri;
6161
};
6262

6363
return () => {
6464
generator()
65-
.then((isCreated) => {
66-
if (isCreated) {
65+
.then((fileUri) => {
66+
if (fileUri) {
6767
vscode.window.showInformationMessage("記事を作成しました");
68+
vscode.window.showTextDocument(fileUri);
6869
}
6970
})
7071
.catch(() => {

src/commands/newBook.ts

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,29 +30,36 @@ const generateBookConfigTemplate = () =>
3030
/**
3131
* 本の設定ファイルを生成する
3232
*/
33-
const createBookConfigFile = async (bookUri: vscode.Uri) => {
33+
const createBookConfigFile = async (
34+
bookUri: vscode.Uri
35+
): Promise<vscode.Uri> => {
3436
const configText = new TextEncoder().encode(generateBookConfigTemplate());
3537
const configUri = vscode.Uri.joinPath(bookUri, "config.yaml");
3638

3739
await vscode.workspace.fs.writeFile(configUri, configText);
40+
41+
return configUri;
3842
};
3943

4044
/**
4145
* 本の作成に基づいてチャプターファイルを作成する
4246
*/
43-
const createBookChapterFiles = async (bookUri: vscode.Uri) => {
44-
await Promise.all(
47+
const createBookChapterFiles = async (
48+
bookUri: vscode.Uri
49+
): Promise<vscode.Uri[]> => {
50+
const bookChapterFileUris = await Promise.all(
4551
TEMPLATE_CHAPTERS.map((fileName) =>
4652
createBookChapterFile(fileName, bookUri)
4753
)
4854
);
55+
return bookChapterFileUris;
4956
};
5057

5158
/**
5259
* 本の新規作成コマンドの実装
5360
*/
5461
export const newBookCommand = (context?: AppContext) => {
55-
const generator = async (): Promise<boolean> => {
62+
const generator = async (): Promise<vscode.Uri | null> => {
5663
if (!context) throw new Error("コマンドを実行できません");
5764

5865
const bookSlug = await vscode.window.showInputBox({
@@ -72,24 +79,25 @@ export const newBookCommand = (context?: AppContext) => {
7279
},
7380
});
7481

75-
if (!bookSlug) return false;
82+
if (!bookSlug) return null;
7683

7784
const bookUri = vscode.Uri.joinPath(context.booksFolderUri, bookSlug);
7885

7986
await vscode.workspace.fs.createDirectory(bookUri);
80-
await Promise.all([
87+
const [configFileUri] = await Promise.all([
8188
createBookConfigFile(bookUri),
8289
createBookChapterFiles(bookUri),
8390
]);
8491

85-
return true;
92+
return configFileUri;
8693
};
8794

8895
return () => {
8996
generator()
90-
.then((isCreated) => {
91-
if (isCreated) {
97+
.then((configFileUri) => {
98+
if (configFileUri) {
9299
vscode.window.showInformationMessage("本を作成しました");
100+
vscode.window.showTextDocument(configFileUri);
93101
}
94102
})
95103
.catch(() => {

src/commands/newChapter.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,23 @@ export const generateBookChapterTemplate = () =>
1818
export const createBookChapterFile = async (
1919
filename: string,
2020
bookUri: vscode.Uri
21-
): Promise<void> => {
21+
): Promise<vscode.Uri> => {
2222
const templateText = generateBookChapterTemplate();
2323
const chapterText = new TextEncoder().encode(templateText);
2424
const chapterUri = vscode.Uri.joinPath(bookUri, `${filename}.md`);
2525

2626
await vscode.workspace.fs.writeFile(chapterUri, chapterText);
27+
28+
return chapterUri;
2729
};
2830

2931
/**
3032
* チャプターの新規作成コマンドの実装
3133
*/
3234
export const newChapterCommand = (context?: AppContext) => {
33-
const generator = async (treeItem?: BookTreeItem): Promise<boolean> => {
35+
const generator = async (
36+
treeItem?: BookTreeItem
37+
): Promise<vscode.Uri | null> => {
3438
if (!context) throw new Error("コマンドを実行できません");
3539

3640
const selectedBookFolder = treeItem?.contentUri
@@ -49,7 +53,7 @@ export const newChapterCommand = (context?: AppContext) => {
4953
});
5054
});
5155

52-
if (!selectedBookFolder) return false;
56+
if (!selectedBookFolder) return null;
5357

5458
// チャプタースラグの作成
5559
const chapterSlug = await vscode.window.showInputBox({
@@ -73,24 +77,25 @@ export const newChapterCommand = (context?: AppContext) => {
7377
});
7478

7579
// チャプタースラグが不正やすでに存在している場合は失敗
76-
if (!chapterSlug) return false;
80+
if (!chapterSlug) return null;
7781

7882
const bookUri = vscode.Uri.joinPath(
7983
context.booksFolderUri,
8084
selectedBookFolder
8185
);
8286

8387
// ファイルを作成する
84-
await createBookChapterFile(chapterSlug, bookUri);
88+
const fileUri = await createBookChapterFile(chapterSlug, bookUri);
8589

86-
return true;
90+
return fileUri;
8791
};
8892

8993
return (treeItem?: BookTreeItem) => {
9094
generator(treeItem)
91-
.then((isCreated) => {
92-
if (isCreated) {
95+
.then((fileUri) => {
96+
if (fileUri) {
9397
vscode.window.showInformationMessage("チャプターを作成しました");
98+
vscode.window.showTextDocument(fileUri);
9499
}
95100
})
96101
.catch(() => {

src/context/editor/index.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { initializeBookChapterEditor } from "./bookChapter";
66
import { initializeBookConfigEditor } from "./bookConfig";
77
import { initializeBookCoverImageEditor } from "./bookCoverImage";
88

9+
import { checkUriCanPreview } from "../../schemas/previewPanel";
910
import { AppContext } from "../app";
1011

1112
/**
@@ -44,7 +45,17 @@ export const initializeEditor = (context: AppContext): vscode.Disposable[] => {
4445
vscode.window.onDidChangeActiveTextEditor((event) => {
4546
if (!event || !event.viewColumn) return;
4647

47-
const key = cache.createKey("previewPanel", event.document.uri);
48+
const activeDocumentUri = event.document.uri;
49+
50+
// 現在のドキュメントのUriがプレビュー可能なものならエディタタイトル上にプレビューボタンを表示
51+
const canPreview = checkUriCanPreview(context, activeDocumentUri);
52+
vscode.commands.executeCommand(
53+
"setContext",
54+
"zenn-preview.active-document-can-preview",
55+
canPreview
56+
);
57+
58+
const key = cache.createKey("previewPanel", activeDocumentUri);
4859
const panel = cache.getCache(key)?.panel;
4960

5061
if (!panel) return;

src/schemas/previewPanel.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,10 @@ export const createPreviewPanel = (
5757
/**
5858
* プレビュー可能な Uri か判別する
5959
*/
60-
const checkUriCanPreview = (context: AppContext, uri: vscode.Uri): boolean => {
60+
export const checkUriCanPreview = (
61+
context: AppContext,
62+
uri: vscode.Uri
63+
): boolean => {
6164
const type = context.getContentsType(uri);
6265
const canPreviewContentsType: ContentsType[] = [
6366
"article",

0 commit comments

Comments
 (0)