Skip to content

Commit 5df4e1b

Browse files
author
黄佰荣
committed
window环境的构建脚本
1 parent 4df201c commit 5df4e1b

File tree

3 files changed

+42
-11
lines changed

3 files changed

+42
-11
lines changed

qpython-docs/add-analytics-window.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import sys
2+
import os
3+
4+
def process_file(input_file, output_file, extra_file):
5+
# 确保 extra.txt 文件存在
6+
if not os.path.exists(extra_file):
7+
print(f"Error: The file '{extra_file}' does not exist.")
8+
return
9+
10+
# 获取 extra.txt 文件内容
11+
with open(extra_file, 'r', encoding='utf-8') as e:
12+
extra = e.read().replace("{{PTH}}", input_file[1:]) # 用路径替换 {{PTH}}
13+
14+
# 逐行读取输入文件并处理内容
15+
with open(input_file, 'r', encoding='utf-8') as f, open(output_file, 'w', encoding='utf-8') as g:
16+
for line in f:
17+
line = line.strip() # 去除行首和行尾空白字符
18+
if line: # 忽略空行
19+
# 如果是特定标签,添加 extra 和 <hr/> 内容
20+
if line == '<div role="contentinfo">':
21+
g.write(extra + "<hr/>\n")
22+
else:
23+
g.write(line + '\n') # 写入处理后的行
24+
25+
# 替换原始文件
26+
os.rename(output_file, input_file)
27+
28+
def main():
29+
if len(sys.argv) < 2:
30+
print("Usage: python script.py <input_file>")
31+
return
32+
33+
input_file = sys.argv[1]
34+
output_file = './qpydoc.tmp'
35+
extra_file = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'extra.txt')
36+
37+
# 处理文件
38+
process_file(input_file, output_file, extra_file)
39+
40+
if __name__ == '__main__':
41+
main()

qpython-docs/add-analytics-windown.py

Lines changed: 0 additions & 10 deletions
This file was deleted.

qpython-docs/build-window.bat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ cd build/html
66

77
REM 使用 Python 执行 add-analytics.py 脚本
88
@REM for /r %%f in (*.html) do (
9-
python ..\..\add-analytics.py "%%f"
9+
python ..\..\add-analytics-window.py "%%f"
1010
@REM )
1111

1212
REM 替换 _static 为 static,_images 为 images

0 commit comments

Comments
 (0)