diff --git a/src/usr/bin/tyto b/src/usr/bin/tyto index 4cf951e..819c3f8 100755 --- a/src/usr/bin/tyto +++ b/src/usr/bin/tyto @@ -26,7 +26,7 @@ import sys sys.path.insert(0, '/var/lib/tyto/program') -import check, domain, wip, navbars +import check, domain, wip, html #====================# # MAIN # @@ -45,8 +45,10 @@ actions = { 'check' : check.manage_check, 'wip' : wip.manage_wip, 'domain' : domain.manage_domain, - 'sidebar' : navbars.manage_navbars, - 'navbar' : navbars.manage_navbars + 'sidebar' : html.manage_configs, + 'navbar' : html.manage_configs, + 'metas' : html.manage_configs, + 'footer' : html.manage_configs } # Dict for Options diff --git a/src/var/lib/tyto/program/domain.py b/src/var/lib/tyto/program/domain.py index 7e10a06..30c80da 100644 --- a/src/var/lib/tyto/program/domain.py +++ b/src/var/lib/tyto/program/domain.py @@ -19,7 +19,7 @@ import os, locale -import tyto +import tyto, html #==========================# # Manage Argument 'domain' # @@ -107,16 +107,19 @@ def create_domain(target, option): db_dir = '%s/.local/tyto/%s/'%(tyto.home_dir, domain_short) - navbars_conf= '%sarticles/navbars/'%tyto.conf_dir + navbars_conf= '%sarticles/_configs/'%tyto.conf_dir conf_domain = 'domain_dir = "%s"\n'%tyto.conf_dir + \ 'domain_conf = "%s"\n'%tyto.domain_conf + \ 'domain_articles = "%sarticles/"\n'%tyto.conf_dir + \ 'domain_files = "%sarticles/files/"\n'%tyto.conf_dir + \ 'domain_images = "%sarticles/images/"\n'%tyto.conf_dir + \ 'domain_db = "%sarticles/"\n'%(db_dir) + \ + 'html_db = "%shtml/"\n'%(db_dir) + \ 'navbars_dir = "%s"\n'%navbars_conf + \ 'navbar_load = "%styto.navbar"\n'%navbars_conf + \ 'sidebar_load = "%styto.sidebar"\n'%navbars_conf + \ + 'metas_load = "%styto.metas.html"\n'%navbars_conf + \ + 'footer_load = "%styto.footer.html"\n'%navbars_conf + \ '\ndomain_short = "%s"\n'%domain_short + \ 'domain_url = "%s"\n'%domain_url + \ 'domain_wipurl = "%s"\n'%domain_wipurl @@ -416,7 +419,7 @@ def create_domain(target, option): srv_wip_tpl, srv_wip_images, srv_wip_files, srv_www_tpl, srv_www_images, srv_www_files, domain_files, domain_images, navbars_dir, - domain_db, + domain_db, html_db ) print(' │') @@ -428,9 +431,14 @@ def create_domain(target, option): # Create tyto.sidebar and metas.html print(' │') - create_sidebar(option, navbars_dir) - create_navbar(option, navbars_dir) - create_metas_file(srv_wip_tpl) + 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') print(' │') print(' ├──────────────────────────────────────┐') @@ -441,21 +449,13 @@ def create_domain(target, option): #========================================# # Create metas.html with default content # #----------------------------------------# -def create_metas_file(srv_wip_tpl): - metas_file = '%smetas.html'%srv_wip_tpl - if os.path.exists(metas_file): - ask = '' - ask = input(' ├ Initialize default metas.html ? ') - if not ask in ['y', 'Y']: - return - - metas_tags = '# Custom metas\n' + \ - '# You can add HTML meta tags or edit them\n' + \ - '# As Tyto makes static pages,\n' + \ - '# for any changes, you will have to commands:\n' + \ - '# "tyto wip again" and "tyto publish again"\n' + \ - '# to apply new changes to your live articles.\n' + \ +def create_metas_file(option): + metas_load = tyto.metas_load + metas_tags = '\n' + \ '\n' + \ '\n' + \ '' - - tyto.set_file(metas_file, True, metas_tags) - print(' ├ Create file: %s'%metas_file) - print(' │ ! Check this file, before starting !') + + + # Create new file, or ask if exists + ask = ' ├ Use default tyto.metas.html ? ' + log = ' ├ Create file: %s'%metas_load + + if os.path.exists(metas_load): + if option == '-i': return # Continue to create template/metas.html + res = input(ask) + if not res in ['y', 'Y']: return + + tyto.set_file(metas_load, 'new', metas_tags) + print(log) #==============================# # sidebar load file translated # #------------------------------# -def create_sidebar(opt, navbars_dir): - try: sidebar_load - except: sidebar_load = "%styto.sidebar"%navbars_dir - +def create_sidebar(option): + sidebar_load = tyto.sidebar_load sdb_load_fr = '# Pour : Tyto - Littérateur\n' + \ '# Type : fichier texte\n' + \ '# Description : Fichier appelé par "tyto sidebar"\n' + \ '# (Liste d\'articles)\n' + \ - '# Fichier : tyto.sidebar\n' + \ - '# Dossier : %s\n'%navbars_dir + \ + '# Fichier : %s\n'%sidebar_load + \ '# Comment : 1 URI de l\'article par ligne\n' + \ '# (depuis articles/)\n' + \ '# Ne commence pas par "/"\n' + \ @@ -512,8 +525,7 @@ def create_sidebar(opt, navbars_dir): '# Type: Text file\n' + \ '# Description: file called with "tyto sidebar"\n' + \ '# (articles\'s list)\n' + \ - '# File: tyto.sidebar\n' + \ - '# Directory: %s\n'%navbars_dir + \ + '# File: %s\n'%sidebar_load + \ '# Comment: 1 article URI per line\n' + \ '# (from articles/)\n' + \ '# not begining with "/"\n' + \ @@ -526,30 +538,31 @@ def create_sidebar(opt, navbars_dir): if tyto.n == 0: sdb_load = sdb_load_fr elif tyto.n == 1: sdb_load = sdb_load_en - - if not opt == 'Remove' and os.path.exists(sidebar_load): - ask = '' - ask = input(' ├ Initialize new sidebar ? ') - if not ask in ['y', 'Y']: - return + + ask = ' ├ Use default (empty) sidebar config ? ' + log = ' ├ Create file: %s'%sidebar_load + + # Create new file, or ask if exists + ask = ' ├ Use default (empty) sidebar config file ? ' + log = ' ├ Create file: %s'%sidebar_load + + if os.path.exists(sidebar_load): + res = input(ask) + if not res in ['y', 'Y']: return tyto.set_file(sidebar_load, 'new', sdb_load) - print(' ├ Create file: %s'%sidebar_load) + print(log) #=============================# # navbar load file translated # #-----------------------------# -def create_navbar(opt, navbars_dir): - try: navbar_load - except: navbar_load = "%styto.navbar"%navbars_dir - +def create_navbar(option): nav_load_fr = '# Pour : Tyto - Littérateur\n' + \ '# Type : fichier texte\n' + \ '# Description : Fichier utilisé par "tyto wip"\n' + \ '# (Liste des catégories)\n' + \ - '# Fichier : tyto.navbar\n' + \ - '# Dossier : %s\n'%navbars_dir + \ + '# Fichier : %s\n'%navbar_load + \ '# Comment : 1 nom de dossier par ligne *1\n' + \ '# (depuis articles/)\n' + \ '# Ne commence pas par "/"\n' + \ @@ -559,19 +572,18 @@ def create_navbar(opt, navbars_dir): '# dans le dossier mentionné\n' + \ '# - utiliser check et wip dessus\n' + \ '# Option *1: Pour définir un titre de lien :\n' + \ - '# - ajouter "= titre de lien"\n' + \ + '# - ajouter "# titre de lien"\n' + \ '\n# %s\n'%(15 * "-") +\ '# Exemples :\n' + \ '# documentation\n' + \ - '# a-propos = Informations concernant ce site\n' + \ + '# a-propos # Informations concernant ce site\n' + \ '# %s\n\n'%(15 * "-") nav_load_en = '# For: Tyto - Littérateur\n' + \ '# Type: Text file\n' + \ '# Description: file used with "tyto wip"\n' + \ '# (categories\'s list)\n' + \ - '# File: tyto.navbar\n' + \ - '# Directory: %s\n'%navbars_dir + \ + '# File : %s\n'%navbar_load + \ '# Comment: 1 folder name per line *1\n' + \ '# (from articles/)\n' + \ '# not begining with "/"\n' + \ @@ -581,21 +593,23 @@ def create_navbar(opt, navbars_dir): '# in set folder\n' + \ '# - check and wip it\n' + \ '# Option *1: To define a title link:' + \ - '# - add "= title link"\n' + \ + '# - add "# title link"\n' + \ '\n# %s\n'%(15 * "-") +\ '# Examples :\n' + \ '# documentation\n' + \ - '# about = infos about this website\n' + \ + '# about # infos about this website\n' + \ '# %s\n\n'%(15 * "-") if tyto.n == 0: nav_load = nav_load_fr elif tyto.n == 1: nav_load = nav_load_en - if not opt == 'Remove' and os.path.exists(navbar_load): - ask = '' - ask = input(' ├ Initialize new navbar ? ') - if not ask in ['y', 'Y']: - return + # Create new file, or ask if exists + ask = ' ├ Use default (empty) navbar config file ? ' + log = ' ├ Create file: %s'%navbar_load + + if os.path.exists(navbar_load): + res = input(ask) + if not res in ['y', 'Y']: return tyto.set_file(navbar_load, 'new', nav_load) - print(' ├ Create file: %s'%navbar_load) + print(log) diff --git a/src/var/lib/tyto/program/html.py b/src/var/lib/tyto/program/html.py index 1cbecac..f1a0414 100644 --- a/src/var/lib/tyto/program/html.py +++ b/src/var/lib/tyto/program/html.py @@ -16,19 +16,52 @@ #---------------------------------------------------------------------- #********************************************************************** -import os +import os, sys -import tyto +import tyto, domain, html # Load domain configuration DB exec(open(tyto.domain_conf).read()) Tyto = 'Tyto - Littérateur' -tytogit = 'https://git.a-lec.org/echolib/tyto-litterateur' -tytoweb = 'https://tyto.echolib.re' +Tytogit = 'https://git.a-lec.org/echolib/tyto-litterateur' +Tytogti = 'Dépôt officiel du code source de Tyto - Littérateur' +Tytoweb = 'https://tyto.echolib.re' +Tytowti = 'Site web officiel du logiciel Tyto - Littérateur' +Tytosrc = '(Code source)' navbar_file = '%snavbar.html'%srv_wip_tpl +# +# Manage fies for HTML +# (sidebar, metas, footer, navbar) +# +def manage_configs(target, option): + + args1 = ('metas', 'sidebar', 'footer', 'navbar') + args2 = ('-n', '-e', '-R') + opts = ('New', 'Edit', 'Remove') + + if target in args1: sys.argv[1] = target + elif target and not option: option = target + if not sys.argv[1] in args1: tyto.exiting('11', '%s'%str(args1), True) + if not option in opts and not option == '-i' and not option in args2: + 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 + } + + actions[sys.argv[1]](option) + + #==========================# # Load article DB # # Start HTML page sections # @@ -49,7 +82,6 @@ def create_metas_page(): # Settings for metas #------------------- metas_page = '' - tab = 4 scale = 'width=device-width, initial-scale=1.0' all_tags = domain_tags + ',' + tags post_url = domain_url + http_uri @@ -61,62 +93,46 @@ def create_metas_page(): sub_uri, rss_file, domain_title, domain_sep, domain_short ) icon_file = 'favicon.png' - icon_ref = 'type="image/png" href="%s%s"'%(sub_uri, icon_file) + icon_ref = 'type="image/png" href="%stemplate/%s"'%(sub_uri, icon_file) en_date = tyto.set_en_date(date[0]) relme = '' # External URL in metas (if exists in config domain) if domain_relme: - relme = '\n'%( + relme = '\n '%( domain_relme ) - - # Check for user metas from wip template/metas.html - #-------------------------------------------------- - metas_file = '%smetas.html'%srv_wip_tpl - user_metas = '' - metas_used = ('\n'%scale + \ - '\n'%domain_url + \ - '\n'%domain_lang + \ - '\n'%domain_mail + \ - '\n'%domain_license + \ - '\n'%Tyto + \ - '\n'%title + \ - '\n'%author + \ - '\n'%about + \ - '\n'%all_tags + \ - '\n'%en_date + \ - '\n'%post_url + \ - '\n'%(rss_ref) + \ - ''%icon_ref + \ + global metas + metas = ' \n' + \ + ' \n'%scale + \ + ' \n'%domain_url + \ + ' \n'%domain_lang + \ + ' \n'%domain_mail + \ + ' \n'%domain_license + \ + ' \n'%Tyto + \ + ' \n'%title + \ + ' \n'%author + \ + ' \n'%about + \ + ' \n'%all_tags + \ + ' \n'%en_date + \ + ' \n'%post_url + \ + ' \n'%(rss_ref) + \ + ' '%icon_ref + \ + ' \n' + \ + ' \n'%domain_title + \ + ' \n'%title + \ + ' \n' + \ + ' \n'%post_url + \ + ' \n' + \ + ' \n' + \ '%s'%relme + \ - user_metas + \ - '
%s
\n'%domain_about + \ ' \n' + \ - '' + \ + '\n' + \ '