Some fixes + help update. No more www server file created with new domain

This commit is contained in:
Cyrille L 2023-03-03 14:02:25 +01:00
parent ba161305eb
commit d866e0f34f
5 changed files with 86 additions and 94 deletions

View File

@ -39,7 +39,7 @@ post_exists = False
home_dir = os.path.expanduser('~') home_dir = os.path.expanduser('~')
try: in_dir = os.getcwd() try: in_dir = os.getcwd()
except: logs.out("13", '', False) except: logs.out("13", '', True)
domain_conf = in_dir domain_conf = in_dir

View File

@ -517,7 +517,7 @@ def create_domain(target):
if not ask.isdigit(): logs.out("3", ask, True) if not ask.isdigit(): logs.out("3", ask, True)
elif int(ask) in range(1,17): sidebar_items = int(ask) elif int(ask) in range(1,17): sidebar_items = int(ask)
set_f = 'sidebar_items = %d'%sidebar_items set_f = 'sidebar_items = %d'%int(sidebar_items)
tyto.set_file(db.domain_conf, False, set_f) tyto.set_file(db.domain_conf, False, set_f)
# Create domain_footer_about (user custom description in footer) # Create domain_footer_about (user custom description in footer)
@ -576,10 +576,10 @@ def create_domain(target):
print('') print('')
for folder in folders: for folder in folders:
if not os.path.exists(folder):
print(' ├ Create directory: %s'%folder)
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)
else:
print(' ├ Create directory: %s'%folder)
# Create in _configs files # Create in _configs files
# Parameter could be used later # Parameter could be used later
@ -606,9 +606,6 @@ def create_sidebar(option):
if not os.path.exists(db.wip_sidebar): if not os.path.exists(db.wip_sidebar):
tyto.set_file(db.wip_sidebar, 'new', '') tyto.set_file(db.wip_sidebar, 'new', '')
print(' ├ Create empty file: %s'%db.wip_sidebar) print(' ├ Create empty file: %s'%db.wip_sidebar)
if not os.path.exists(db.www_sidebar):
tyto.set_file(db.www_sidebar, 'new', '')
print(' ├ Create empty file: %s'%db.www_sidebar)
# Create new file, or ask if exists with option = 'reset' # Create new file, or ask if exists with option = 'reset'
ask = ' ├ Reset sidebar configuration file ? ' ask = ' ├ Reset sidebar configuration file ? '
@ -626,7 +623,7 @@ def create_sidebar(option):
sdb_load_fr = \ sdb_load_fr = \
'# Pour : Tyto - Littérateur\n' + \ '# Pour : Tyto - Littérateur\n' + \
'# Type : fichier texte\n' + \ '# Type : fichier texte\n' + \
'# Description : Fichier appelé par "tyto sidebar"\n' + \ '# Description : Fichier utilisé par "tyto wip/publish"\n' + \
'# (Liste d\'articles)\n' + \ '# (Liste d\'articles)\n' + \
'# Fichier : %s\n'%db.sidebar_load + \ '# Fichier : %s\n'%db.sidebar_load + \
"# Commandes: tyto new sidebar (réinitialiser)\n" + \ "# Commandes: tyto new sidebar (réinitialiser)\n" + \
@ -646,7 +643,7 @@ def create_sidebar(option):
sdb_load_en = \ sdb_load_en = \
'# For: Tyto - Littérateur\n' + \ '# For: Tyto - Littérateur\n' + \
'# Type: Text file\n' + \ '# Type: Text file\n' + \
'# Description: file called with "tyto sidebar"\n' + \ '# Description: file used with "tyto wip/publish"\n' + \
'# (articles\'s list)\n' + \ '# (articles\'s list)\n' + \
'# File: %s\n'%db.sidebar_load + \ '# File: %s\n'%db.sidebar_load + \
'# Commands: tyto new sidebar (reset)\n' + \ '# Commands: tyto new sidebar (reset)\n' + \
@ -682,9 +679,6 @@ def create_navbar(option):
if not os.path.exists(db.wip_navbar): if not os.path.exists(db.wip_navbar):
tyto.set_file(db.wip_navbar, 'new', '') tyto.set_file(db.wip_navbar, 'new', '')
print(' ├ Create empty file: %s'%db.wip_navbar) print(' ├ Create empty file: %s'%db.wip_navbar)
if not os.path.exists(db.www_navbar):
tyto.set_file(db.www_navbar, 'new', '')
print(' ├ Create empty file: %s'%db.www_navbar)
# Create new file, or ask if exists # Create new file, or ask if exists
ask = ' ├ Reset navbar configuration file ? ' ask = ' ├ Reset navbar configuration file ? '
@ -702,18 +696,18 @@ def create_navbar(option):
# French navbar_load content # French navbar_load content
nav_load_fr = '# Pour : Tyto - Littérateur\n' + \ nav_load_fr = '# Pour : Tyto - Littérateur\n' + \
'# Type : fichier texte\n' + \ '# Type : fichier texte\n' + \
'# Description : Fichier utilisé par "tyto wip"\n' + \ '# Description : Fichier utilisé par "tyto wip/publish"\n' + \
'# (Liste des catégories)\n' + \ '# (Liste des catégories)\n' + \
'# Fichier : %s\n'%db.navbar_load + \ '# Fichier : %s\n'%db.navbar_load + \
'# Comment : 1 nom de dossier par ligne *1\n' + \ '# Comment : 1 nom de dossier par ligne *1\n' + \
'# (depuis articles/)\n' + \ '# (depuis articles/)\n' + \
'# Ne commence pas par "/"\n' + \ '# Ne commence pas par "/"\n' + \
'# L\'ordre définit la position\n' + \ '# L\'ordre définit la position\n' + \
'# Note: Pour éviter l\'erreur 404 :\n' + \ '# Note : Pour éviter l\'erreur 404 :\n' + \
'# - ajouter un article index.{ext}\n' + \ '# - ajouter un article index.{ext}\n' + \
'# dans le dossier mentionné\n' + \ '# dans le dossier mentionné\n' + \
'# - utiliser check et wip dessus\n' + \ '# - utiliser check et wip dessus\n' + \
'# Option *1: Pour définir un titre de lien :\n' + \ '# *1 Option : Pour définir un titre de lien :\n' + \
'# - ajouter "# titre de lien"\n' + \ '# - ajouter "# titre de lien"\n' + \
'\n# %s\n'%(15 * "-") +\ '\n# %s\n'%(15 * "-") +\
'# Exemples :\n' + \ '# Exemples :\n' + \
@ -724,7 +718,7 @@ def create_navbar(option):
# English navbar_load content # English navbar_load content
nav_load_en = '# For: Tyto - Littérateur\n' + \ nav_load_en = '# For: Tyto - Littérateur\n' + \
'# Type: Text file\n' + \ '# Type: Text file\n' + \
'# Description: file used with "tyto wip"\n' + \ '# Description: file used with "tyto wip/publish"\n' + \
'# (categories\'s list)\n' + \ '# (categories\'s list)\n' + \
'# File : %s\n'%db.navbar_load + \ '# File : %s\n'%db.navbar_load + \
'# Comment: 1 folder name per line *1\n' + \ '# Comment: 1 folder name per line *1\n' + \
@ -735,7 +729,7 @@ def create_navbar(option):
'# - add index.{ext} file article\n' + \ '# - add index.{ext} file article\n' + \
'# in set folder\n' + \ '# in set folder\n' + \
'# - check and wip it\n' + \ '# - check and wip it\n' + \
'# Option *1: To define a title link:' + \ '# *1 Option : To define a title link:' + \
'# - add "# title link"\n' + \ '# - add "# title link"\n' + \
'\n# %s\n'%(15 * "-") +\ '\n# %s\n'%(15 * "-") +\
'# Examples :\n' + \ '# Examples :\n' + \
@ -763,54 +757,52 @@ def create_metas(option):
# Set metas_load default content # Set metas_load default content
#------------------------------- #-------------------------------
metas_tags = \ metas_tags = \
'<!-- Custom HTML metas for all pages\n' + \ '# Custom HTML metas for all pages\n' + \
'# You can add/edit HTML tags\n' + \ '# You can add/edit HTML tags\n' + \
'# ! Only <meta > and <link > lines are used !\n' + \ '# ! Only <meta > and <link > lines are used !\n' + \
'# After editing, use "tyto wip/publish metas"\n' + \ '# After editing, use "tyto wip/publish metas"\n' + \
'# (You should not copy this file to template)' + \ '# (You should NOT copy this file to template)\n' + \
'\n' + \ '\n' + \
'# Already set metas with values:\n' + \ '# Already set metas with values:\n' + \
'# <meta charset="UTF-8">\n' + \ '# <meta name="viewport" ...\n' + \
'# <meta name="viewport" ...>\n' + \ '# <meta name=”url” ...\n' + \
'# <meta name=”url” ...>\n' + \ '# <meta name="language" ...\n' + \
'# <meta name="language" ...>\n' + \ '# <meta name="reply-to" ...\n' + \
'# <meta name="reply-to" ...>\n' + \ '# <meta name="copyright" ...\n' + \
'# <meta name="copyright" ...>\n' + \ '# <meta name="generator" ...\n' + \
'# <meta name="generator" ...>\n' + \ '# <meta name="title" ...\n' + \
'# <meta name="title" ...>\n' + \ '# <meta name="author" ...\n' + \
'# <meta name="author" ...>\n' + \ '# <meta name="description" ...\n' + \
'# <meta name="description" ...>\n' + \ '# <meta name="keywords" ...\n' + \
'# <meta name="keywords" ...>\n' + \ '# <meta name="search_date" ...\n' + \
'# <meta name="search_date" ...>\n' + \ '# <link rel="canonical" ...\n' + \
'# <link rel="canonical" ..." />\n' + \ '# <link rel="alternate" ... # RSS\n' + \
'# <link rel="alternate" ..." /> # RSS\n' + \ '# <link rel="stylesheet" ...\n' + \
'# <link rel="stylesheet" ... />\n' + \ '# <link rel="shortcut icon" ...\n' + \
'# <link rel="shortcut icon" ... />\n' + \ '# <link rel="me" ... # if profile url in config\n' + \
'# <link rel="me" ... > # if profile url in config\n' + \ '\n' + \
'# Open Graph data\n' + \ '# Open Graph data\n' + \
'# <meta property="og:site_name" ... />\n' + \ '# <meta property="og:site_name" ...\n' + \
'# <meta property="og:title" ... />\n' + \ '# <meta property="og:title" ...\n' + \
'# <meta property="og:type" ... />\n' + \ '# <meta property="og:type" ...\n' + \
'# <meta property="og:url" ... />\n' + \ '# <meta property="og:url" ...\n' + \
'# <meta property="og:description" ... />\n' + \ '# <meta property="og:description" ...\n' + \
'# <meta property="og:image" ... />\n' + \ '# <meta property="og:image" ...\n\n' + \
'-->\n' + \ '<meta charset="UTF-8" />\n' + \
'<meta name="robots" content="all">\n' + \ '<meta name="robots" content="all" />\n' + \
'<meta name="medium" content="website">\n' + \ '<meta name="medium" content="website" />\n' + \
'<meta name="revisit-after" content="3 days">' '<meta name="revisit-after" content="3 days" />'
metas_srvs = \ metas_srvs = \
' <meta name="robots" content="all">\n' + \ ' <meta charset="UTF-8" />\n' + \
' <meta name="medium" content="website">\n' + \ ' <meta name="robots" content="all" />\n' + \
' <meta name="revisit-after" content="3 days">' ' <meta name="medium" content="website" />\n' + \
' <meta name="revisit-after" content="3 days" />'
# Create an empty html file in wip/www server if not exists # Create an empty html file in wip/www server if not exists
if not os.path.exists(db.wip_metas): if not os.path.exists(db.wip_metas):
tyto.set_file(db.wip_metas, 'new', metas_srvs) tyto.set_file(db.wip_metas, 'new', metas_srvs)
print(' ├ Create empty file: %s'%db.wip_metas) print(' ├ Create empty file: %s'%db.wip_metas)
if not os.path.exists(db.www_metas):
tyto.set_file(db.www_metas, 'new', metas_srvs)
print(' ├ Create empty file: %s'%db.www_metas)
# Create new default file, or ask if exists # Create new default file, or ask if exists
ask = ' ├ Reset metas configuration file ? ' ask = ' ├ Reset metas configuration file ? '
@ -840,9 +832,6 @@ def create_footer(option):
if not os.path.exists(db.wip_footer): if not os.path.exists(db.wip_footer):
tyto.set_file(db.wip_footer, 'new', '') tyto.set_file(db.wip_footer, 'new', '')
print(' ├ Create empty file: %s'%db.wip_footer) 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)
# Create new default file, or ask if exists # Create new default file, or ask if exists
ask = ' ├ Reset footer configuration file ? ' ask = ' ├ Reset footer configuration file ? '
@ -923,15 +912,16 @@ def create_footer(option):
# Final HTML footer code # Final HTML footer code
footer = \ footer = \
'<!-- Default <footer> generated by %s\n'%tyto.Tyto + \ '# Default <footer> generated by %s\n'%tyto.Tyto + \
' file: /articles/_configs/tyto.footer.html\n' + \ '# file: /articles/_configs/tyto.footer.html\n' + \
' Type: "tyto wip/publish footer"\n' + \ '# Type: "tyto wip/publish footer"\n' + \
' to use this default configuration on your website,\n' + \ '# to use this default configuration on your website,\n' + \
' or change it to create your own on your website.\n' + \ '# or change it to create your own footer,\n' + \
' Type: "tyto new footer"\n' + \ '# Please, keep Tyto\'s credits ;)\n' + \
' to reset it (you\'ll have to confirm)\n' + \ '# Type: "tyto new footer"\n' + \
' Type: tyto edit footer to edit this configuration\n' + \ '# to reset it (you\'ll have to confirm)\n' + \
'-->\n' + \ '# Type: tyto edit footer to edit this configuration\n' + \
'# (You should NOT copy this file to template)\n\n' + \
'<footer id="footer_page">\n' + \ '<footer id="footer_page">\n' + \
' <div id="footer_infos">\n' + \ ' <div id="footer_infos">\n' + \
' <h1 id="footer_site_title">%s %s\n'%( ' <h1 id="footer_site_title">%s %s\n'%(

View File

@ -66,7 +66,7 @@ def create_metas_page():
#----------------------- #-----------------------
global metas global metas
metas = \ metas = \
' <meta charset="UTF-8" />\n' + \ '<!--# include virtual="/template/metas.html"-->\n'
' <meta name="viewport" content="%s" />\n'%scale + \ ' <meta name="viewport" content="%s" />\n'%scale + \
' <meta name=”url” content=”%s” />\n'%db.domain_www_url + \ ' <meta name=”url” content=”%s” />\n'%db.domain_www_url + \
' <meta name="language" content="%s" />\n'%db.domain_lang + \ ' <meta name="language" content="%s" />\n'%db.domain_lang + \
@ -90,7 +90,6 @@ def create_metas_page():
' <meta property="og:description" content="%s" />\n'%db.about + \ ' <meta property="og:description" content="%s" />\n'%db.about + \
' <meta property="og:image" content="%s" />\n'%db.snpic + \ ' <meta property="og:image" content="%s" />\n'%db.snpic + \
'%s'%relme + \ '%s'%relme + \
'<!--# include virtual="/template/metas.html"-->\n' + \
' <title>%s</title>'%db.title ' <title>%s</title>'%db.title
@ -345,10 +344,7 @@ def create_sidebar(option):
#------------------------------------# #------------------------------------#
def create_navbar(option): def create_navbar(option):
# Check if can process # Check if can process
if not db.domain_exists \ domain.domain_needed()
or db.incomplete_domain \
or not db.domain_active:
return
try: try:
db.navbar_load db.navbar_load
@ -370,7 +366,8 @@ def create_navbar(option):
nolines = ('#', '/') nolines = ('#', '/')
navbar_lines = open(db.navbar_load, 'r').read() navbar_lines = open(db.navbar_load, 'r').read()
for line in navbar_lines.rsplit('\n'): for line in navbar_lines.rsplit('\n'):
if not line or line.startswith(nolines): continue if not line or line.startswith(nolines):
continue
navbar_has = True navbar_has = True
# Get HTML title if defined (commented after) # Get HTML title if defined (commented after)
@ -392,6 +389,7 @@ def create_navbar(option):
index_wip = False index_wip = False
index_www = False index_www = False
for f in os.listdir(dir_uri): for f in os.listdir(dir_uri):
# An index file must be in the directory
if f.startswith("index."): if f.startswith("index."):
index_src = True index_src = True
if option == 'wip': if option == 'wip':
@ -408,9 +406,11 @@ def create_navbar(option):
index_www = True index_www = True
else: else:
break break
if not index_src: if not index_src:
logs.out("26", 'in "%s": %s'%(direc, dir_uri), False) logs.out("26", 'in "%s": %s'%(direc, dir_uri), False)
continue continue
if not index_wip and option == 'wip': continue if not index_wip and option == 'wip': continue
if not index_www and option == 'www': continue if not index_www and option == 'www': continue
@ -514,7 +514,7 @@ def create_user_footer(option):
user_footer = '' user_footer = ''
user_file = open(db.footer_load, 'r').read() user_file = open(db.footer_load, 'r').read()
for line in user_file.rsplit('\n'): for line in user_file.rsplit('\n'):
if not line: continue if not line or line.startswith('#'): continue
if user_footer: user_footer = "%s\n %s"%(user_footer, line) if user_footer: user_footer = "%s\n %s"%(user_footer, line)
else: user_footer = ' %s'%line else: user_footer = ' %s'%line

View File

@ -35,27 +35,28 @@ def tyto(target):
db_domains = '%s/.local/tyto'%os.path.expanduser('~') db_domains = '%s/.local/tyto'%os.path.expanduser('~')
user = os.environ.get('USER') user = os.environ.get('USER')
hashdomain = False hashdomain = False
print('# Registred domains for', user)
for folder in os.listdir(db_domains): for folder in os.listdir(db_domains):
if os.path.isdir('%s/%s'%(db_domains, folder)): if os.path.isdir('%s/%s'%(db_domains, folder)):
if hashdomain: if hashdomain:
hasdomain = False hasdomain = False
hashdomain = True hashdomain = True
print('# Registred domains for', user) print(' -', folder)
print('-', folder)
except: except:
noinfo = True noinfo = True
print(':< No .../.local/tyto') print(':< No .../.local/tyto')
# Show Usage # Show Usage
print( print(
'\nUsage: tyto [action] [target] \n' '\n# New domain:\n'
' After created domain (tyto new domain [URL]),\n' ' - Create your domain folder, and go in\n'
' create article\'s file in articles/ directory.\n' ' - Create domain with "tyto new domain [URL]"\n'
' Use this actions on article\'s file: Check > wip > publish\n' ' - Create article\'s file in articles/ directory\n'
' Config\'s files are in _configs/ directory,\n' ' - Use these actions on article\'s file: Check > wip > publish\n'
' and used to create HTML file in your template.\n\n' ' ! Config\'s files are in _configs/ directory\n'
'- [action] according to [target]:\n' ' and used to create HTML file in your template\n\n'
'# Usage: tyto [action] [target] \n'
' - [action] according to [target]:\n'
' edit : Edit article\'s file\n' ' edit : Edit article\'s file\n'
' edit-db : Edit article\'s database (TAKE CARE !)\n' ' edit-db : Edit article\'s database (TAKE CARE !)\n'
' edit-wip: Edit html file in wip server\n' ' edit-wip: Edit html file in wip server\n'
@ -68,21 +69,21 @@ def tyto(target):
' check : Check if article is valid\n' ' check : Check if article is valid\n'
' wip : Create page in wip server\n' ' wip : Create page in wip server\n'
' publish : Create page in www server\n\n' ' publish : Create page in www server\n\n'
'- [target] according to [action]\n' ' - [target] according to [action]\n'
' all : Convert again all already converted articles' ' all : Convert again all already converted articles\n'
' domain : Create/Show config file\n' ' domain : Create/Show config file\n'
' [file] : URI of an article\'s file (autocompletion is your friend)\n' ' [file] : URI of an article\'s file (autocompletion is your friend)\n'
' footer : Create/Show footer HTML config\'s file\n' ' footer : Create/Show footer HTML config\'s file\n'
' metas : Create/Show metas HTML config\'s file\n' ' metas : Create/Show metas HTML config\'s file\n'
' navbar : Create/Show navbar config\'s file\n' ' navbar : Create/Show navbar config\'s file\n'
' sidebar : Create/Show sidebar config\'s file\n\n' ' sidebar : Create/Show sidebar config\'s file\n\n'
'Examples:\n' '# Examples:\n'
'- Check article\'s syntax: tyto check mysubdir/index.tyto\n' ' - Check article\'s syntax: tyto check mysubdir/index.tyto\n'
'- Create default _configs/tyto.sidebar: tyto new sidebar\n' ' - Create default _configs/tyto.sidebar: tyto new sidebar\n'
'- Edit _configs/tyto.navbar: tyto edit navbar\n' ' - Edit _configs/tyto.navbar: tyto edit navbar\n'
'- Edit index.html in www server: tyto edit-www index.tyto\n' ' - Edit index.html in www server: tyto edit-www index.tyto\n'
'- Create sidebar.html in wip server: tyto wip sidebar\n' ' - Create sidebar.html in wip server: tyto wip sidebar\n'
'- Show sidebar.html in wip server: tyto show-wip sidebar\n' ' - Show sidebar.html in wip server: tyto show-wip sidebar\n'
'- Create navbar.html in www server: tyto publish navbar\n' ' - Create navbar.html in www server: tyto publish navbar\n'
'- Show navbar.html in www server: tyto show-www navbar\n' ' - Show navbar.html in www server: tyto show-www navbar\n'
) )

View File

@ -23,7 +23,8 @@ from hashlib import blake2b
import db, logs import db, logs
domain_active = False domain_active = False
home_dir = os.path.expanduser('~') home_dir = os.path.expanduser('~')
in_dir = os.getcwd() try: in_dir = os.getcwd()
except: logs.out("13", '', True)
domain_conf = in_dir domain_conf = in_dir
# Set translations: french, english # Set translations: french, english