replace org content, make global style for generated site

This commit is contained in:
Tykayn 2024-11-09 00:19:43 +01:00 committed by tykayn
parent 3539a8a496
commit f5c73ffd33
2990 changed files with 49840 additions and 75227 deletions

View file

@ -4,43 +4,73 @@ import argparse
parser = argparse.ArgumentParser(description="Générer un site Web à partir de fichiers HTML.")
parser.add_argument("html_dir", help="Le chemin vers le dossier contenant les fichiers HTML.")
parser.add_argument("blog_name", help="Le chemin vers le dossier contenant les fichiers HTML.")
parser.add_argument("--title", "-t", default="Mon site Web", help="Le titre du site Web.")
parser.add_argument("--style", default="templates/style_general.css", help="Le chemin vers le fichier de style CSS.")
args = parser.parse_args()
# Style CSS minimaliste
style_file = args.style
css_content = ""
inline_the_css=False
# inline_the_css=True
html_dir = args.html_dir
blog_name = args.blog_name
source_blog = f"sources/{blog_name}"
header_content_path = f"{source_blog}/templates/header_page.org"
footer_content_path = f"{source_blog}/templates/header_page.org"
def enrich_one_file(file, root_path):
print('enrich html file:',os.path.join(root_path, file))
print(' ----------- enrich html file:',os.path.join(root_path, file))
css_content = ""
inline_the_css=False
# inline_the_css=True
print(' ----------- CSSS inline: ',inline_the_css)
# Trouver le fichier entête
header_content=''
with open(os.path.join(root_path, file), "r") as f:
header_content = f.read()
# Ouvrir le fichier HTML en mode lecture
with open(os.path.join(root_path, file), "r") as f:
html_content = f.read()
if inline_the_css:
print('include css inline in each html page')
print(' ----------- include css inline in each html page')
with open(os.path.join(root_path, file), "r") as f:
css_content = f.read()
css_content = "<style type='text/css'>{css_content}</style>"
# Ajouter la déclaration de charset UTF-8, le doctype HTML et le titre du site Web
html_content = f"<!DOCTYPE html>\n<html lang=\"fr\">\n<head>\n<meta charset=\"UTF-8\">\n<title>{args.title}</title>\n{css_content}<link type='stylesheet/css' href='/style.css'></link></head>\n<body>\n<a href='/'>Retour à l'Accueil</a><hr/>{html_content}\n<footer><hr/><a href='/'>Retour à l'Accueil</a></footer></body>\n</html>"
html_content = f"""<!DOCTYPE html>
<html lang=\"fr\">
<head>
<meta charset=\"UTF-8\">
<title>{args.title}</title>
{css_content}
<link rel=\"stylesheet\" href=\"/style.css\"></link>
</head>
<body>
<a href=\"/\">Retour à l'Accueil</a>
<hr/>
{html_content}
<footer>
<hr/>
<a href='/'>Retour à l'Accueil</a>
</footer>
</body>
</html>"""
html_path_enriched=os.path.join(root_path, file)
# Écrire le contenu modifié dans le fichier HTML
with open(os.path.join(root_path, file), "w") as f:
with open(html_path_enriched, "w") as f:
f.write(html_content)
print('\n ----------- html écrit ', html_path_enriched)
# Parcourir tous les fichiers HTML dans le dossier
for root, _, files in os.walk(html_dir):
print(files)
for root, _, files in os.walk(blog_name):
# print(files)
for file in files:
if file.endswith(".html"):
enrich_one_file(file, root)