Skip to content

Commit

Permalink
v1.1.0 local svg, undefined name bug, update some deps
Browse files Browse the repository at this point in the history
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
  • Loading branch information
jks-liu committed Sep 9, 2021
1 parent 68b2e53 commit 270dbb9
Show file tree
Hide file tree
Showing 10 changed files with 2,487 additions and 7,438 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ zhihu-title-image: 请输入专栏文章题图(若无需题图,删除本行

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

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

插件图标来自[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)下授权。

Expand Down
9,827 changes: 2,428 additions & 7,399 deletions package-lock.json

Large diffs are not rendered by default.

18 changes: 10 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "wpls",
"displayName": "WPL/s - Zhihu Write Publish Loop w/ statistic",
"description": "使用 Markdown 在 VS Code 中进行知乎创作(回答问题,写专栏文章)",
"version": "1.0.2",
"version": "1.1.0",
"publisher": "jks-liu",
"license": "MIT",
"enableProposedApi": false,
Expand All @@ -11,8 +11,10 @@
},
"keywords": [
"zhihu",
"feed",
"writing"
"知乎专栏",
"writing",
"知乎",
"Markdown"
],
"categories": [
"Notebooks"
Expand Down Expand Up @@ -341,12 +343,11 @@
"@typescript-eslint/parser": "^4.28.5",
"eslint": "^6.8.0",
"mocha": "^7.0.1",
"ts-loader": "^6.2.1",
"typescript": "^3.7.5",
"uglifyjs-webpack-plugin": "^2.2.0",
"ts-loader": "^9.2.5",
"typescript": "^4.4.2",
"vscode-test": "^1.3.0",
"webpack": "^4.41.5",
"webpack-cli": "^3.3.10"
"webpack": "^5.52.0",
"webpack-cli": "^4.8.0"
},
"dependencies": {
"@types/cheerio": "^0.22.17",
Expand All @@ -364,6 +365,7 @@
"pug": "^2.0.4",
"request": "^2.88.0",
"request-promise": "^4.2.5",
"sharp": "^0.29.1",
"tough-cookie": "^3.0.1",
"tough-cookie-filestore": "^0.0.1",
"zhihu-encrypt": "^1.0.0"
Expand Down
8 changes: 4 additions & 4 deletions src/service/http.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ export class HttpService {
}
}

var httpService = new HttpService()
const httpService = new HttpService()

export const sendRequest = httpService.sendRequest;
export const clearCookie = httpService.clearCookie;
export const clearCache = httpService.clearCache;
export const sendRequest = (options) => httpService.sendRequest(options);
export const clearCookie = (domain?: string) => httpService.clearCookie(domain);
export const clearCache = () => httpService.clearCache();
10 changes: 9 additions & 1 deletion src/service/paste.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { Output } from "../global/logger";
import { IImageUploadToken } from "../model/publish/image.model";
import { sendRequest } from "./http.service";
import { getCache, setCache } from "../global/cache";
import * as sharp from "sharp";

/**
* Paste Service for image upload
Expand Down Expand Up @@ -73,14 +74,21 @@ export class PasteService {
enableCache: true
});
} else {
// Get absolute image path
if(!path.isAbsolute(link)) {
let _dir = path.dirname(vscode.window.activeTextEditor.document.uri.fsPath);
link = path.join(_dir, link);
}
try {
// Convert svg to png
if (path.extname(link).toLowerCase() === ".svg") {
await sharp(link).png().toFile(link + ".png")
link = link + ".png";
}

buffer = fs.readFileSync(link);
} catch (error) {
Output('图片获取失败!', 'warn')
Output('图片获取失败!', 'warn');
buffer = undefined
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/service/profile.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ export class ProfileService {
if (await this.accountService.isAuthenticated()) {
this.profile = await sendRequest({
uri: SelfProfileAPI,
json: true
json: true,
gzip: true,
});
} else {
this.profile = undefined;
Expand Down
14 changes: 8 additions & 6 deletions src/treeview/collection-treeview-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,17 @@ export class CollectionItem extends LinkableTreeItem {
public readonly target?: IQuestionAnswerTarget | IQuestionTarget | IArticleTarget,
) {
super(label, collapsibleState, target ? target.url : '');
this.tooltip = this.target ? this.target.excerpt : '';
this.description = this.target ? this.target.excerpt : '';
}

get tooltip(): string | undefined {
return this.target ? this.target.excerpt : '';
}
// get tooltip(): string | undefined {
// return this.target ? this.target.excerpt : '';
// }

get description(): string | undefined {
return this.target ? this.target.excerpt : '';
}
// get description(): string | undefined {
// return this.target ? this.target.excerpt : '';
// }

// iconPath = {
// light: vscode.ThemeIcon.File,
Expand Down
28 changes: 16 additions & 12 deletions src/treeview/feed-treeview-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,15 +125,17 @@ export class FeedTreeItem extends LinkableTreeItem {
public avatarUrl?: string
) {
super(label, collapsibleState, target ? target.url : '');
this.tooltip = this.target ? this.target.excerpt : '';
this.description = this.target && this.target.excerpt ? this.target.excerpt : '';
}

get tooltip(): string | undefined {
return this.target ? this.target.excerpt : '';
}
// get tooltip(): string | undefined {
// return this.target ? this.target.excerpt : '';
// }

get description(): string {
return this.target && this.target.excerpt ? this.target.excerpt : '';
}
// get description(): string {
// return this.target && this.target.excerpt ? this.target.excerpt : '';
// }

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

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

get tooltip(): string | undefined {
return removeHtmlTag(this.event.content);
}
// get tooltip(): string | undefined {
// return removeHtmlTag(this.event.content);
// }

get description(): string {
return beautifyDate(this.event.date);
}
// get description(): string {
// return beautifyDate(this.event.date);
// }

iconPath = false;

Expand Down
14 changes: 8 additions & 6 deletions src/treeview/hotstory-treeview-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,17 @@ export class ZhihuTreeItem extends LinkableTreeItem {
public page?: number,
) {
super(label, collapsibleState, target && target.url ? target.url : '');
this.tooltip = this.target && this.target.excerpt ? this.target.excerpt : '';
this.description = this.target && this.target.excerpt ? this.target.excerpt : '';
}

get tooltip(): string {
return this.target && this.target.excerpt ? this.target.excerpt : '';
}
// get tooltip(): string {
// return this.target && this.target.excerpt ? this.target.excerpt : '';
// }

get description(): string {
return this.target && this.target.excerpt ? this.target.excerpt : '';
}
// get description(): string {
// return this.target && this.target.excerpt ? this.target.excerpt : '';
// }

// iconPath = {
// light: vscode.ThemeIcon.File,
Expand Down
1 change: 1 addition & 0 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const config = {
devtool: 'source-map',
externals: [{
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/
sharp: 'commonjs sharp',
},
// {
// 'uglify-js': 'uglify-js'
Expand Down

0 comments on commit 270dbb9

Please sign in to comment.