- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAutoHtmlFinal.py
More file actions
Latest commit
52 lines (41 loc) · 1.86 KB
/
Copy pathAutoHtmlFinal.py
File metadata and controls
52 lines (41 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
importos
chapter_data= {
"chapter": 3,
"verses": [
"Não exaltar os talentosos previne a rivalidade.",
"Não valorizar tesouros raros evita o roubo.",
"Não exibir o desejável impede a confusão do coração.",
"O sábio governa esvaziando os corações e preenchendo os estômagos."
]
}
defgenerate_html_page():
output_dir="output"
os.makedirs(output_dir, exist_ok=True)
# Lê o template original do arquivo index-2.html
withopen("index-2.html", "r", encoding="utf-8") asf:
template=f.read()
chapter=chapter_data["chapter"]
# Adiciona link de volta para a página inicial
link_html='<p><a href="https://pdrodoc.github.io/tao/index.html" style="color: #569cd6;">← Voltar </a></p>'
# Gera os versos formatados com numeração e classes HTML
verses_html=link_html+"\n"+"\n".join(
[f'<p><span class="line-number">{i+1}</span><span class="verse">{v}</span></p>'fori, vinenumerate(chapter_data["verses"])]
)
# Substitui o conteúdo estático do template com placeholders ou via string
new_html=template
# Substitui o número do capítulo no título
new_html=new_html.replace("Capítulo 1", f"Capítulo {chapter}")
# Substitui os versos entre <p>...</p> até encontrar as dedicatórias
start=new_html.find('<p><span class="line-number">1')
end=new_html.find('<p class="dedication">')
ifstart!=-1andend!=-1:
new_html=new_html[:start] +verses_html+"\n"+new_html[end:]
# Salva novo HTML
filename=f"{output_dir}/index-{chapter}.html"
withopen(filename, "w", encoding="utf-8") asf:
f.write(new_html)
print(f"Generated: {filename}")
if__name__=="__main__":
print("Generating HTML using index-2.html as template...")
generate_html_page()
print("Done. Be aware, don't slip.")