diff --git a/.gitignore b/.gitignore index 3806351343acbd0d70c46d708045009a11513ca6..8748abd6209fecc933a3aad50f754ee90fa277ac 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ out build +publish temp __pycache__ *.egg-info diff --git a/after_build.py b/after_build.py new file mode 100644 index 0000000000000000000000000000000000000000..8753c72e83d45baf66c8df316970b08134d2bc83 --- /dev/null +++ b/after_build.py @@ -0,0 +1,102 @@ +import os +from bs4 import BeautifulSoup + +path = "out\\doc\\" +api_path_list = [] + +for i in os.listdir(path): + if i.startswith("API_reference"): + api_path_list.append(path + i) + + +def find_html_files(path): + html_files = [] + for root, dirs, files in os.walk(path): + for file in files: + if file.endswith('.html'): + html_files.append(os.path.join(root, file)) + return html_files + + +def replace_version(file_path): + with open(file_path, 'r', encoding='utf-8') as file: + content = file.read() + + # 解析 HTML + soup = BeautifulSoup(content, "html.parser") + + # 查找 active 标签中的文本 + active_tag_list = soup.find_all("li", class_="active") + + # 筛选多余选项 + for i in active_tag_list: + active_content = i.text.strip() + if active_content.find("中文") == -1 and active_content.find("English") == -1: + break + # 获取version对应的标签 + version_tag = soup.find("a", string="Version") + + # 替换标签内容 + if version_tag: + version_tag.string = active_content + + # 将修改后的 HTML 写回文件 + with open(file_path, 'w', encoding='utf-8') as file: + file.write(soup.prettify()) + + +# 增加BSP相关版本选择器 +def add_bsp_selecter(file_path): + with open(file_path, 'r', encoding='utf-8') as file: + content = file.read() + + # 解析 HTML + soup = BeautifulSoup(content, "html.parser") + + toc_content_div = soup.find("div", id="toc-content") + + + # 创建一个新的 div 标签 + pagination_div = soup.new_tag('div', class_='pagination') + + # 创建 span 标签 + span_tag = soup.new_tag('span') + span_tag.string = '型号选择:' + + # 创建 select 标签 + select_tag = soup.new_tag('select', id='pageSelect') + + # 将 span 和 select 标签添加到 pagination_div 中 + pagination_div.append(span_tag) + pagination_div.append(select_tag) + + # 在 toc_content_div 之前插入新的 div 标签 + toc_content_div.insert_before(pagination_div) + + # 将修改后的 HTML 写回文件 + with open(file_path, 'w', encoding='utf-8') as file: + file.write(soup.prettify()) + + + +def main(): + html_files = [] + for path in api_path_list: + html_files += find_html_files(path) + + for file in html_files: + print(file) + replace_version(file) + + + bsp_filter = ["machine.I2C", "machine.SPI", "machine.Pin", "machine.UART", "machine.KeyPad", "misc.ADC"] + for path in api_path_list: + for i in bsp_filter: + if path.find(i) != -1: + print(path) + add_bsp_selecter(path) + + + +if __name__ == "__main__": + main() diff --git a/docs/API_reference/zh/peripherals/machine.SPI.md b/docs/API_reference/zh/peripherals/machine.SPI.md index 571c44606ad4726f5ad30c1c74f1d04b36a6c23a..17bf2b45e13e1f87e3c3760224fd6fb4fe86b593 100644 --- a/docs/API_reference/zh/peripherals/machine.SPI.md +++ b/docs/API_reference/zh/peripherals/machine.SPI.md @@ -88,7 +88,7 @@ -
+
class machine.I2C(I2Cn, MODE)
 

参数描述:

@@ -183,7 +183,35 @@ - +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
SPI编号CS引脚CLK引脚MOSI引脚MISO引脚
SPI0引脚58引脚61引脚59引脚60
SPI1引脚4引脚1引脚3引脚2
+ + @@ -406,7 +434,62 @@
SPI编号
- +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
SPI编号GroupCS引脚CLK引脚MOSI引脚MISO引脚
SPI0Group0引脚31引脚30引脚32引脚33
SPI0Group1引脚52引脚53引脚50引脚51
SPI1Group0引脚52引脚53引脚50引脚51
SPI1Group1引脚69引脚68引脚85引脚84
SPI2NULL引脚76引脚77引脚78引脚16
+ + @@ -489,7 +572,35 @@
SPI编号
- +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
SPI编号CS引脚CLK引脚MOSI引脚MISO引脚
SPI0引脚37引脚40引脚38引脚39
SPI1引脚26引脚27引脚25引脚24
+ + @@ -678,7 +789,42 @@
SPI编号
- +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
SPI编号CS引脚CLK引脚MOSI引脚MISO引脚
SPI0引脚31引脚30引脚32引脚33
SPI1引脚52引脚53引脚50引脚51
SPI2引脚74引脚75引脚76引脚77
+ + diff --git a/publish.py b/publish.py new file mode 100644 index 0000000000000000000000000000000000000000..8ee29f3c91893e8343b6a8bff4ae0203073059ff --- /dev/null +++ b/publish.py @@ -0,0 +1,315 @@ +''' +@Time : 2025/1/19 10:07 +@File : publish.py +@Software: +@Desc : 根据releaes tag创建待编译的文件夹,同步更新文件夹下的配置文件, +@Desc : 1. 通过gitee api获取tag列表, 2. 通过tag列表对应的commit获取版本文件, 3. 创建待编译的文件夹, 4. 同步更新文件夹下的配置文件 5. 更新全局配置文件 + + +''' +import time +import json +import requests +import zipfile +import os, shutil +import subprocess +from bs4 import BeautifulSoup, NavigableString + + +repo_url = "https://gitee.com/qpy-doc-center/api_reference.git" +access_token = "affe431c03995bd7d5bd4683e6e23096" + + +def get_tag_list(): + tag_api_url = "https://gitee.com/api/v5/repos/{owner}/{repo}/tags?sort=updated&direction=asc&page=1".format(owner="qpy-doc-center", repo="api_reference") + headers = { + "Authorization": "token " + access_token, + "Content-Type": "application/json" + } + response = requests.get(tag_api_url, headers=headers) + if response.status_code == 200: + tag_list = [] + for i in response.json(): + tag_list.append({"name": i["name"], "commit_sha": i["commit"]["sha"]}) + return tag_list + + else: + print("请求失败, 状态码: ", response.status_code) + return [] + + +def get_commit_file(name, commit_sha): + commit_api_url = "https://gitee.com/api/v5/repos/{owner}/{repo}/zipball".format(owner="qpy-doc-center", repo="api_reference") + file_path = name + ".zip" + commit_api_url = commit_api_url + "?access_token=" + access_token + "&ref=" + commit_sha + headers = { + "Content-Type": "application/json" + } + response = requests.get(commit_api_url, headers=headers) + if response.status_code == 200: + with open(file_path, "wb") as f: + for chunk in response.iter_content(chunk_size=16384): + f.write(chunk) + return file_path + else: + print("请求失败, 状态码: ", response.status_code) + return None + + +def set_site(page): + with open("../site_config.json", "r", encoding="utf-8") as f: + site_data = json.load(f) + + # 新增中文页面路由和英文页面路由 + site_data["route"]["docs"][page] = "docs" + page + site_data["translate"]["docs"][page] = [{ + "url": page.replace("zh", "en"), + "src": "docs" + page.replace("zh", "en"), + }] + with open("../site_config.json", "w", encoding="utf-8") as f: + json.dump(site_data, f, ensure_ascii=False, indent=4) + + +def set_config(tag, src): + try: + # 修改中文页面的Version下拉框 + with open("../docs/" + src + "/zh/config.json", "r", encoding="utf-8") as f: + config_data = json.load(f) + + items = [] + for index, i in enumerate(tag): + folder_url = "latest" if index == len(tag) - 1 else i["name"] + if folder_url == "latest": + folder_url = "" # 不使用latest url,因为避免修改存量的链接 + else: + folder_url = "_" + folder_url # 带版本的链接 + items.insert(0, { + "url": "/API_reference" + folder_url + "/zh/", + "label": i["name"] + "(latest)" if index == len(tag) - 1 else i["name"] + }) + + config_data["navbar"] = { + "items":[{ + "label": "Version", + "position": "right", + "type": "list", + "items": items + }] + } + with open("../docs/" + src + "/zh/config.json", "w", encoding="utf-8") as f: + json.dump(config_data, f, ensure_ascii=False, indent=4) + + + + # 修改英文页面的Version下拉框 + with open("../docs/" + src + "/en/config.json", "r", encoding="utf-8") as f: + config_data = json.load(f) + + items = [] + for index, i in enumerate(tag): + folder_url = "latest" if index == len(tag) - 1 else i["name"] + if folder_url == "latest": + folder_url = "" # 不使用latest url,因为避免修改存量的链接 + else: + folder_url = "_" + folder_url # 带版本的链接 + items.insert(0, { + "url": "/API_reference" + folder_url + "/en/", + "label": i["name"] + "(latest)" if index == len(tag) - 1 else i["name"] + }) + + config_data["navbar"] = { + "items":[{ + "label": "Version", + "position": "right", + "type": "list", + "items": items + }] + } + with open("../docs/" + src + "/en/config.json", "w", encoding="utf-8") as f: + json.dump(config_data, f, ensure_ascii=False, indent=4) + + except: + pass + + +def publish(): + # 删除历史发布临时文件夹 + if os.path.exists("./publish"): + shutil.rmtree("./publish") + os.mkdir("./publish") # 创建发布文件夹 + os.chdir("./publish") + + # 删除当前目录下旧的api文件 + for i in os.listdir("../docs"): + if i.startswith("API_reference"): + shutil.rmtree("../docs/" + i) + + + # 获取API_reference tag列表 + tag_list = get_tag_list() + + for tag in tag_list: + zip_file = get_commit_file("API_reference_" + tag["name"], tag["commit_sha"]) + # uzip file to temp publish folder + if zip_file: + with zipfile.ZipFile(zip_file, "r") as zf: + zf.extractall(zip_file.split(".zip")[0]) + os.remove(zip_file) + + # 移动文件到docs文件夹 + release_file_list = os.listdir() + for index, item in enumerate(release_file_list): + # 最后一级文件夹更名为latest---20250314 删除该逻辑 调整为API_reference + if index == len(release_file_list) - 1: + for file in os.listdir(item): + print(item + "/" + file + "/en/", " =======>> ", "../docs/API_reference/en") + shutil.move(item + "/" + file + "/en/", "../docs/API_reference/en") + print(item + "/" + file + "/zh/", " =======>> ", "../docs/API_reference/zh") + shutil.move(item + "/" + file + "/zh/", "../docs/API_reference/zh") + + # 设置 site_config.json 站点页面路由 + set_site("/API_reference/zh") + # 设置页面版本切换菜单 + set_config(tag_list, "API_reference") + else: + for file in os.listdir(item): + print(item + "/" + file + "/en/", " =======>> ", "../docs/" + item + "/en") + shutil.move(item + "/" + file + "/en/", "../docs/" + item + "/en") + print(item + "/" + file + "/zh/", " =======>> ", "../docs/" + item + "/zh") + shutil.move(item + "/" + file + "/zh/", "../docs/" + item + "/zh") + + # 设置 site_config.json 站点页面路由 + set_site("/" + item + "/zh") + # 设置页面版本切换菜单 + set_config(tag_list, item) + + os.chdir("..") + +def run_teedoc_build(): + try: + # 执行 teedoc build 命令 + result = subprocess.Popen(['teedoc', 'build'], shell=True, cwd=os.getcwd(), stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) + + # 打印命令的输出 + for line in result.stdout: + print(line.decode(encoding='utf-8', errors='ignore')) + + # 打印命令的错误信息(如果有) + if result.stderr: + print("命令错误:") + print(result.stderr) + + except subprocess.CalledProcessError as e: + # 如果命令执行失败,打印错误信息 + print(f"命令执行失败,错误代码: {e.returncode}") + print(f"错误信息: {e.stderr}") + + + + +def find_html_files(path): + html_files = [] + for root, dirs, files in os.walk(path): + for file in files: + if file.endswith('.html'): + html_files.append(os.path.join(root, file)) + return html_files + + +def replace_version(file_path): + with open(file_path, 'r', encoding='utf-8') as file: + content = file.read() + + # 解析 HTML + soup = BeautifulSoup(content, "html.parser") + + # 查找 active 标签中的文本 + active_tag_list = soup.find_all("li", class_="active") + + # 筛选多余选项 + for i in active_tag_list: + active_content = i.text.strip() + if active_content.startswith("V"): + break + # 获取version对应的标签 + version_tag = soup.find("a", string="Version") + + # 替换标签内容 + if version_tag: + version_tag.string = active_content + + # 将修改后的 HTML 写回文件 + with open(file_path, 'w', encoding='utf-8') as file: + file.write(soup.prettify()) + + +# 增加BSP相关版本选择器 +def add_bsp_selecter(file_path): + with open(file_path, 'r', encoding='utf-8') as file: + content = file.read() + + # 解析 HTML + soup = BeautifulSoup(content, "html.parser") + + toc_content_div = soup.find("div", id="toc_content") + + + # 创建一个新的 div 标签 + pagination_div = soup.new_tag('div', class_='pagination') + + # 创建 span 标签 + span_tag = soup.new_tag('span') + span_tag.string = '型号选择:' + + # 创建 select 标签 + select_tag = soup.new_tag('select', id='pageSelect') + + # 将 span 和 select 标签添加到 pagination_div 中 + pagination_div.append(span_tag) + pagination_div.append(select_tag) + + # 在 toc_content_div 之前插入新的 div 标签 + toc_content_div.insert_before(pagination_div) + toc_content_div.insert_before(NavigableString('\n')) + + + # 将修改后的 HTML 写回文件 + with open(file_path, 'w', encoding='utf-8') as file: + file.write(soup.prettify()) + + + +def main(): + path = "out\\doc\\" + api_path_list = [] + try: + for i in os.listdir(path): + if i.startswith("API_reference"): + api_path_list.append(path + i) + except Exception as e: + print("teedoc编译失败,未发现编译生成文件目录") + + # 获取所有api html列表 + html_files = [] + for path in api_path_list: + html_files += find_html_files(path) + + # 修改版本下拉选项 + for file in html_files: + print("replace_version: " + file) + replace_version(file) + + # 增加BSP相关版本选择器 + bsp_filter = ["machine.I2C", "machine.SPI", "machine.Pin", "machine.UART", "machine.KeyPad", "misc.ADC"] + for file in html_files: + for i in bsp_filter: + if file.find(i) != -1: + print("add_bsp_selecter: " + file) + add_bsp_selecter(file) + + + +if __name__ == "__main__": + publish() + run_teedoc_build() + main() diff --git a/readme_bsp.md b/readme_bsp.md new file mode 100644 index 0000000000000000000000000000000000000000..3c9c207d6d01836a0f9a6ce3ced5285a95ff8ff3 --- /dev/null +++ b/readme_bsp.md @@ -0,0 +1,99 @@ +# 文档中心API接口BSP分型号选择文档编写指南 + +## 概述 + +该文档描述如何编写BSP相关的md文档以达到文档页面可以选择型号来查看只包含对应型号BSP的文档 + +## 文档编写指南 + +针对文档中对于BSP部分的描述,需要使用表格、列表或者其他方式来展示不同平台的差异化参数的部分内容需要重新编写 + +编写后的内容会以html的形式呈现,但是文档本身还是markdown文件 + +需要注意的是对于不同形式的内容,需要使用不同的方法去编写 + +比如表格、无序列表、正文、 + +### 表格 + +原BSP的表格使用md格式编写,在一个表格中通过多行来区分平台之间的差异 + +新版文档中心中表格改为使用html编写,使用不同表格来区分不同平台 + +针对一个API文档中不同的表格,使用不同的html属性来区分 + +举例 + +'''html +
+
SPI编号
+表格内容 +
+ +表格内容 +
+
+''' + +- 其中table-QuecPython为html属性,EC600U和EC200U为表格的class属性 + +- 原文档中构造函数中的引脚对应关系表格使用 table-QuecPython + +- 原文档中常量表格使用 table-cons-QuecPython + +- 表格class属性按照实际型号列表编写(每一个型号都要写) + +- 两个位置的表格中型号要保持一致 + + +### 正文 + + +正文使用双重div标签将想要区分的型号包含起来 + +第一重标签为content-QuecPython + +第二重标签为具体的型号(如有重复的内容可以叠在一起写,使用|间隔) + + +'''html +
+
+
class machine.I2C(I2Cn, MODE)
+
+

参数描述:

+
    +
  • I2Cn - I2C 通路索引号,int类型,说明如下:
    I2C0 : 0 - 通道0
    I2C1 : 1 - 通道1
    I2C2 : 2 - 通道2

    +
  • +
  • MODE - I2C 的工作模式,int类型,说明如下:
    STANDARD_MODE : 0 - 标准模式
    FAST_MODE1 - 快速模式

    +
  • + +
+
+
+
class machine.I2C(I2Cn, MODE)
+
+

参数描述:

+
    +
  • I2Cn - I2C 通路索引号,int类型,说明如下:
    I2C0 : 0 - 通道0
    I2C1 : 1 - 通道1
    I2C2 : 2 - 通道2

    +
  • +
  • MODE - I2C 的工作模式,int类型,说明如下:
    STANDARD_MODE : 0 - 标准模式
    FAST_MODE1 - 快速模式
    ENHANCED_FAST_MODE2 - 快速模式增强

    +
  • +
+
+
+
class machine.I2C(I2Cn, MODE, [group])
+
+

参数描述:

+
    +
  • I2Cn - I2C 通路索引号,int类型,说明如下:
    I2C0 : 0 - 通道0
    I2C1 : 1 - 通道1
    I2C2 : 2 - 通道2

    +
  • +
  • MODE - I2C 的工作模式,int类型,说明如下:
    STANDARD_MODE : 0 - 标准模式
    FAST_MODE1 - 快速模式

    +
  • +
  • [group] - 选择在不同管脚使用IIC,缺省值为0

    +
  • +
+
+
+''' + diff --git a/readme_publish.md b/readme_publish.md new file mode 100644 index 0000000000000000000000000000000000000000..19cac5bb31828de5718fef8c55a0ec8d06769e87 --- /dev/null +++ b/readme_publish.md @@ -0,0 +1,46 @@ +# 文档中心API接口分版本方案发布脚本使用指南 + +## 概述 + +本脚本用于发布文档中心分版本方案,包括: + +- 发布前生成源文件(md)脚本 + +- 编译后修改编译生成文件脚本 + + +## 编译前 + +### 存放api文档仓库 + +https://gitee.com/qpy-doc-center/api_reference.git + + +### 编译前步骤 + +- 拉取仓库的release列表和对应版本的文档源文件 + +- 将拉取文档源文件拷贝到文档中心的docs下对应的版本目录下 + +- 生成版本文件对应配置项和版本选择对应的配置文件 + +## 编译 + +使用 teedoc build命令编译即可 + + +## 编译后 + +- 修改编译生成的html文件 + +- 注意: 最新的版本会被编译成latest以确保最新的api文档链接不会随着版本发布发生变化 + + +## 预览 + +进入out目录 + +使用 python -m http.server 80 启动一个http服务 + +访问 http://127.0.0.1/doc即可访问预览页面(注意:跟正式发布页面有细微差异) + diff --git a/site_config.json b/site_config.json index ce5ce0a5f1f806f8aa709f0b4ea4da516744ed0b..838e2dc1e831682349cfe46354d3a2d8078ba48d 100644 --- a/site_config.json +++ b/site_config.json @@ -8,10 +8,10 @@ "source": "https://toscode.gitee.com/qpy-doc-center/teedoc_with_qpydoc/blob/main/", "route": { "docs": { - "/API_reference/zh/": "docs/API_reference/zh", "/Getting_started/zh/": "docs/Getting_started/zh", "/Application_guide/zh/": "docs/Application_guide/zh", - "/FAQ/zh/": "docs/FAQ/zh" + "/FAQ/zh/": "docs/FAQ/zh", + "/API_reference/zh": "docs/API_reference/zh" }, "pages": { "/": "pages/index/zh" @@ -22,29 +22,34 @@ }, "translate": { "docs": { - "/API_reference/zh/": [ { - "url": "/API_reference/en/", - "src": "docs/API_reference/en" - } - ], - "/Getting_started/zh/": [ { + "/Getting_started/zh/": [ + { "url": "/Getting_started/en/", "src": "docs/Getting_started/en" } ], - "/Application_guide/zh/": [ { + "/Application_guide/zh/": [ + { "url": "/Application_guide/en/", "src": "docs/Application_guide/en" } ], - "/FAQ/zh/": [ { + "/FAQ/zh/": [ + { "url": "/FAQ/en/", "src": "docs/FAQ/en" } + ], + "/API_reference/zh": [ + { + "url": "/API_reference/en", + "src": "docs/API_reference/en" + } ] }, "pages": { - "/": [ { + "/": [ + { "url": "/en/", "src": "pages/index/en" } @@ -56,7 +61,7 @@ "pip": "pip3" }, "plugins": { - "teedoc-plugin-markdown-parser":{ + "teedoc-plugin-markdown-parser": { "from": "pypi", "config": { "mathjax": { @@ -64,24 +69,23 @@ } } }, - "teedoc-plugin-jupyter-notebook-parser":{ + "teedoc-plugin-jupyter-notebook-parser": { "from": "pypi", - "config": { - } + "config": {} }, - "teedoc-plugin-theme-default":{ + "teedoc-plugin-theme-default": { "from": "pypi", "config": { "dark": true, - "default_dark": false, + "default_dark": false, "mobile_navbar_collapsed": true, "toc_depth": 4, - "env":{ + "env": { "main_color": "#ED1922" } } }, - "teedoc-plugin-search":{ + "teedoc-plugin-search": { "from": "pypi", "config": { "search_hint": "Search" @@ -92,11 +96,25 @@ "config": { "code": "4d52982572d5512e9762879ebf063c86" } + }, + "teedoc-plugin-assets": { + "from": "pypi", + "config": { + "header_items": [ + "/static/css/custom.css" + ], + "footer_items": [ + "/static/js/custom.js" + ], + "env": { + "main_color": "#000000" + } + } } }, "rebuild_changes_delay": 1, - "robots":{ + "robots": { "User-agent": "*" }, "layout_root_dir": "layout" -} +} \ No newline at end of file diff --git a/static/css/custom.css b/static/css/custom.css index 708773e15e9c1d945d26cc42da87bbe415bca141..f6bed23471d8c7d277b7df9492bef5b59bbd48c0 100644 --- a/static/css/custom.css +++ b/static/css/custom.css @@ -1,123 +1,39 @@ -#navbar h2 { - color: ${main_color}; -} -#navbar .site_logo { - margin-right: 0.5em; -} -#page_footer { - margin-top: 0; -} -#home_page #page_content h1 { - width: 100%; - font-size: 6em; - text-align: center; - font-family: sans-serif; - color: ${main_color}; -} -#home_page h3 { - width: 100%; - text-align: center; -} -#navbar { - background: white; - z-index: 98; - box-shadow: 0px 0px 5px 0px #e4e4e4; -} -.dark #navbar { - background: #161616; - z-index: 98; - box-shadow: 0px 0px 5px 0px #0000002e; -} -#home_page .logo { - height: 2em; - vertical-align: middle; - filter: invert(56%) sepia(31%) saturate(171%) hue-rotate(196deg) brightness(87%) contrast(86%); -} -.big_btn_wrapper { - display: flex; - justify-content: space-evenly; - margin: 8em 1em; -} -#home_page .big_btn a { - padding: 2em; - background-color: ${main_color}; - font-size: 1.3em; - border-radius: 10px; - transition: 0.4s; - display: flex; - color: white; -} -#home_page .big_btn a:hover { - box-shadow: 6px 4px 20px #0000002e; -} -.md_page #page_content > div { - width: 100%; - max-width: 100%; - margin: auto; - line-height: 2em; -} -.dark #home_page .big_btn a { - background-color: #1b5638; - color: #d2f9e5; -} -.dark #home_page .big_btn a:hover { - box-shadow: 6px 4px 20px #000000; - background-color: #2a7d53; -} -#home_page .dark #navbar { - background: #1f1f1f; - box-shadow: 0px 0px 5px 0px #000000; -} -.section { - overflow: hidden; -} -.dsc_wrapper_left > div > div { - display: flex; - flex-direction: row; - align-items: center; +/* 版本选择器 */ +#toc span { + font-size: 18px; /* 你可以根据需要调整字体大小 */ + font-weight: bolder; /* 加粗 */ } -.dsc_wrapper_left .dsc_left { - width: 50%; - text-align: center; - color: #818395; -} -.dsc_wrapper_left .dsc_right { - flex-grow: 1; - text-align: center; - color: #818395; + +#toc { + margin-top: 20px; } -.dsc_wrapper_right > div > div { +.pagination { display: flex; - flex-direction: row; align-items: center; } -.dsc_wrapper_right .dsc_right { - width: 50%; - text-align: center; - color: #818395; -} -.dsc_wrapper_right .dsc_left { - flex-grow: 1; - text-align: center; - color: #818395; -} +#pageSelect { + margin-bottom: 18px; /* 可选:增加底部间距 */ + padding: 4px 10px; + margin-left: 4px; + border: 1px solid #ccc; + border-radius: 4px; + font-size: 16px; + background-color: #fff; + appearance: auto; /* 去掉默认的下拉箭头 */ + background-image: url('data:image/svg+xml;utf8,'); + background-repeat: no-repeat; + background-position: right 8px center; + background-size: 10px 6px; +} -@media screen and (max-width: 900px) { - #navbar #navbar_items { - display: none; - } - .dsc_wrapper_left > div > div { - flex-direction: column; - } - .dsc_wrapper_right > div > div { - flex-direction: column-reverse; - } - #home_page .big_btn a { - padding: 1em; - font-size: 1em; - } +#pageSelect:focus { + border-color: #007bff; + outline: none; + box-shadow: 0 0 5px rgba(0, 123, 255, 0.5); } + +/* 版本选择器 */ \ No newline at end of file diff --git a/static/css/theme_default/light.css b/static/css/theme_default/light.css index 2a6cb39febd5757ced7dbc7f4b89623841a4685e..92198ddfeae86c0cfc27a7f5a99f9d310bffdc9a 100644 --- a/static/css/theme_default/light.css +++ b/static/css/theme_default/light.css @@ -21,6 +21,8 @@ html { } + + /* global template */ body { color: var(--mid-10); @@ -1614,6 +1616,4 @@ table { font-size: 18px; font-weight: bold; line-height: 200%; -} - - +} \ No newline at end of file diff --git a/static/js/custom.js b/static/js/custom.js index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..ce137544790992415bf4494f822732b059067db1 100644 --- a/static/js/custom.js +++ b/static/js/custom.js @@ -0,0 +1,326 @@ +// API BSP接口表格分型号方案 + + +// BSP型号数据 ( 数据以API表格数量为准) +var BSPData = []; // 下拉框型号列表 +// API 表格数据 +var tableData_api = []; // 表格数据 +var headerData_api = []; // 表头数据 +// 常量 表格数据 +var tableData_cons = []; // 表格数据 +var headerData_cons = []; // 表头数据 +// 正文内容 +var content_list = []; +var content_global_list = []; + + + +function main() { + + // 判断是否有BSP相关的API表格 + var table_api = document.querySelector(".table-QuecPython") + + if (table_api) { + console.log("有api相关的表格"); + getTableData("api", table_api) + } else { + console.log("没有api相关的表格"); + } + + + // 判断是否有BSP相关的API常量表格 + var table_cons = document.querySelector(".table-cons-QuecPython") + + if (table_cons) { + console.log("有cons相关的表格"); + getTableData("cons", table_cons) + } else { + console.log("没有cons相关的表格"); + } + + content_list = document.querySelectorAll(".content-QuecPython") + console.log(content_list) + if (content_list) { + content_list.forEach(function(content) { + content_global = content.cloneNode(true) + content_global_list.push(content_global) + }) + } + console.log(content_global_list) + + console.log('BSP数据:', BSPData); + + // 渲染分页栏 + if (BSPData.length > 0) { + renderPagination(BSPData); + } + +} + + +// 获取表格数据 +function getTableData(type, tables) { + var elements = tables.querySelectorAll('table'); + elements.forEach(function(element) { + var BSPName = element.className + // 生成BSP型号数据 + if (type == "api") { + BSPData.push(BSPName) + } + + if (type == "api") { + // 表头数据 + if (headerData_api.length == 0) { + headerData_api.push("适用平台") + var thead = element.querySelector('thead'); + if (thead) { + var rows = thead.querySelectorAll('tr'); + if (rows) { + var headers = rows[0].querySelectorAll('th'); + headers.forEach(function(header) { + headerData_api.push(header.textContent.trim()); + }); + } + } + } + + // 表格数据 + var tbody = element.querySelector('tbody'); + if (tbody) { + var rows = tbody.querySelectorAll('tr'); + if (rows) { + rows.forEach(function(row) { + var cells = row.querySelectorAll('td'); + var rowData = {}; + rowData[headerData_api[0]] = BSPName + cells.forEach(function(cell, index) { + rowData[headerData_api[index + 1]] = cell.textContent.trim(); + }); + tableData_api.push(rowData); + }); + } + } + } + + if (type == "cons") { + // 表头数据 + if (headerData_cons.length == 0) { + headerData_cons.push("适用平台") + var thead = element.querySelector('thead'); + if (thead) { + var rows = thead.querySelectorAll('tr'); + if (rows) { + var headers = rows[0].querySelectorAll('th'); + headers.forEach(function(header) { + headerData_cons.push(header.textContent.trim()); + }); + } + } + } + + // 表格数据 + var tbody = element.querySelector('tbody'); + if (tbody) { + var rows = tbody.querySelectorAll('tr'); + if (rows) { + rows.forEach(function(row) { + var cells = row.querySelectorAll('td'); + var rowData = {}; + rowData[headerData_cons[0]] = BSPName + cells.forEach(function(cell, index) { + rowData[headerData_cons[index + 1]] = cell.textContent.trim(); + }); + tableData_cons.push(rowData); + }); + } + } + } + + }); + + // console.log('表格数据:', tableData_api, tableData_cons); + +} + + +// 渲染正文 +function renderContent(page) { + + // 判断是否有BSP相关的正文属性内容 + + console.log(content_global_list) + content_global_list.forEach(function(content_global, index) { + if (content_global) { + var divs = content_global.querySelectorAll("div"); + console.log(divs) + + for (const div of divs) { + match_flag = false + if (div.className.includes(page)) { + console.log("有BSP相关的正文属性内容"); + content_list[index].innerHTML = div.innerHTML + match_flag = true + break; + + }else{ + // div.style.display = "none" + } + } + if (match_flag == false) { + content_list[index].innerHTML = "" + console.log("ces正文属性内容") + } + } + + }) + + + +} + +// 渲染表格 +function renderTable(page) { + // 渲染API表格 + const table_div = document.querySelector(".table-QuecPython") + if ( table_div == null) { + // 如果没有api表格 默认视为也没有常量表格 + return; + } + table_div.innerHTML = ""; // 清空表格内容 + var pageData = [] + // 筛选表格中需要渲染的数据 + tableData_api.forEach(function(item) { + if (item[headerData_api[0]] == page) { + pageData.push(item) + } + }); + // console.log(pageData) + table_div.innerHTML = ` + + + + + + + +
+ `; + + const thead = table_div.querySelector("thead tr"); + headerData_api.forEach(function(header) { + const th = document.createElement("th"); + th.textContent = header; + thead.appendChild(th); + }); + const tbody = table_div.querySelector("tbody"); + pageData.forEach(item => { + const tr = document.createElement("tr"); + for (const key in item) { + if (item.hasOwnProperty(key)) { + const td = document.createElement("td"); + td.textContent = item[key]; + tr.appendChild(td); + } + } + // console.log(tr) + tbody.innerHTML += tr.outerHTML; + + }); + + // 渲染 常量表格 + const table_cons = document.querySelector(".table-cons-QuecPython") + if ( table_cons == null) { + // 如果没有常量表格 + return; + } + table_cons.innerHTML = ""; // 清空表格内容 + var pageData = [] + // 筛选表格中需要渲染的数据 + tableData_cons.forEach(function(item) { + if (item[headerData_cons[0]] == page) { + pageData.push(item) + } + }); + // console.log(pageData) + table_cons.innerHTML = ` + + + + + + + +
+ `; + + const thead_cons = table_cons.querySelector("thead tr"); + headerData_cons.forEach(function(header) { + const th = document.createElement("th"); + th.textContent = header; + thead_cons.appendChild(th); + }); + + const tbody_cons = table_cons.querySelector("tbody"); + pageData.forEach(item => { + const tr = document.createElement("tr"); + for (const key in item) { + if (item.hasOwnProperty(key)) { + const td = document.createElement("td"); + td.textContent = item[key]; + tr.appendChild(td); + } + } + // console.log(tr) + tbody_cons.innerHTML += tr.outerHTML; + }); + + +} + + + +// 渲染型号选择下拉框 +function renderPagination(data) { + + const pageSelect = document.querySelector("#pageSelect"); + pageSelect.innerHTML = ""; // 清空下拉框内容 + + + data.forEach(function(item) { + const option = document.createElement("option"); + option.value = item; + option.textContent = item; + pageSelect.appendChild(option); + }); + + + // 监听下拉框变化 + pageSelect.addEventListener("change", (event) => { + currentPage = event.target.value; + renderTable(currentPage); + renderContent(currentPage); + }); +} + + + +// 页面刷新进入的响应函数 (初始化时主动刷新) +$(document).ready(function(){ + main(); + + + if (BSPData.length > 0) { + // 默认显示html中排序为最靠前的型号 + renderTable(BSPData[0]) + renderContent(BSPData[0]) + } + + +}); + + + + +// TODO CSS样式调整 + +// 修改light.css