mirror of
https://forge.chapril.org/tykayn/orgmode-to-gemini-blog
synced 2025-06-20 09:04:42 +02:00
site builder ok
This commit is contained in:
parent
7e9e8f2436
commit
83dd9f7472
27 changed files with 526 additions and 235 deletions
|
@ -15,10 +15,15 @@ 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"
|
||||
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"
|
||||
|
||||
footer_content=''
|
||||
after_article=''
|
||||
# with open(footer_content_path, "r") as f:
|
||||
# footer_content = f.read()
|
||||
|
||||
# variables du template de page
|
||||
BANNIERE_ENTETE=''
|
||||
BLOG_TITLE='Cipher Bliss'
|
||||
|
@ -47,23 +52,14 @@ ARTICLE=''
|
|||
FOOTER=''
|
||||
|
||||
|
||||
|
||||
def extract_body_content(html_content):
|
||||
pattern = r'<body>.+?</body>'
|
||||
pattern = r'<body[^>]*?>(.*?)</body>'
|
||||
match = re.search(pattern, html_content, re.DOTALL)
|
||||
if match:
|
||||
return match.group(1)
|
||||
else:
|
||||
return None
|
||||
def remove_before_body(text):
|
||||
pattern = r"<!DOCTYPE>.+?<body>"
|
||||
replacement = "<body>"
|
||||
return re.sub(pattern, replacement, text, flags=re.DOTALL)
|
||||
|
||||
def remove_after_body(text):
|
||||
pattern = r"</body>.+?</html>"
|
||||
replacement = "</body>"
|
||||
return re.sub(pattern, replacement, text, flags=re.DOTALL)
|
||||
|
||||
|
||||
def remove_properties_section(text):
|
||||
pattern = r"<h1 id=\"article\">Article</h1>.+?</ul>"
|
||||
|
@ -85,13 +81,13 @@ def remove_hint_html(text):
|
|||
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)
|
||||
print(' ----------- enrich_html: CSS inline: ',inline_the_css)
|
||||
# Trouver le fichier entête
|
||||
header_content=''
|
||||
with open(os.path.join(root_path, file), "r") as f:
|
||||
|
@ -101,12 +97,14 @@ def enrich_one_file(file, root_path):
|
|||
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)
|
||||
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')
|
||||
html_content = extract_body_content(html_content)
|
||||
|
||||
if inline_the_css is True:
|
||||
print(' ----------- enrich_html: 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>"
|
||||
|
@ -124,12 +122,9 @@ def enrich_one_file(file, root_path):
|
|||
<meta property="og:description" content="{BLOG_SUBTITLE}">
|
||||
<meta property="og:url" content="{NDD}">
|
||||
<meta property="og:site_name" content="Cipher Bliss">
|
||||
<link rel="alternate" type="application/rss+xml" title="Cipher Bliss » Flux"
|
||||
href="{NDD}/feed/">
|
||||
<link rel="alternate" type="application/rss+xml" title="Cipher Bliss » Flux" href="{NDD}/feed/">
|
||||
<link href="/style.css" rel="stylesheet">
|
||||
|
||||
<meta charset="utf-8">
|
||||
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>{TITLE}</title>
|
||||
<meta name="author" content="{AUTHOR}">
|
||||
|
@ -186,6 +181,9 @@ def enrich_one_file(file, root_path):
|
|||
<main class="body-wrap boxed-container">
|
||||
<article class="content">
|
||||
{html_content}
|
||||
<p class="after-article">
|
||||
{after_article}
|
||||
</p>
|
||||
</article>
|
||||
</main>
|
||||
<footer class="site-footer has-top-divider">
|
||||
|
@ -193,6 +191,7 @@ def enrich_one_file(file, root_path):
|
|||
<div class="site-footer-inner">
|
||||
|
||||
|
||||
|
||||
{NAVIGATION}
|
||||
|
||||
</div>
|
||||
|
@ -206,11 +205,11 @@ def enrich_one_file(file, root_path):
|
|||
"""
|
||||
|
||||
html_path_enriched=os.path.join(root_path, file)
|
||||
print(' html_path_enriched ============> ',html_path_enriched)
|
||||
print(' ----------- enrich_html: html_path_enriched ============> ',html_path_enriched)
|
||||
# Écrire le contenu modifié dans le fichier HTML
|
||||
with open(html_path_enriched, "w") as f:
|
||||
f.write(html_content)
|
||||
print('\n ----------- html écrit ', html_path_enriched)
|
||||
print('\n ----------- enrich_html: html écrit ', html_path_enriched)
|
||||
|
||||
# Parcourir tous les fichiers HTML dans le dossier
|
||||
for root, _, files in os.walk(blog_name):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue