Skip to content

Commit 270dbb9

Browse files
committed
v1.1.0 local svg, undefined name bug, update some deps
Support svg image (using sharp), not support online svg now Add externals: { sharp: 'commonjs sharp'} in webpack.config.js lovell/sharp#2350 (comment) Zhihu username sometimes shows undefined, it is because profile is gziped Add gzip: true in fetchProfile Update ts-loader webpack typescript webpack-cli, with somebugs this undefined https://github.com/Microsoft/TypeScript/wiki/FAQ#why-does-this-get-orphaned-in-my-instance-methods Explictly call member function, e.g. const sendRequest = (options) => httpService.sendRequest(options) Always error on property override accessor microsoft/TypeScript#37894 My solution is set tooltip and description in the constructor Remove dep of uglifyjs-webpack-plugin add keyword of 知乎专栏, 知乎, Markdown
1 parent 68b2e53 commit 270dbb9

10 files changed

+2487
-7438
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ zhihu-title-image: 请输入专栏文章题图(若无需题图,删除本行
1717

1818
这是一个开源项目,你可以在[jks-liu.WPL-s@Github](https://github.com/jks-liu/WPL-s)上找到它。
1919

20-
本项目源于牛岱的开源项目(开源协议:MIT)[VSCode-Zhihu](https://github.com/niudai/VSCode-Zhihu),在此表示感谢。原项目貌似已不再维护,我在此接力。
20+
本项目源于牛岱的开源项目(开源协议:MIT)[VSCode-Zhihu](https://github.com/niudai/VSCode-Zhihu),在此表示感谢。
2121

2222
插件图标来自[Google Material icons](https://fonts.google.com/icons?icon.query=coffee),在 [Apache License, Version 2.0](https://www.apache.org/licenses/LICENSE-2.0.html)下授权。
2323

package-lock.json

Lines changed: 2428 additions & 7399 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "wpls",
33
"displayName": "WPL/s - Zhihu Write Publish Loop w/ statistic",
44
"description": "使用 Markdown 在 VS Code 中进行知乎创作(回答问题,写专栏文章)",
5-
"version": "1.0.2",
5+
"version": "1.1.0",
66
"publisher": "jks-liu",
77
"license": "MIT",
88
"enableProposedApi": false,
@@ -11,8 +11,10 @@
1111
},
1212
"keywords": [
1313
"zhihu",
14-
"feed",
15-
"writing"
14+
"知乎专栏",
15+
"writing",
16+
"知乎",
17+
"Markdown"
1618
],
1719
"categories": [
1820
"Notebooks"
@@ -341,12 +343,11 @@
341343
"@typescript-eslint/parser": "^4.28.5",
342344
"eslint": "^6.8.0",
343345
"mocha": "^7.0.1",
344-
"ts-loader": "^6.2.1",
345-
"typescript": "^3.7.5",
346-
"uglifyjs-webpack-plugin": "^2.2.0",
346+
"ts-loader": "^9.2.5",
347+
"typescript": "^4.4.2",
347348
"vscode-test": "^1.3.0",
348-
"webpack": "^4.41.5",
349-
"webpack-cli": "^3.3.10"
349+
"webpack": "^5.52.0",
350+
"webpack-cli": "^4.8.0"
350351
},
351352
"dependencies": {
352353
"@types/cheerio": "^0.22.17",
@@ -364,6 +365,7 @@
364365
"pug": "^2.0.4",
365366
"request": "^2.88.0",
366367
"request-promise": "^4.2.5",
368+
"sharp": "^0.29.1",
367369
"tough-cookie": "^3.0.1",
368370
"tough-cookie-filestore": "^0.0.1",
369371
"zhihu-encrypt": "^1.0.0"

src/service/http.service.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ export class HttpService {
9696
}
9797
}
9898

99-
var httpService = new HttpService()
99+
const httpService = new HttpService()
100100

101-
export const sendRequest = httpService.sendRequest;
102-
export const clearCookie = httpService.clearCookie;
103-
export const clearCache = httpService.clearCache;
101+
export const sendRequest = (options) => httpService.sendRequest(options);
102+
export const clearCookie = (domain?: string) => httpService.clearCookie(domain);
103+
export const clearCache = () => httpService.clearCache();

src/service/paste.service.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { Output } from "../global/logger";
1313
import { IImageUploadToken } from "../model/publish/image.model";
1414
import { sendRequest } from "./http.service";
1515
import { getCache, setCache } from "../global/cache";
16+
import * as sharp from "sharp";
1617

1718
/**
1819
* Paste Service for image upload
@@ -73,14 +74,21 @@ export class PasteService {
7374
enableCache: true
7475
});
7576
} else {
77+
// Get absolute image path
7678
if(!path.isAbsolute(link)) {
7779
let _dir = path.dirname(vscode.window.activeTextEditor.document.uri.fsPath);
7880
link = path.join(_dir, link);
7981
}
8082
try {
83+
// Convert svg to png
84+
if (path.extname(link).toLowerCase() === ".svg") {
85+
await sharp(link).png().toFile(link + ".png")
86+
link = link + ".png";
87+
}
88+
8189
buffer = fs.readFileSync(link);
8290
} catch (error) {
83-
Output('图片获取失败!', 'warn')
91+
Output('图片获取失败!', 'warn');
8492
buffer = undefined
8593
}
8694
}

src/service/profile.service.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ export class ProfileService {
1616
if (await this.accountService.isAuthenticated()) {
1717
this.profile = await sendRequest({
1818
uri: SelfProfileAPI,
19-
json: true
19+
json: true,
20+
gzip: true,
2021
});
2122
} else {
2223
this.profile = undefined;

src/treeview/collection-treeview-provider.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,17 @@ export class CollectionItem extends LinkableTreeItem {
7676
public readonly target?: IQuestionAnswerTarget | IQuestionTarget | IArticleTarget,
7777
) {
7878
super(label, collapsibleState, target ? target.url : '');
79+
this.tooltip = this.target ? this.target.excerpt : '';
80+
this.description = this.target ? this.target.excerpt : '';
7981
}
8082

81-
get tooltip(): string | undefined {
82-
return this.target ? this.target.excerpt : '';
83-
}
83+
// get tooltip(): string | undefined {
84+
// return this.target ? this.target.excerpt : '';
85+
// }
8486

85-
get description(): string | undefined {
86-
return this.target ? this.target.excerpt : '';
87-
}
87+
// get description(): string | undefined {
88+
// return this.target ? this.target.excerpt : '';
89+
// }
8890

8991
// iconPath = {
9092
// light: vscode.ThemeIcon.File,

src/treeview/feed-treeview-provider.ts

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -125,15 +125,17 @@ export class FeedTreeItem extends LinkableTreeItem {
125125
public avatarUrl?: string
126126
) {
127127
super(label, collapsibleState, target ? target.url : '');
128+
this.tooltip = this.target ? this.target.excerpt : '';
129+
this.description = this.target && this.target.excerpt ? this.target.excerpt : '';
128130
}
129131

130-
get tooltip(): string | undefined {
131-
return this.target ? this.target.excerpt : '';
132-
}
132+
// get tooltip(): string | undefined {
133+
// return this.target ? this.target.excerpt : '';
134+
// }
133135

134-
get description(): string {
135-
return this.target && this.target.excerpt ? this.target.excerpt : '';
136-
}
136+
// get description(): string {
137+
// return this.target && this.target.excerpt ? this.target.excerpt : '';
138+
// }
137139

138140
iconPath = this.avatarUrl ? vscode.Uri.parse(this.avatarUrl) : false;
139141

@@ -154,15 +156,17 @@ export class EventTreeItem extends vscode.TreeItem {
154156
public readonly parent: vscode.TreeItem
155157
) {
156158
super(removeSpace(removeHtmlTag(event.content)).slice(0, 12) + '...', collapsibleState);
159+
this.tooltip = removeHtmlTag(this.event.content);
160+
this.description = beautifyDate(this.event.date);
157161
}
158162

159-
get tooltip(): string | undefined {
160-
return removeHtmlTag(this.event.content);
161-
}
163+
// get tooltip(): string | undefined {
164+
// return removeHtmlTag(this.event.content);
165+
// }
162166

163-
get description(): string {
164-
return beautifyDate(this.event.date);
165-
}
167+
// get description(): string {
168+
// return beautifyDate(this.event.date);
169+
// }
166170

167171
iconPath = false;
168172

src/treeview/hotstory-treeview-provider.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,15 +84,17 @@ export class ZhihuTreeItem extends LinkableTreeItem {
8484
public page?: number,
8585
) {
8686
super(label, collapsibleState, target && target.url ? target.url : '');
87+
this.tooltip = this.target && this.target.excerpt ? this.target.excerpt : '';
88+
this.description = this.target && this.target.excerpt ? this.target.excerpt : '';
8789
}
8890

89-
get tooltip(): string {
90-
return this.target && this.target.excerpt ? this.target.excerpt : '';
91-
}
91+
// get tooltip(): string {
92+
// return this.target && this.target.excerpt ? this.target.excerpt : '';
93+
// }
9294

93-
get description(): string {
94-
return this.target && this.target.excerpt ? this.target.excerpt : '';
95-
}
95+
// get description(): string {
96+
// return this.target && this.target.excerpt ? this.target.excerpt : '';
97+
// }
9698

9799
// iconPath = {
98100
// light: vscode.ThemeIcon.File,

webpack.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const config = {
2121
devtool: 'source-map',
2222
externals: [{
2323
vscode: 'commonjs vscode', // the vscode-module is created on-the-fly and must be excluded. Add other modules that cannot be webpack'ed, 📖 -> https://webpack.js.org/configuration/externals/
24+
sharp: 'commonjs sharp',
2425
},
2526
// {
2627
// 'uglify-js': 'uglify-js'

0 commit comments

Comments
 (0)