Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion ACKNOWLEDGEMENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

A big thanks to the following individuals for contributing:

- [@JIEJIAN21](https://github.com/JIEJIAN21) - thanks for logo and icon design
- [@TsFreddie](https://github.com/TsFreddie) — [contributions](https://github.com/jdneo/vscode-leetcode/commits?author=TsFreddie)
- [@ntt2k](https://github.com/ntt2k) — [contributions](https://github.com/jdneo/vscode-leetcode/commits?author=ntt2k)
- [@purocean](https://github.com/purocean) — [contributions](https://github.com/jdneo/vscode-leetcode/commits?author=purocean)
Expand All @@ -17,4 +18,5 @@ A big thanks to the following individuals for contributing:
- [@houtianze](https://github.com/houtianze) — [contributions](https://github.com/jdneo/vscode-leetcode/commits?author=houtianze)
- [@magic-akari](https://github.com/magic-akari) - [contributions](https://github.com/jdneo/vscode-leetcode/commits?author=magic-akari)
- [@SF-Zhou](https://github.com/SF-Zhou) - [contributions](https://github.com/jdneo/vscode-leetcode/commits?author=SF-Zhou)
- [@JIEJIAN21](https://github.com/JIEJIAN21) - thanks for logo and icon design
- [@fuafa](https://github.com/fuafa) - [contributions](https://github.com/jdneo/vscode-leetcode/commits?author=fuafa)
- [@iFun](https://github.com/iFun) - [contributions](https://github.com/jdneo/vscode-leetcode/commits?author=iFun)
30 changes: 27 additions & 3 deletions src/webview/leetCodePreviewProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ class LeetCodePreviewProvider extends LeetCodeWebview {
const { title, url, category, difficulty, likes, dislikes, body } = this.description;
const head: string = markdownEngine.render(`# [${title}](${url})`);
const info: string = markdownEngine.render([
`| Category | Difficulty | Likes | Dislikes | [Discuss](${url.replace("/description/", "/discuss/?currentPage=1&orderBy=most_votes&query=")}) |`,
`| :------: | :--------: | :---: | :------: | :-----: |`,
`| ${category} | ${difficulty} | ${likes} | ${dislikes} | -- |`,
`| Category | Difficulty | Likes | Dislikes |`,
`| :------: | :--------: | :---: | :------: |`,
`| ${category} | ${difficulty} | ${likes} | ${dislikes} |`,
].join("\n"));
const tags: string = [
`<details>`,
Expand All @@ -97,6 +97,11 @@ class LeetCodePreviewProvider extends LeetCodeWebview {
),
`</details>`,
].join("\n");
const links: string = markdownEngine.render([
`---`,
`- [Discussion](${this.getDiscussionLink(url)})`,
`- [Solution](${this.getSolutionLink(url)})`,
].join("\n"));
return `
<!DOCTYPE html>
<html>
Expand All @@ -114,6 +119,7 @@ class LeetCodePreviewProvider extends LeetCodeWebview {
${tags}
${companies}
${body}
${links}
${!this.sideMode ? button.element : ""}
<script>
const vscode = acquireVsCodeApi();
Expand Down Expand Up @@ -172,6 +178,24 @@ class LeetCodePreviewProvider extends LeetCodeWebview {
body: body.join("\n").replace(/<pre>[\r\n]*([^]+?)[\r\n]*<\/pre>/g, "<pre><code>$1</code></pre>"),
};
}

private getDiscussionLink(url: string): string {
if (url.includes("leetcode-cn.com")) {
return url.replace("/description/", "/comments/");
} else if (url.includes("leetcode.com")) {
return url.replace("/description/", "/discuss/?currentPage=1&orderBy=most_votes&query=");
}

return "https://leetcode.com";
}

private getSolutionLink(url: string): string {
if (url.includes("leetcode-cn.com") || url.includes("leetcode.com")) {
return url.replace("/description/", "/solution/");
}

return "https://leetcode.com";
}
}

interface IDescription {
Expand Down