#!/bin/python3 import os import argparse import re parser = argparse.ArgumentParser(description="Générer un site Web à partir de 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 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/footer_page.org" static_page_path = f"{source_blog}/templates/html/static.html" # variables du template de page BANNIERE_ENTETE='' BLOG_TITLE='Cipher Bliss' BLOG_SUBTITLE='Code, nouvelles technologies et entrepreneurariat par B. Lemoine' TITLE='' AUTHOR='' PAGE_TITLE='' LOCALE='fr_FR' DESCRIPTION='' NDD='https://www.cipherbliss.com' EMAIL='contact@cipherbliss.com' SITE_ICON='https://www.cipherbliss.com/wp-content/uploads/2016/12/rond.png' SITE_ICON_TYPE='image/png' NAVIGATION=""" """ BANNIERE_ENTETE='https://www.cipherbliss.com/wp-content/uploads/2016/11/bg.jpg' BANNIERE_ENTETE_ALT='bannière du site' ARTICLE='' FOOTER='' def extract_body_content(html_content): pattern = r'
.+?' match = re.search(pattern, html_content, re.DOTALL) if match: return match.group(1) else: return None def remove_before_body(text): pattern = r".+?" replacement = "" return re.sub(pattern, replacement, text, flags=re.DOTALL) def remove_after_body(text): pattern = r".+?" replacement = "" return re.sub(pattern, replacement, text, flags=re.DOTALL) def remove_properties_section(text): pattern = r"
.+?" 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"
ceciestduhtml
" replacement = "" return re.sub(pattern, replacement, text, flags=re.DOTALL) def enrich_one_file(file, root_path): 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() # remove some parts # html_content = remove_properties_section(html_content) # html_content = remove_article_head_properties_orgmode(html_content) # html_content = remove_hint_html(html_content) if inline_the_css == True: 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 = "" # remplir le template html_content = f"""