Skip to content

[new feature] 增加題目分類 #21

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions public/localData.json

Large diffs are not rendered by default.

29 changes: 29 additions & 0 deletions retrieveTopicTag.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const data = require("./data.json");
const axios = require("axios");
const fs = require("fs");

const delay = async (ms = 1000) => new Promise((r) => setTimeout(r, ms));
(async function () {
console.log("START");
let delayTime = 0; // 延時請求,防止對方 server 出現 code 429 (請求過於頻繁)
const result = await Promise.all(
data.map(async (datum, i) => {
delayTime += 1000;
await delay(delayTime);
const res = await axios.post("https://leetcode.com/graphql/", {
query:
"\n query singleQuestionTopicTags($titleSlug: String!) {\n question(titleSlug: $titleSlug) {\n topicTags {\n name\n slug\n }\n }\n}\n ",
variables: {
titleSlug: datum.TitleSlug,
},
});
const topicTags = res?.data?.data?.question?.topicTags || [];
console.log(`Finished ${i + 1} request`);
return { ...datum, topicTags };
})
);
fs.writeFile("/public/localData.json", JSON.stringify(result), function (err) {
if (err) return console.log(err);
console.log("DONE");
});
})();
1 change: 1 addition & 0 deletions src/locale/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export default {
placeholder: "type a keyword",
contestNumber: "Contest number",
ratingInterval: "Rating interval",
topicTags: "Topic Tags",
asc: "Asc",
desc: "Desc",
query: "Query",
Expand Down
1 change: 1 addition & 0 deletions src/locale/zh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export default {
placeholder: "输入关键词",
contestNumber: "竞赛编号",
ratingInterval: "分数区间",
topicTags: "題目分類",
asc: "升序",
desc: "降序",
query: "查询",
Expand Down
19 changes: 18 additions & 1 deletion src/views/ProblemRating.vue
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,15 @@
@sort-change="sortChange"
>
<el-table-column prop="ID" label="ID" width="180" sortable="custom" />
<el-table-column prop="topicTags" :label="$t('topicTags')" width="300">
<template #default="{ row: { topicTags } }">
<template v-for="topicTag in topicTags" :key="topicTag.slug">
<label class="topicTag">
{{ topicTag.name }}
</label>
</template>
</template>
</el-table-column>
<el-table-column :label="$t('problemName')">
<template #default="scope">
<el-link
Expand Down Expand Up @@ -129,7 +138,7 @@ import axios, { AxiosResponse } from "axios";
import { ElMessage } from "element-plus";
import { useI18n } from "vue-i18n";

const url = "./data.json";
const url = "./localData.json";

interface Problem {
ContestID_en: string;
Expand All @@ -145,6 +154,7 @@ interface Problem {
ProblemHrefEN: string | null;
ContestHrefEN: string | null;
ContestHrefZH: string | null;
topicTags: string[];
}
interface SortInfo {
prop: "Rating" | "ID";
Expand Down Expand Up @@ -304,4 +314,11 @@ function reset() {
display: flex;
justify-content: right;
}

.topicTag {
margin-right: 8px;
padding: 4px;
border-radius: 4px;
background-color: blanchedalmond;
}
</style>
4 changes: 4 additions & 0 deletions vue.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ module.exports = defineConfig({
target: "https://zerotrac.github.io/leetcode_problem_rating",
secure: false,
},
"/localData.json": {
target: "/",
secure: false,
},
},
},
chainWebpack(config) {
Expand Down