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

@ -230,6 +230,7 @@ def html_main_page(wip_html):
[ '%sheader.html'%domain.srv_wip_template, headers ], [ '%sheader.html'%domain.srv_wip_template, headers ],
[ '%sfooter.html'%domain.srv_wip_template, footers ], [ '%sfooter.html'%domain.srv_wip_template, footers ],
] ]
for file_tpl in files_tpl: for file_tpl in files_tpl:
if not os.path.exists(file_tpl[0]): if not os.path.exists(file_tpl[0]):
datas = open(file_tpl[0], 'w') datas = open(file_tpl[0], 'w')
@ -238,16 +239,25 @@ def html_main_page(wip_html):
msg_log = 'Create default file: %s'%file_tpl[0] msg_log = 'Create default file: %s'%file_tpl[0]
log.append_f(check.post_logs, msg_log, 0) log.append_f(check.post_logs, msg_log, 0)
#------------------#
# Create full page # Create full page #
#----------------- #------------------#
page = '<!DOCTYPE html>\n' + \ page = '<!DOCTYPE html>\n' + \
' <html lang="%s">\n'%domain.domain_lang + \ ' <html lang="%s">\n'%domain.domain_lang + \
' <head>' ' <head>'
# Add tab metas in page # Add tab metas in page
#----------------------
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'): for meta in metas.rsplit('\n'):
page = '%s\n%s%s'%(page, 6*' ', meta) 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*' ') + \ page = '%s\n%s</head>\n'%(page, 4*' ') + \
'\n%s<body id="%s" class="%s">'%( '\n%s<body id="%s" class="%s">'%(
@ -255,14 +265,24 @@ def html_main_page(wip_html):
) )
# Add tab header in page # Add tab header in page
#-----------------------
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'): for header in headers.rsplit('\n'):
page = '%s\n%s%s'%(page, 6*' ', header) 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 # Add tab article in page
for article in articles.rsplit('\n'): for article in articles.rsplit('\n'):
page = '%s\n%s%s'%(page, 6*' ', article) page = '%s\n%s%s'%(page, 6*' ', article)
# Add post from wip.html # Add post from wip.html
#-----------------------
for line in wip_html: for line in wip_html:
page = '%s\n%s%s'%(page, 4*' ', line) page = '%s\n%s%s'%(page, 4*' ', line)
page = '%s\n%s</article>\n'%(page, 8*' ') page = '%s\n%s</article>\n'%(page, 8*' ')
@ -275,8 +295,16 @@ def html_main_page(wip_html):
# Add footer in page # Add footer in page
#------------------- #-------------------
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'): for footer in footers.rsplit('\n'):
page = '%s\n%s%s'%(page, 4*' ', footer) 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) print(page)