68 lines
2.1 KiB
Python
68 lines
2.1 KiB
Python
|
|
#!/usr/bin/env python3
|
|||
|
|
# -*- coding: utf-8 -*-
|
|||
|
|
|
|||
|
|
import os
|
|||
|
|
|
|||
|
|
def read_ehs_content():
|
|||
|
|
"""
|
|||
|
|
读取EHS项目的完整内容
|
|||
|
|
"""
|
|||
|
|
project_folder = "网页未导入数据/能源产业/学生完成的项目"
|
|||
|
|
|
|||
|
|
# 查找EHS文件
|
|||
|
|
for file in os.listdir(project_folder):
|
|||
|
|
if "EHS" in file and file.endswith(".md"):
|
|||
|
|
file_path = os.path.join(project_folder, file)
|
|||
|
|
with open(file_path, 'r', encoding='utf-8') as f:
|
|||
|
|
content = f.read()
|
|||
|
|
return content, file.replace(".md", "")
|
|||
|
|
return None, None
|
|||
|
|
|
|||
|
|
def generate_clickable_projects_code():
|
|||
|
|
"""
|
|||
|
|
生成可点击项目的JavaScript代码
|
|||
|
|
"""
|
|||
|
|
content, title = read_ehs_content()
|
|||
|
|
if not content:
|
|||
|
|
print("未找到EHS项目文件")
|
|||
|
|
return
|
|||
|
|
|
|||
|
|
# 转义特殊字符
|
|||
|
|
content_escaped = content.replace('\\', '\\\\').replace('`', '\\`').replace('${', '\\${')
|
|||
|
|
|
|||
|
|
# 生成JavaScript代码
|
|||
|
|
js_code = f''' // 可点击查看的特殊项目
|
|||
|
|
const clickableProjects = [
|
|||
|
|
{{
|
|||
|
|
id: "energy-clickable-1",
|
|||
|
|
name: "{title}",
|
|||
|
|
unitName: "EHS管理体系",
|
|||
|
|
isClickable: true,
|
|||
|
|
content: {{
|
|||
|
|
title: "{title}",
|
|||
|
|
description: "本项目以"安绿一体"EHS管理体系建设与运行示范项目,体现了在EHS(环境、健康、安全)体系中将安全管理与环境管理深度融合的理念。",
|
|||
|
|
images: [],
|
|||
|
|
sections: [
|
|||
|
|
{{
|
|||
|
|
title: "项目详情",
|
|||
|
|
content: `{content_escaped}`
|
|||
|
|
}}
|
|||
|
|
],
|
|||
|
|
relatedPositions: [
|
|||
|
|
{{ name: "EHS工程师", level: "技术骨干岗" }},
|
|||
|
|
{{ name: "安全管理专员", level: "普通岗" }},
|
|||
|
|
{{ name: "环保工程师", level: "技术骨干岗" }}
|
|||
|
|
]
|
|||
|
|
}}
|
|||
|
|
}}
|
|||
|
|
];'''
|
|||
|
|
|
|||
|
|
# 保存到文件
|
|||
|
|
with open("clickable_projects_update.js", 'w', encoding='utf-8') as f:
|
|||
|
|
f.write(js_code)
|
|||
|
|
|
|||
|
|
print(f"✅ JavaScript代码已生成到:clickable_projects_update.js")
|
|||
|
|
print(f"📋 项目标题:{title}")
|
|||
|
|
|
|||
|
|
if __name__ == "__main__":
|
|||
|
|
generate_clickable_projects_code()
|