This commit is contained in:
Tykayn 2024-11-14 16:22:34 +01:00 committed by tykayn
parent 086287fad3
commit 1d224cb8e4
1995 changed files with 66244 additions and 8957 deletions

View file

@ -1,8 +1,7 @@
#!/bin/python3
import argparse
import os
import re
from utils import *
from website_config import configs_sites
parser = argparse.ArgumentParser(description="Générer un site Web à partir de fichiers HTML.")
@ -15,47 +14,22 @@ args = parser.parse_args()
style_file = args.style
blog_name = args.blog_name.replace('html-websites/', '')
html_pages = 'html-websites/'+blog_name
source_blog = f"sources/{blog_name}"
header_content_path = f"{source_blog}/templates/converted/header_page.html"
footer_content_path = f"{source_blog}/templates/converted/footer_page.html"
static_page_path = f"{source_blog}/templates/html/static.html"
print('---------- blog name ', blog_name)
enable_header=True
# print('---------- blog name ', blog_name)
template_content = configs_sites[blog_name]
after_article = ''
inline_the_css = False
# inline_the_css=True
def extract_body_content(html_content):
pattern = r'<body[^>]*?>(.*?)</body>'
match = re.search(pattern, html_content, re.DOTALL)
if match:
return match.group(1)
else:
return None
def remove_properties_section(text):
pattern = r"<h1 id=\"article\">Article</h1>.+?</ul>"
replacement = ""
return re.sub(pattern, replacement, text, flags=re.DOTALL)
def remove_article_head_properties_orgmode(text):
pattern = r":PROPERTIES:.+?:END:"
replacement = ""
return re.sub(pattern, replacement, text, flags=re.DOTALL)
def remove_hint_html(text):
pattern = r"<p>ceci<sub>estduhtml</sub></p>"
replacement = ""
return re.sub(pattern, replacement, text, flags=re.DOTALL)
def enrich_one_file(html_content, partials={"header_page": "", "footer_content": ""}):
# remove some parts
@ -70,7 +44,8 @@ def enrich_one_file(html_content, partials={"header_page": "", "footer_content":
with open(os.path.join(root_path, file), "r") as f:
css_content = f.read()
css_content = "<style type='text/css'>{css_content}</style>"
template_content["CSS_INLINE_CONTENT"] = css_content
template_content["PAGE_SLUG"] = "la_page"
# remplir le template
html_content = f"""
@ -101,7 +76,7 @@ def enrich_one_file(html_content, partials={"header_page": "", "footer_content":
</head>
<body>
<div id="page">
<div id="page" class="page__{template_content["PAGE_SLUG"]}">
<header id="masthead" class="site-header">
<div class="header-image" style="background: url({template_content['BANNIERE_ENTETE']})">
<a href="/">
@ -182,19 +157,27 @@ def ouvrir_fichier(chemin_fichier):
else:
raise FileNotFoundError(f"Le fichier {chemin_fichier} n'existe pas.")
liste_fichiers_du_blog_convertis = os.walk(html_pages)
print('fichiers à enrichir:', liste_fichiers_du_blog_convertis)
# Parcourir tous les fichiers HTML dans le dossier du blog donné
for root_path, dirs, files in liste_fichiers_du_blog_convertis :
# Parcourir tous les fichiers HTML dans le dossier
for root_path, _, files in os.walk(blog_name):
# Prendre les templates partiaux pour chaque site web
partials = {
"header_content": "",
"footer_content": "",
}
partials["header_content"] = ouvrir_fichier(os.path.join(root_path, 'templates', 'header_page.org'))
partials["footer_content"] = ouvrir_fichier(os.path.join(root_path, 'templates', 'footer_page.org'))
print(len(files))
partials["header_content"] = ouvrir_fichier(os.path.join('sources',blog_name, 'templates', 'header_page.org'))
partials["footer_content"] = ouvrir_fichier(os.path.join('sources',blog_name, 'templates', 'footer_page.org'))
for file in files:
print(file)
if file is "index.html":
template_content['no_header']
if file.endswith(".html"):
print(' ----------- enrich_html: file:', os.path.join(root_path, file))