html: use template file else defaut

This commit is contained in:
Cyrille L 2022-11-24 11:28:18 +01:00
parent f2d1f341dd
commit 3e3885edf6
1 changed files with 39 additions and 11 deletions

View File

@ -222,7 +222,7 @@ def html_main_page(wip_html):
' </div>\n' + \
'</footer>'
# Create file if not exists
#--------------------------
files_tpl = [
@ -230,6 +230,7 @@ def html_main_page(wip_html):
[ '%sheader.html'%domain.srv_wip_template, headers ],
[ '%sfooter.html'%domain.srv_wip_template, footers ],
]
for file_tpl in files_tpl:
if not os.path.exists(file_tpl[0]):
datas = open(file_tpl[0], 'w')
@ -238,31 +239,50 @@ def html_main_page(wip_html):
msg_log = 'Create default file: %s'%file_tpl[0]
log.append_f(check.post_logs, msg_log, 0)
# Create full page
#-----------------
#------------------#
# Create full page #
#------------------#
page = '<!DOCTYPE html>\n' + \
' <html lang="%s">\n'%domain.domain_lang + \
' <head>'
# Add tab metas in page
for meta in metas.rsplit('\n'):
page = '%s\n%s%s'%(page, 6*' ', meta)
#----------------------
if os.path.exists(files_tpl[0][0]):
metas_datas = open(files_tpl[0][0], 'r').read()
for meta_line in metas_datas.rsplit('\n'):
page = '%s\n%s%s'%(page, 6*' ', meta_line)
else:
# No file: use this default
for meta in metas.rsplit('\n'):
page = '%s\n%s%s'%(page, 6*' ', meta)
msg_log = 'Use default metas in page. Unused file: %s'%files_tpl[0][0]
log.append_f(check.post_logs, msg_log, 0)
page = '%s\n%s</head>\n'%(page, 4*' ') + \
'\n%s<body id="%s" class="%s">'%(
4*' ', post_ID, domain.domain_css
)
# Add tab header in page
for header in headers.rsplit('\n'):
page = '%s\n%s%s'%(page, 6*' ', header)
#-----------------------
if os.path.exists(files_tpl[1][0]):
headers_datas = open(files_tpl[1][0], 'r').read()
for header_line in headers_datas.rsplit('\n'):
page = '%s\n%s%s'%(page, 6*' ', header_line)
else:
# No file: use this default
for header in headers.rsplit('\n'):
page = '%s\n%s%s'%(page, 6*' ', header)
msg_log = 'Use default header in page. Unused file: %s'%files_tpl[1][0]
log.append_f(check.post_logs, msg_log, 0)
# Add tab article in page
for article in articles.rsplit('\n'):
page = '%s\n%s%s'%(page, 6*' ', article)
# Add post from wip.html
#-----------------------
for line in wip_html:
page = '%s\n%s%s'%(page, 4*' ', line)
page = '%s\n%s</article>\n'%(page, 8*' ')
@ -275,8 +295,16 @@ def html_main_page(wip_html):
# Add footer in page
#-------------------
for footer in footers.rsplit('\n'):
page = '%s\n%s%s'%(page, 4*' ', footer)
if os.path.exists(files_tpl[2][0]):
footers_datas = open(files_tpl[2][0], 'r').read()
for footer_line in footers_datas.rsplit('\n'):
page = '%s\n%s%s'%(page, 4*' ', footer_line)
else:
# No file: use this default
for footer in footers.rsplit('\n'):
page = '%s\n%s%s'%(page, 4*' ', footer)
msg_log = 'Use default footer in page. Unused file: %s'%files_tpl[2][0]
log.append_f(check.post_logs, msg_log, 0)
print(page)