Skip to content

Commit

Permalink
Change md format configs to json
Browse files Browse the repository at this point in the history
  • Loading branch information
Temparo committed Jun 26, 2024
1 parent cb2cd3e commit f7c5b54
Show file tree
Hide file tree
Showing 7 changed files with 516 additions and 36 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/url-process.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
python-version: '3.12'
- run: |
cd url-process
python "md_format_to_json.py"
python "json-format-to-json.py"
cd ..
# Commit all changed files back to the repository
Expand Down
41 changes: 28 additions & 13 deletions src/hooks/useUrlList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,6 @@ export default function () {
"url": "https://www.csu.edu.cn/info/1050/7585.htm",
"text": "校历"
},
{
"id": nanoid(),
"url": "https://career.csu.edu.cn/",
"text": "就业指导中心"
},
{
"id": nanoid(),
"url": "https://pan.csu.edu.cn/#/",
Expand Down Expand Up @@ -200,11 +195,6 @@ export default function () {
"text": "OriginLab",
"description": "科研绘图工具"
},
{
"id": nanoid(),
"url": "https://www.zhiyunwenxian.cn/",
"text": "知云文献翻译"
},
{
"id": nanoid(),
"url": "https://qrbtf.com/zh",
Expand Down Expand Up @@ -239,7 +229,22 @@ export default function () {
{
"id": nanoid(),
"url": "https://snapdrop.net",
"text": "局域网文件传输"
"text": "局域网文件传输1"
},
{
"id": nanoid(),
"url": "https://pairdrop.net/",
"text": "局域网文件传输2"
},
{
"id": nanoid(),
"url": "https://www.wenshushu.cn/",
"text": "文叔叔"
},
{
"id": nanoid(),
"url": "https://wormhole.app/",
"text": "Wormhole"
}
]
let urlList5: UrlBlock = [
Expand Down Expand Up @@ -416,7 +421,7 @@ export default function () {
"id": nanoid(),
"url": "https://www.grammarly.com/",
"text": "Grammarly",
"description": "英文写作辅助工具"
"description": "英文拼写检查"
}
]
let urlList8: UrlBlock = [
Expand Down Expand Up @@ -470,6 +475,11 @@ export default function () {
"id": nanoid(),
"url": "https://webdemo.myscript.com/",
"text": "MyScript"
},
{
"id": nanoid(),
"url": "https://www.zhiyunwenxian.cn/",
"text": "知云文献翻译"
}
]
let urlList9: UrlBlock = [
Expand Down Expand Up @@ -498,7 +508,12 @@ export default function () {
"id": nanoid(),
"url": "https://www.onetonline.org/",
"text": "O*NET OnLine",
"description": " 为英文网站,提供不同职业的入职要求、劳动强度、工作环境、工作内容、薪酬福利、就业趋势等信息(网站数据来源于美国,请结合实际情况分析)"
"description": " 为英文网站,提供不同职业的入职要求、劳动强度、工作环境、工作内容、薪酬福利、就业趋势等信息(网站数据来源于美国,请结合实际情况分析)"
},
{
"id": nanoid(),
"url": "https://career.csu.edu.cn/",
"text": "就业指导中心"
}
]

Expand Down
40 changes: 40 additions & 0 deletions url-process/json-format-to-json.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import re
import json

origin_file = open("origin-urls.json", "r", encoding="utf-8")
ts_template = open("useUrlList-Template", "r", encoding="utf-8")
ts_output = open("../src/hooks/useUrlList.ts", "w", encoding="utf-8")

origin_content = origin_file.read()
ts_template_content = ts_template.read()
origin_file.close()
ts_template.close()

sequence: int = 1
content_dic = json.loads(origin_content)
for key, value in content_dic.items():
count: int = 0
mid_list: list = []
target: str = ""
block_name = key

for item in value:
text = item["text"]
url = item["url"]
small_dict: dict = {"id": 'nanoid()', "url": url, "text": text}
if item.get("description") is not None:
description = item["description"]
small_dict["description"] = description
mid_list.append(small_dict)
count += 1

target = json.dumps(mid_list, ensure_ascii=False, indent=True)
target = target.replace("\"nanoid()\"", "nanoid()")
print(target)
# print("共有{}个链接".format(count))
ts_template_content = re.sub(r"<blockContent{}>".format(sequence), target, ts_template_content)
ts_template_content = re.sub(r"<blockName{}>".format(sequence), block_name, ts_template_content)
sequence += 1

ts_output.write(ts_template_content)
ts_output.close()
File renamed without changes.
Loading

0 comments on commit f7c5b54

Please sign in to comment.