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): if not os.makedirs(folder, exist_ok=True):
print(' │ Exists directory: %s'%folder) print(' │ Exists directory: %s'%folder)
# Create tyto.sidebar and metas.html # Create in _configs files
# Force will ask to create in template
print('') print('')
create_sidebar(option) #create_sidebar(option)
html.manage_configs('sidebar', '-n') #html.manage_configs('sidebar', 'Force')
create_navbar(option) #html.manage_configs('navbar', 'Force')
html.manage_configs('navbar', '-n') #html.manage_configs('metas', 'Force')
create_metas_file(option) html.manage_configs('footer', 'Force')
html.manage_configs('metas', '-n')
html.create_footer(option)
html.manage_configs('footer', '-n')
print('') print('')
print(' ├──────────────────────────────────────┐') print(' ├──────────────────────────────────────┐')

View File

@ -41,8 +41,8 @@ navbar_file = '%snavbar.html'%srv_wip_tpl
def manage_configs(target, option): def manage_configs(target, option):
args1 = ('metas', 'sidebar', 'footer', 'navbar') args1 = ('metas', 'sidebar', 'footer', 'navbar')
args2 = ('-n', '-e', '-R') args2 = ('-n', '-e', '-F', )
opts = ('New', 'Edit', 'Remove') opts = ('New', 'Edit', 'Force')
if target in args1: sys.argv[1] = target if target in args1: sys.argv[1] = target
elif target and not option: option = target elif target and not option: option = target
@ -51,12 +51,12 @@ def manage_configs(target, option):
tyto.exiting('11', '%s'%str(args2), True) tyto.exiting('11', '%s'%str(args2), True)
# Getting default file # Getting default file
if option == 'New':
actions = { actions = {
'sidebar' : domain.create_sidebar, 'sidebar' : domain.create_sidebar,
'navbar' : domain.create_navbar, 'navbar' : domain.create_navbar,
'metas' : create_user_metas, 'metas' : create_user_metas,
'footer' : html.create_footer 'footer' : create_footer
} }
actions[sys.argv[1]](option) actions[sys.argv[1]](option)
@ -101,11 +101,11 @@ def create_metas_page():
domain_relme domain_relme
) )
# Set all raw HTML metas # Set all raw HTML metas
#----------------------- #-----------------------
global metas global metas
metas = ' <meta charset="UTF-8" />\n' + \ metas = \
' <meta charset="UTF-8" />\n' + \
' <meta name="viewport" content="%s" />\n'%scale + \ ' <meta name="viewport" content="%s" />\n'%scale + \
' <meta name=”url” content=”%s” />\n'%domain_url + \ ' <meta name=”url” content=”%s” />\n'%domain_url + \
' <meta name="language" content="%s" />\n'%domain_lang + \ ' <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:title" content="%s" />\n'%title + \
' <meta property="og:type" content="article" />\n' + \ ' <meta property="og:type" content="article" />\n' + \
' <meta property="og:url" content="%s" />\n'%post_url + \ ' <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' + \ ' <meta property="og:image" content="" />\n' + \
'%s'%relme + \ '%s'%relme + \
'\n<!--# include virtual="/template/metas.html"-->\n' + \ '\n<!--# include virtual="/template/metas.html"-->\n' + \
' <title>%s</title>'%title ' <title>%s</title>'%title
#=======================================# #=======================================#
# Set main page, with all HTML sections # # Set main page, with all HTML sections #
#---------------------------------------# #---------------------------------------#
@ -158,7 +157,8 @@ def create_main_page(target, article_bottom):
#-----------------------# #-----------------------#
# Create main HTML Page # # Create main HTML Page #
#-----------------------# #-----------------------#
main_page = '<!Doctype html>\n' + \ main_page = \
'<!Doctype html>\n' + \
'<html lang="%s">\n'%domain_lang + \ '<html lang="%s">\n'%domain_lang + \
' <head>\n' + \ ' <head>\n' + \
'%s\n'%metas + \ '%s\n'%metas + \
@ -244,9 +244,9 @@ def create_navbar(option, target):
tyto.set_file(navbar_file, 'new', menu_html) 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): def create_user_metas(option):
domain.create_metas_file("-i") # Ensure config file exists domain.create_metas_file("-i") # Ensure config file exists
@ -279,16 +279,16 @@ def create_footer(option):
domain_licurl = "/" domain_licurl = "/"
# Default footer contents # 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' + \ ' <div id="footer_infos">\n' + \
' <a href="/"\n' + \ ' <a href="/"\n' + \
' title="%s"\n'%(tyto.trans[1][tyto.n]) + \ ' title="%s"\n'%(tyto.trans[1][tyto.n]) + \
' id="footer_title_link">\n' + \ ' id="footer_title_link">\n' + \
' <h1 id="footer_site_title">%s</h1>\n'%( ' <h1 id="footer_site_title">%s</h1>\n'%(domain_title) + \
domain_title) + \
' </a>\n' + \ ' </a>\n' + \
' <p id="footer_site_about">%s</p>\n'%( ' <p id="footer_site_about">%s</p>\n'%(domain_about) + \
domain_about) + \
' </div>\n' + \ ' </div>\n' + \
'\n' + \ '\n' + \
' <div id="footer_references">\n' + \ ' <div id="footer_references">\n' + \
@ -308,20 +308,60 @@ def create_footer(option):
' </li>\n' + \ ' </li>\n' + \
' </ul>\n' + \ ' </ul>\n' + \
' </div>\n' + \ ' </div>\n' + \
'</footer>\n' '</footer>'
# Create new file, or ask if exists # Create new file, or ask if exists
ask = ' ├ Use default footer.html ? ' ask_load = ' ├ Use default _configs/tyto.footer.html ? '
log = ' ├ Create file: %s'%footer_load 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 os.path.exists(footer_load):
if option == '-i': return if option == 'New':
res = input(ask) create_load = False
if not res in ['y', 'Y']: return else:
res = input(ask_load)
if not res in ['y', 'Y']: create_load = False
if create_load:
tyto.set_file(footer_load, 'new', footer) 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' + \ ' <li id="fotter_item">\n' + \
@ -332,26 +372,3 @@ def create_footer(option):
Copyright © 2021-2022 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)