From 4e21403e3dd19ba7e3b7fdfda88b56bb9e4f63da Mon Sep 17 00:00:00 2001 From: Cyrille L Date: Wed, 11 Jan 2023 10:00:42 +0100 Subject: [PATCH] html: better navbar management. Use virtual nginx line from navbar.html --- src/var/lib/tyto/program/html.py | 112 +++++++++++++++++----------- src/var/lib/tyto/program/navbars.py | 5 +- src/var/lib/tyto/program/tyto.py | 3 + 3 files changed, 75 insertions(+), 45 deletions(-) diff --git a/src/var/lib/tyto/program/html.py b/src/var/lib/tyto/program/html.py index 2d8388e..1cbecac 100644 --- a/src/var/lib/tyto/program/html.py +++ b/src/var/lib/tyto/program/html.py @@ -21,12 +21,13 @@ import os import tyto # Load domain configuration DB -exec(open(tyto.domain_conf).read(),globals()) +exec(open(tyto.domain_conf).read()) Tyto = 'Tyto - Littérateur' tytogit = 'https://git.a-lec.org/echolib/tyto-litterateur' tytoweb = 'https://tyto.echolib.re' +navbar_file = '%snavbar.html'%srv_wip_tpl #==========================# # Load article DB # @@ -134,50 +135,21 @@ def create_main_page(target, article_bottom): '%salt="logo: %s">\n'%(15 * " ", domain_title) + \ '%sid="site_logo_image">\n'%(15 * " ") + \ '%s'%(8 * " ") - - #------------------------------------# - # Create HTML menu from root folders # - #------------------------------------# - menu_html = '' - - # Conditions to create navbar - #---------------------------- - # True in config - if domain_menubar: - # Create folder links (from tyto.navbar) in navbar - try: - nav_file = open(navbar_load, 'r').read() - nav_bar = True - except: - tyto.exiting("1", '(navbar) %s'%navbar_load, False) - nav_bar = False - - if nav_bar: - # Open HTML tags - menu_html = '%s\n'%(menu_html, 8 * ' ', 6 * ' ') + # Check for menu bar + # Delete file if deactivated in conf + if domain_menubar: + if os.path.exists(navbar_file): + tyto.exiting("25", 'menu from: %s'%navbar_file, False) + else: + tyto.exiting("24", '(menu file): %s'%navbar_file, False) + else: + if os.path.exists(navbar_file) and os.stat(navbar_file).st_size > 1: + tyto.set_file(navbar_file, 'new', '') + tyto.exiting("26", 'domain_menubar', False) + tyto.exiting('27', 'contents (menu file): %s'%navbar_file, False) + #-----------------------# # Create main HTML Page # #-----------------------# @@ -200,7 +172,7 @@ def create_main_page(target, article_bottom): ' \n' + \ '

%s

\n'%domain_about + \ ' \n' + \ - '%s'%menu_html + \ + '' + \ ' \n' + \ '\n' + \ '
\n' + \ @@ -209,3 +181,55 @@ def create_main_page(target, article_bottom): '\n' + \ ' \n' + \ '' + + +#====================================# +# Create HTML menu from root folders # +#------------------------------------# +def create_navbar(): + # Conditions to create navbar + if not domain_menubar: + tyto.set_file(navbar_file, 'new', '') + tyto.exiting("26", 'domain_menubar', False) + if os.path.exists(navbar_file) and os.stat(navbar_file).st_size > 1: + tyto.exiting('27', 'contents (menu file): %s'%navbar_file, False) + return + + # True in config + # Create folder links (from navbars/tyto.navbar) + try: nav_file = open(navbar_load, 'r').read() + except: tyto.exiting("1", '(navbar) %s'%navbar_load, True) + + # Open HTML tags + menu_html = '%s\n'%(menu_html, 8 * ' ', 6 * ' ') + tyto.set_file('%snavbar.html'%srv_wip_tpl, 'new', menu_html) diff --git a/src/var/lib/tyto/program/navbars.py b/src/var/lib/tyto/program/navbars.py index 02255f7..afc1ecf 100644 --- a/src/var/lib/tyto/program/navbars.py +++ b/src/var/lib/tyto/program/navbars.py @@ -18,7 +18,7 @@ #********************************************************************** import sys -import tyto +import tyto, html # Load domain configuration if exists if tyto.domain_exists: exec(open(tyto.domain_conf).read()) @@ -43,6 +43,9 @@ def manage_navbars(target, option): elif option == 'Edit': print(":D Edit %s configuration file:"%sys.argv[1], file) tyto.edit_file(file) + elif option == 'New': + html.create_navbar() + else: db_exists = tyto.get_db_post(target) # Article exists + has DB ? diff --git a/src/var/lib/tyto/program/tyto.py b/src/var/lib/tyto/program/tyto.py index 0e5b541..9dd88bb 100644 --- a/src/var/lib/tyto/program/tyto.py +++ b/src/var/lib/tyto/program/tyto.py @@ -507,6 +507,9 @@ def exiting(nbr, value, out): '23' : ':? %sCorrupted database%s: %s'%(CY, CS, value), '24' : ':? %sfile missing%s %s'%(CY, CS, value), '25' : ':D Add contents %s'%value, + '26' : ':? %sDeactivated%s "%s" in domain conf'%(CY, CS, value), + '27' : ':? %sDeleted%s %s'%(CY, CS, value), + '28' : ':? %sUnused directory%s: %s'%(CY, CS, value), '255' : ':| Maybe later...' }