8000 feat: added solution link (#441) · jipantester/vscode-leetcode@ffdccec · GitHub
[go: up one dir, main page]

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit ffdccec

Browse files
iFunjdneo
authored andcommitted
feat: added solution link (LeetCode-OpenSource#441)
1 parent 01f5a28 commit ffdccec

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

ACKNOWLEDGEMENTS.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
A big thanks to the following individuals for contributing:
44

5+
- [@JIEJIAN21](https://github.com/JIEJIAN21) - thanks for logo and icon design
56
- [@TsFreddie](https://github.com/TsFreddie)[contributions](https://github.com/jdneo/vscode-leetcode/commits?author=TsFreddie)
67
- [@ntt2k](https://github.com/ntt2k)[contributions](https://github.com/jdneo/vscode-leetcode/commits?author=ntt2k)
78
- [@purocean](https://github.com/purocean)[contributions](https://github.com/jdneo/vscode-leetcode/commits?author=purocean)
@@ -17,4 +18,5 @@ A big thanks to the following individuals for contributing:
1718
- [@houtianze](https://github.com/houtianze)[contributions](https://github.com/jdneo/vscode-leetcode/commits?author=houtianze)
1819
- [@magic-akari](https://github.com/magic-akari) - [contributions](https://github.com/jdneo/vscode-leetcode/commits?author=magic-akari)
1920
- [@SF-Zhou](https://github.com/SF-Zhou) - [contributions](https://github.com/jdneo/vscode-leetcode/commits?author=SF-Zhou)
20-
- [@JIEJIAN21](https://github.com/JIEJIAN21) - thanks for logo and icon design
21+
- [@fuafa](https://github.com/fuafa) - [contributions](https://github.com/jdneo/vscode-leetcode/commits?author=fuafa)
22+
- [@iFun](https://github.com/iFun) - [contributions](https://github.com/jdneo/vscode-leetcode/commits?author=iFun)

src/webview/leetCodePreviewProvider.ts

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
// Licensed under the MIT license.
33

44
import { commands, ViewColumn } from "vscode";
5-
import { IProblem } from "../shared";
5+
import { getLeetCodeEndpoint } from "../commands/plugin";
6+
import { Endpoint, IProblem } from "../shared";
67
import { ILeetCodeWebviewOption, LeetCodeWebview } from "./LeetCodeWebview";
78
import { markdownEngine } from "./markdownEngine";
89

@@ -73,9 +74,9 @@ class LeetCodePreviewProvider extends LeetCodeWebview {
7374
const { title, url, category, difficulty, likes, dislikes, body } = this.description;
7475
const head: string = markdownEngine.render(`# [${title}](${url})`);
7576
const info: string = markdownEngine.render([
76-
`| Category | Difficulty | Likes | Dislikes | [Discuss](${url.replace("/description/", "/discuss/?currentPage=1&orderBy=most_votes&query=")}) |`,
77-
`| :------: | :--------: | :---: | :------: | :-----: |`,
78-
`| ${category} | ${difficulty} | ${likes} | ${dislikes} | -- |`,
77+
`| Category | Difficulty | Likes | Dislikes |`,
78+
`| :------: | :--------: | :---: | :------: |`,
79+
`| ${category} | ${difficulty} | ${likes} | ${dislikes} |`,
7980
].join("\n"));
8081
const tags: string = [
8182
`<details>`,
@@ -97,6 +98,7 @@ class LeetCodePreviewProvider extends LeetCodeWebview {
9798
),
9899
`</details>`,
99100
].join("\n");
101+
const links: string = markdownEngine.render(`[Discussion](${this.getDiscussionLink(url)}) | [Solution](${this.getSolutionLink(url)})`);
100102
return `
101103
<!DOCTYPE html>
102104
<html>
@@ -114,6 +116,8 @@ class LeetCodePreviewProvider extends LeetCodeWebview {
114116
${tags}
115117
${companies}
116118
${body}
119+
<hr />
120+
${links}
117121
${!this.sideMode ? button.element : ""}
118122
<script>
119123
const vscode = acquireVsCodeApi();
@@ -172,6 +176,21 @@ class LeetCodePreviewProvider extends LeetCodeWebview {
172176
body: body.join("\n").replace(/<pre>[\r\n]*([^]+?)[\r\n]*<\/pre>/g, "<pre><code>$1</code></pre>"),
173177
};
174178
}
179+
180+
private getDiscussionLink(url: string): string {
181+
const endPoint: string = getLeetCodeEndpoint();
182+
if (endPoint === Endpoint.LeetCodeCN) {
183+
return url.replace("/description/", "/comments/");
184+
} else if (endPoint === Endpoint.LeetCode) {
185+
return url.replace("/description/", "/discuss/?currentPage=1&orderBy=most_votes&query=");
186+
}
187+
188+
return "https://leetcode.com";
189+
}
190+
191+
private getSolutionLink(url: string): string {
192+
return url.replace("/description/", "/solution/");
193+
}
175194
}
176195

177196
interface IDescription {

0 commit comments

Comments
 (0)
0