updated footer/metas/navbar/sidebar managing

This commit is contained in:
Cyrille L 2023-02-16 11:36:40 +01:00
parent 50baaf14f2
commit 6eec2a7d90
4 changed files with 173 additions and 162 deletions

View File

@ -497,10 +497,12 @@ def create_domain(target):
print(' │ Exists directory: %s'%folder)
# Create in _configs files
# Force will ask to create in template
# Parameter could be used later
print('')
create_sidebar('new')
create_navbar('new')
create_metas('new')
create_footer('new')
print('')
print(' ├──────────────────────────────────────┐')
@ -536,11 +538,15 @@ def create_sidebar(option):
if not res in ['y', 'Y']: return
# French sidebar_load content
sdb_load_fr = '# Pour : Tyto - Littérateur\n' + \
sdb_load_fr = \
'# Pour : Tyto - Littérateur\n' + \
'# Type : fichier texte\n' + \
'# Description : Fichier appelé par "tyto sidebar"\n' + \
'# (Liste d\'articles)\n' + \
'# Fichier : %s\n'%db.sidebar_load + \
"# Commandes: tyto new sidebar (réinitialiser)\n" + \
'# tyto wip/publish sidebar (créer)\n' + \
'# tyto edit sidebar (editer ce fichier)\n' + \
'# Comment : 1 URI de l\'article par ligne\n' + \
'# (depuis articles/)\n' + \
'# Ne commence pas par "/"\n' + \
@ -552,12 +558,16 @@ def create_sidebar(option):
'# %s\n\n'%(15 * "-")
# English sidebar_load content
sdb_load_en = '# For: Tyto - Littérateur\n' + \
sdb_load_en = \
'# For: Tyto - Littérateur\n' + \
'# Type: Text file\n' + \
'# Description: file called with "tyto sidebar"\n' + \
'# (articles\'s list)\n' + \
'# File: %s\n'%db.sidebar_load + \
'# Comment: 1 article URI per line\n' + \
'# Commands: tyto new sidebar (reset)\n' + \
'# tyto wip/publish sidebar (Create)\n' + \
'# tyto edit sidebar (edit this file)\n' + \
'# How: 1 article URI per line\n' + \
'# (from articles/)\n' + \
'# not begining with "/"\n' + \
'# Order in sidebar position\n' + \
@ -572,6 +582,7 @@ def create_sidebar(option):
elif tyto.n == 1: sdb_load = sdb_load_en
tyto.set_file(db.sidebar_load, 'new', sdb_load)
tyto.create_db_load(db.sidebar_load, db.sidebar_load_db)
print(log)
@ -652,6 +663,7 @@ def create_navbar(option):
elif tyto.n == 1: nvb_load = nav_load_en
tyto.set_file(db.navbar_load, 'new', nvb_load)
tyto.create_db_load(db.navbar_load, db.navbar_load_db)
print(log)
@ -669,7 +681,7 @@ def create_metas(option):
'<!-- Custom HTML metas for all pages\n' + \
'# You can add/edit HTML tags\n' + \
'# ! Only <meta > and <link > lines are used !\n' + \
'# After editing, use "tyto metas -n"\n' + \
'# After editing, use "tyto wip/publish metas"\n' + \
'# (You should not copy this file to template)' + \
'\n' + \
'# Already set metas with values:\n' + \
@ -715,7 +727,7 @@ def create_metas(option):
tyto.set_file(db.www_metas, 'new', metas_srvs)
print(' ├ Create empty file: %s'%db.www_metas)
# Create new file, or ask if exists
# Create new default file, or ask if exists
ask = ' ├ Reset metas configuration file ? '
log = ' ├ Create source file: %s'%db.metas_load
res = ''
@ -728,7 +740,81 @@ def create_metas(option):
if not res in ['y', 'Y']: return
tyto.set_file(db.metas_load, 'new', metas_tags)
tyto.create_db_load(db.metas_load, db.metas_load_db)
print(log)
#=============================#
# footer load file translated #
#-----------------------------#
def create_footer(option):
# Check if can process
domain_needed()
# Create an empty html file in wip/www server if not exists
if not os.path.exists(db.wip_footer):
tyto.set_file(db.wip_footer, 'new', '')
print(' ├ Create empty file: %s'%db.wip_footer)
if not os.path.exists(db.www_footer):
tyto.set_file(db.www_footer, 'new', '')
print(' ├ Create empty file: %s'%db.www_footer)
# Default footer contents
Tytosrc = '(<a href="%s" '%tyto.Tytogit + \
'title="%s" '%tyto.trans[4][tyto.n] + \
'id="footer_item_link">%s</a>)'%tyto.trans[3][tyto.n]
footer = \
'<!-- Default <footer> generated by %s\n'%tyto.Tyto + \
' file: /articles/_configs/tyto.footer.html\n' + \
' Type: "tyto wip/publish footer"\n' + \
' to use this default configuration on your website,\n' + \
' or change it to create your own on your website.\n' + \
' Type: "tyto new footer"\n' + \
' to reset it (you\'ll have to confirm)\n' + \
' Type: tyto edit footer to edit this configuration\n' + \
'-->\n' + \
'<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'%(db.domain_title) + \
' </a>\n' + \
' <p id="footer_site_about">%s</p>\n'%(db.domain_about) + \
' </div>\n' + \
'\n' + \
' <div id="footer_references">\n' + \
' <ul> id="footer_items"\n' + \
' <li id="footer_item">\n' + \
' <a href="%s"\n'%db.domain_licurl + \
' title="%s %s %s"\n'%(
tyto.trans[2][tyto.n],
db.domain_sep, db.domain_title) + \
' id="footer_item_link">%s</a>\n'%(
db.domain_license) + \
' </li>\n' + \
' <li id="footer_item">\n' + \
' <a href="%s"\n'%tyto.Tytoweb + \
' title="%s"\n'%tyto.trans[5][tyto.n] + \
' id="footer_item_link">%s</a> %s\n'%(tyto.Tyto, Tytosrc) + \
' </li>\n' + \
' </ul>\n' + \
' </div>\n' + \
'</footer>'
# Create new default file, or ask if exists
ask = ' ├ Reset footer configuration file ? '
log = ' ├ Create source file: %s'%db.footer_load
res = ''
if os.path.exists(db.footer_load):
try:
res = input(ask)
except KeyboardInterrupt:
print('')
logs.out("255", '', True)
if not res in ['y', 'Y']: return
tyto.set_file(db.footer_load, 'new', footer)
tyto.create_db_load(db.footer_load, db.footer_load_db)
print(log)

View File

@ -206,24 +206,6 @@ def create_html_infos_section(process):
)
#========================================================#
# Create DB file with hash from [type]_load file content #
#--------------------------------------------------------#
def create_db_load(file_load, file_db):
hash_load = tyto.get_filesum(file_load, True)
if not os.path.exists(file_db):
set_f = 'file_load_hash = "%s"'%hash_load
tyto.set_file(file_db, True, set_f)
return
global file_load_hash
file_load_hash = ''
exec(open(file_db, 'r').read(), globals())
if not file_load_hash == hash_load:
set_f = 'file_load_hash = "%s"'%hash_load
tyto.set_file(file_db, True, set_f)
#============================================#
# Create HTML sidebar from file tyto.sidebar #
#--------------------------------------------#
@ -512,97 +494,16 @@ def create_user_metas(option):
# Create generic footer from domain datas #
#-----------------------------------------#
def create_user_footer(option):
if not db.domain_exists: return
# Check if can process
domain.domain_needed()
create_load = False # file in _configs
create_html = False # file in template/
if option == 'wip': target = db.wip_footer
elif option == 'www': target = db.www_footer
# Get sidebar_load hash or create sidebar db file if not exists
#--------------------------------------------------------------
if os.path.exists(db.footer_load):
create_db_load(db.footer_load, db.footer_load_db)
# Manage option
#--------------
if not os.path.exists(db.footer_load):
create_load = True
elif option == 'Force':
create_load = True
create_html = True
elif option == 'Create':
create_html = True
elif option == 'Edit':
hash_load_old = tyto.get_filesum(db.footer_load, True)
tyto.edit_file(db.footer_load)
hash_load_new = tyto.get_filesum(db.footer_load, True)
if not hash_load_old == hash_load_new:
create_db_load(db.footer_load, db.footer_load_db)
create_html = True
# Default footer contents
Tytosrc = '(<a href="%s" '%tyto.Tytogit + \
'title="%s" '%tyto.trans[4][tyto.n] + \
'id="footer_item_link">%s</a>)'%tyto.trans[3][tyto.n]
footer = \
'<!-- Default <footer> generated by %s -->\n'%tyto.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'%(db.domain_title) + \
' </a>\n' + \
' <p id="footer_site_about">%s</p>\n'%(db.domain_about) + \
' </div>\n' + \
'\n' + \
' <div id="footer_references">\n' + \
' <ul> id="footer_items"\n' + \
' <li id="footer_item">\n' + \
' <a href="%s"\n'%db.domain_licurl + \
' title="%s %s %s"\n'%(
tyto.trans[2][tyto.n],
db.domain_sep, db.domain_title) + \
' id="footer_item_link">%s</a>\n'%(
db.domain_license) + \
' </li>\n' + \
' <li id="footer_item">\n' + \
' <a href="%s"\n'%tyto.Tytoweb + \
' title="%s"\n'%tyto.trans[5][tyto.n] + \
' id="footer_item_link">%s</a> %s\n'%(tyto.Tyto, Tytosrc) + \
' </li>\n' + \
' </ul>\n' + \
' </div>\n' + \
'</footer>'
# Create new default footer_load, or ask if exists
#-------------------------------------------------
if create_load:
ask_load = ' ├ Reset footer configuration file ? '
log_load = ' ├ Create file: %s'%db.footer_load
ask_load = ' ├ Replace HTML footer: %s ? '%target
log_load = ' ├ Create file: %s'%target
res = ''
if os.path.exists(db.footer_load):
try:
res = input(ask_load)
except KeyboardInterrupt:
print('')
logs.out("255", '', True)
if not res in ['y', 'Y']: return
create_html = True
tyto.set_file(db.footer_load, True, footer)
create_db_load(db.footer_load, db.footer_load_db)
print(log_load)
if create_html:
ask_load = ' ├ Replace HTML footer: %s ? '%db.wip_footer
log_load = ' ├ Create file: %s'%db.wip_footer
res = ''
if os.path.exists(db.wip_footer):
if os.path.exists(target):
try:
res = input(ask_load)
except KeyboardInterrupt:
@ -617,7 +518,7 @@ def create_user_footer(option):
if user_footer: user_footer = "%s\n %s"%(user_footer, line)
else: user_footer = ' %s'%line
tyto.set_file(db.wip_footer, True, user_footer)
tyto.set_file(target, True, user_footer)
print(log_load)

View File

@ -26,13 +26,19 @@ import logs, args, db, domain, html
# - domain: target becomes 3rd command argument #
#-----------------------------------------------#
def manage_new(target):
# Generic option, except for domain
option = 'new'
if target == "domain":
try: URL = sys.argv[3]
except: URL = ''
domain.manage_domain(URL)
try: option = sys.argv[3]
except: option = ''
elif target == 'sidebar':
domain.create_sidebar('new')
if target in args.pass_targets:
actions = {
'domain' : domain.manage_domain,
'sidebar' : domain.create_sidebar,
'navbar' : domain.create_navbar,
'metas' : domain.create_metas,
'footer' : domain.create_footer
}
elif target == 'navbar':
domain.create_navbar('new')
actions[target](option)

View File

@ -199,6 +199,24 @@ def set_file(path, new, text):
logs.out("4", path, True)
#========================================================#
# Create DB file with hash from [type]_load file content #
#--------------------------------------------------------#
def create_db_load(file_load, file_db):
hash_load = get_filesum(file_load, True)
if not os.path.exists(file_db):
line = 'file_load_hash = "%s"'%hash_load
set_file(file_db, True, line)
return
global file_load_hash
file_load_hash = ''
exec(open(file_db, 'r').read(), globals())
if not file_load_hash == hash_load:
line = 'file_load_hash = "%s"'%hash_load
set_file(file_db, True, line)
#==========================#
# Get CSS from line if set #
#--------------------------#