indev: changed code for managing tyto.footer.html and footer.html

This commit is contained in:
Cyrille L 2023-01-16 01:24:51 +01:00
parent 73546b5966
commit 9adb8ec8c8
2 changed files with 155 additions and 140 deletions

View File

@ -429,16 +429,14 @@ def create_domain(target, option):
if not os.makedirs(folder, exist_ok=True):
print(' │ Exists directory: %s'%folder)
# Create tyto.sidebar and metas.html
# Create in _configs files
# Force will ask to create in template
print('')
create_sidebar(option)
html.manage_configs('sidebar', '-n')
create_navbar(option)
html.manage_configs('navbar', '-n')
create_metas_file(option)
html.manage_configs('metas', '-n')
html.create_footer(option)
html.manage_configs('footer', '-n')
#create_sidebar(option)
#html.manage_configs('sidebar', 'Force')
#html.manage_configs('navbar', 'Force')
#html.manage_configs('metas', 'Force')
html.manage_configs('footer', 'Force')
print('')
print(' ├──────────────────────────────────────┐')

View File

@ -41,8 +41,8 @@ navbar_file = '%snavbar.html'%srv_wip_tpl
def manage_configs(target, option):
args1 = ('metas', 'sidebar', 'footer', 'navbar')
args2 = ('-n', '-e', '-R')
opts = ('New', 'Edit', 'Remove')
args2 = ('-n', '-e', '-F', )
opts = ('New', 'Edit', 'Force')
if target in args1: sys.argv[1] = target
elif target and not option: option = target
@ -51,12 +51,12 @@ def manage_configs(target, option):
tyto.exiting('11', '%s'%str(args2), True)
# Getting default file
if option == 'New':
actions = {
'sidebar' : domain.create_sidebar,
'navbar' : domain.create_navbar,
'metas' : create_user_metas,
'footer' : html.create_footer
'footer' : create_footer
}
actions[sys.argv[1]](option)
@ -101,11 +101,11 @@ def create_metas_page():
domain_relme
)
# Set all raw HTML metas
#-----------------------
global metas
metas = ' <meta charset="UTF-8" />\n' + \
metas = \
' <meta charset="UTF-8" />\n' + \
' <meta name="viewport" content="%s" />\n'%scale + \
' <meta name=”url” content=”%s” />\n'%domain_url + \
' <meta name="language" content="%s" />\n'%domain_lang + \
@ -126,14 +126,13 @@ def create_metas_page():
' <meta property="og:title" content="%s" />\n'%title + \
' <meta property="og:type" content="article" />\n' + \
' <meta property="og:url" content="%s" />\n'%post_url + \
' <meta property="og:description" content="Description Here" />\n' + \
' <meta property="og:description" content="%s" />\n'%about + \
' <meta property="og:image" content="" />\n' + \
'%s'%relme + \
'\n<!--# include virtual="/template/metas.html"-->\n' + \
' <title>%s</title>'%title
#=======================================#
# Set main page, with all HTML sections #
#---------------------------------------#
@ -158,7 +157,8 @@ def create_main_page(target, article_bottom):
#-----------------------#
# Create main HTML Page #
#-----------------------#
main_page = '<!Doctype html>\n' + \
main_page = \
'<!Doctype html>\n' + \
'<html lang="%s">\n'%domain_lang + \
' <head>\n' + \
'%s\n'%metas + \
@ -244,9 +244,9 @@ def create_navbar(option, target):
tyto.set_file(navbar_file, 'new', menu_html)
#
# Create metas.html from tyto.metas.html
#
#========================================#
# Create metas.html from tyto.metas.html #
#----------------------------------------#
def create_user_metas(option):
domain.create_metas_file("-i") # Ensure config file exists
@ -279,16 +279,16 @@ def create_footer(option):
domain_licurl = "/"
# Default footer contents
footer = '<footer id="footer_page">\n' + \
footer = \
'<!-- Default <footer> generated by %s -->\n'%Tyto + \
'<footer id="footer_page">\n' + \
' <div id="footer_infos">\n' + \
' <a href="/"\n' + \
' title="%s"\n'%(tyto.trans[1][tyto.n]) + \
' id="footer_title_link">\n' + \
' <h1 id="footer_site_title">%s</h1>\n'%(
domain_title) + \
' <h1 id="footer_site_title">%s</h1>\n'%(domain_title) + \
' </a>\n' + \
' <p id="footer_site_about">%s</p>\n'%(
domain_about) + \
' <p id="footer_site_about">%s</p>\n'%(domain_about) + \
' </div>\n' + \
'\n' + \
' <div id="footer_references">\n' + \
@ -308,20 +308,60 @@ def create_footer(option):
' </li>\n' + \
' </ul>\n' + \
' </div>\n' + \
'</footer>\n'
'</footer>'
# Create new file, or ask if exists
ask = ' ├ Use default footer.html ? '
log = ' ├ Create file: %s'%footer_load
ask_load = ' ├ Use default _configs/tyto.footer.html ? '
log_load = ' ├ Create file: %s'%footer_load
create_load = True
footer_html = '%sfooter.html'%srv_wip_tpl
ask_html = ' ├ Replace template/footer.html ' + \
'from _configs/tyto.footer.html ? '
log_html = ' ├ Create file: %s'%footer_html
create_html = True
user_footer = ''
# Auto create if not tyto.footer.html in _configs
# Pass if exists, user not wants, option is 'New' (only footer.html)
res = ''
if os.path.exists(footer_load):
if option == '-i': return
res = input(ask)
if not res in ['y', 'Y']: return
if option == 'New':
create_load = False
else:
res = input(ask_load)
if not res in ['y', 'Y']: create_load = False
if create_load:
tyto.set_file(footer_load, 'new', footer)
print(log)
print(log_load)
# Auto create if not footer.html in template/
# Create if option is 'New'
res = ''
if os.path.exists(footer_html):
if option == 'New':
create_html = True
else:
res = input(ask_html)
if not res in ['y', 'Y']: create_html = False
if create_html:
user_file = open(footer_load, 'r').read()
for line in user_file.rsplit('\n'):
if not line: continue
if user_footer: user_footer = "%s\n %s"%(user_footer, line)
else: user_footer = ' %s'%line
tyto.set_file(footer_html, 'new', user_footer)
print(log_html)
'''
' <li id="fotter_item">\n' + \
@ -332,26 +372,3 @@ def create_footer(option):
Copyright © 2021-2022
'''
#
# Create footer.html from tyto.footer.html
#
def create_user_footer(option):
create_footer("-i") # Ensure config file exists
footer_html = '%sfooter.html'%srv_wip_tpl
user_footer = ''
noline = ('<!--')
log = ' ├ Create file: %s'%footer_html
try:
user_file = open(footer_load, 'r').read()
for line in user_file.rsplit('\n'):
if line.startswith(noline): continue
if user_metas: user_metas = "%s\n %s"%(user_metas, line)
else: user_metas = ' %s'%line
tyto.set_file(footer_html, 'new', user_footer)
print(log)
except:
tyto.exiting("24", '(metas file): %s'%footer_load, False)