[1.9.33] - Working on modules (header Ok, testing navbar)
This commit is contained in:
parent
8a66677925
commit
461c15c46e
|
@ -10,6 +10,12 @@ Tyto - Littérateur
|
||||||
|
|
||||||
# CURRENTLY IN DEV (in devel branch) !
|
# CURRENTLY IN DEV (in devel branch) !
|
||||||
|
|
||||||
|
## [1.9.33]
|
||||||
|
- Working on creating modules (header, navbar, sidebar, header)
|
||||||
|
- - Added working header module
|
||||||
|
- - Finishing navbar module...
|
||||||
|
- - Todo Next: sidebar and footer modules
|
||||||
|
|
||||||
## [1.9.32]
|
## [1.9.32]
|
||||||
- Working on creating modules (header, navbar, sidebar, header)
|
- Working on creating modules (header, navbar, sidebar, header)
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,7 @@ tyto
|
||||||
## Working on
|
## Working on
|
||||||
- 'wip' action processes
|
- 'wip' action processes
|
||||||
- Create HTML full page from article
|
- Create HTML full page from article
|
||||||
|
- Create/Manage modules (header, navbar, sidebar, footer)
|
||||||
|
|
||||||
## ToDo
|
## ToDo
|
||||||
- thinking about creating an auto top article menu from titles
|
- thinking about creating an auto top article menu from titles
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
Package: tyto
|
Package: tyto
|
||||||
Version: 1.9.32
|
Version: 1.9.33
|
||||||
Section: custom
|
Section: custom
|
||||||
Priority: optional
|
Priority: optional
|
||||||
Architecture: all
|
Architecture: all
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
# Version: 1.9.32
|
# Version: 1.9.33
|
||||||
# Updated: 2023-10-18 1697613100
|
# Updated: 2023-10-18 1697613100
|
||||||
# Tyto - Littérateur
|
# Tyto - Littérateur
|
||||||
|
|
||||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -154,6 +154,48 @@ def cf_load():
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
#======================================#
|
||||||
|
# Load another post configuration file #
|
||||||
|
#--------------------------------------#
|
||||||
|
def tmp_load(wrk_post, db_id):
|
||||||
|
global error
|
||||||
|
|
||||||
|
db_tmp_uri = os.path.join(domain.wrk_db, db_id)
|
||||||
|
post_tmp_uri = os.path.join(domain.wrk_articles, wrk_post)
|
||||||
|
|
||||||
|
if not os.path.exists(db_tmp_uri):
|
||||||
|
error = \
|
||||||
|
debug.out(5, wrk_post, db_tmp_uri, True, 2, False)
|
||||||
|
return False
|
||||||
|
|
||||||
|
global tmp_cf
|
||||||
|
tmp_cf = ""
|
||||||
|
tmp_cf = configparser.ConfigParser()
|
||||||
|
tmp_cf.read(tmp_uri)
|
||||||
|
|
||||||
|
if tmp_cf.get("CHECK", "errors"):
|
||||||
|
error = \
|
||||||
|
debug.out(10, "True", db_tmp_uri, True, 2, False)
|
||||||
|
return False
|
||||||
|
|
||||||
|
global tmp_title, tmp_about
|
||||||
|
try:
|
||||||
|
tmp_title = tmp_cf.get("HEADERS", "title")
|
||||||
|
except:
|
||||||
|
error = \
|
||||||
|
debug.out(51, "title:", post_tmp_uri, True, 2, False)
|
||||||
|
return False
|
||||||
|
|
||||||
|
try:
|
||||||
|
tmp_about = tmp_cf.get("HEADERS", "about")
|
||||||
|
except:
|
||||||
|
error = \
|
||||||
|
debug.out(51, "about:", post_tmp_uri, True, 2, False)
|
||||||
|
return False
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
#================================#
|
#================================#
|
||||||
# Return value from section, key #
|
# Return value from section, key #
|
||||||
#--------------------------------#
|
#--------------------------------#
|
||||||
|
|
|
@ -115,7 +115,7 @@ def create_dirs(path):
|
||||||
debug.out(203, "True", path, False, 0, False)
|
debug.out(203, "True", path, False, 0, False)
|
||||||
except:
|
except:
|
||||||
# Exit if not created
|
# Exit if not created
|
||||||
debug.out(5, "False", path, True, 2, True)
|
debug.out(6, "False", path, True, 2, True)
|
||||||
|
|
||||||
|
|
||||||
#============================#
|
#============================#
|
||||||
|
|
|
@ -100,6 +100,11 @@ def convert(target):
|
||||||
if not post.is_article(target):
|
if not post.is_article(target):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
# Check/create wip server directories
|
||||||
|
# Exit on error !
|
||||||
|
for key, directory in domain.cf.items("WIP_DIRS"):
|
||||||
|
tools.create_dirs(directory)
|
||||||
|
|
||||||
# Check/Create modules files
|
# Check/Create modules files
|
||||||
# navbar, sidebar, header, footer
|
# navbar, sidebar, header, footer
|
||||||
if not get_modules("wip"):
|
if not get_modules("wip"):
|
||||||
|
@ -595,14 +600,16 @@ def convert_list(markdown_str, mark_b, mark_c):
|
||||||
# - footer #
|
# - footer #
|
||||||
#--------------------------------------------#
|
#--------------------------------------------#
|
||||||
def get_modules(srv):
|
def get_modules(srv):
|
||||||
|
global modules
|
||||||
|
|
||||||
# Modules settings
|
# Modules settings
|
||||||
|
"""
|
||||||
raws_uris = {
|
raws_uris = {
|
||||||
"header" : domain.wrk_header,
|
"header" : domain.wrk_header,
|
||||||
"navbar" : domain.wrk_navbar,
|
"navbar" : domain.wrk_navbar,
|
||||||
"sidebar" : domain.wrk_sidebar,
|
"sidebar" : domain.wrk_sidebar,
|
||||||
"footer" : domain.wrk_footer
|
"footer" : domain.wrk_footer
|
||||||
}
|
}
|
||||||
|
|
||||||
raws_sets = \
|
raws_sets = \
|
||||||
{
|
{
|
||||||
"header" : tyto.module_header%(
|
"header" : tyto.module_header%(
|
||||||
|
@ -625,55 +632,124 @@ def get_modules(srv):
|
||||||
),
|
),
|
||||||
"footer" : tyto.module_footer,
|
"footer" : tyto.module_footer,
|
||||||
}
|
}
|
||||||
|
"""
|
||||||
create_html_mods = {
|
modules = \
|
||||||
"header" : navbar_check,
|
{
|
||||||
|
"header" : {
|
||||||
|
"raw" : tyto.module_header%(
|
||||||
|
"/template/%s"%domain.logo, domain.about,
|
||||||
|
"/template/%s"%domain.logo, domain.about, domain.about,
|
||||||
|
domain.title,
|
||||||
|
domain.about
|
||||||
|
),
|
||||||
|
"wrk" : domain.wrk_header,
|
||||||
|
"wip" : domain.wip_header,
|
||||||
|
"www" : domain.www_header,
|
||||||
|
"set" : header_html_create
|
||||||
|
},
|
||||||
|
"navbar" : {
|
||||||
|
"raw" : langs.logs.navbar_header%(
|
||||||
|
domain.title, domain.wrk_articles,
|
||||||
|
domain.wrk_navbar,
|
||||||
|
domain.wip_navbar,
|
||||||
|
domain.www_navbar
|
||||||
|
),
|
||||||
|
"wrk" : domain.wrk_navbar,
|
||||||
|
"wip" : domain.wip_navbar,
|
||||||
|
"www" : domain.www_navbar,
|
||||||
|
"set" : navbar_check
|
||||||
|
},
|
||||||
|
"sidebar" : {
|
||||||
|
"raw" : langs.logs.sidebar_header%(
|
||||||
|
domain.title, domain.wrk_articles,
|
||||||
|
domain.wrk_sidebar,
|
||||||
|
domain.wip_sidebar,
|
||||||
|
domain.www_sidebar
|
||||||
|
),
|
||||||
|
"wrk" : domain.wrk_sidebar,
|
||||||
|
"wip" : domain.wip_sidebar,
|
||||||
|
"www" : domain.www_sidebar,
|
||||||
|
"set" : sidebar_check,
|
||||||
|
},
|
||||||
|
"footer" : {
|
||||||
|
"raw" : tyto.module_footer,
|
||||||
|
"wrk" : domain.wrk_footer,
|
||||||
|
"wip" : domain.wip_footer,
|
||||||
|
"www" : domain.www_footer,
|
||||||
|
"set" : footer_html_create
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Manage modules
|
||||||
|
# Create raw files, and set html "srv" file
|
||||||
|
for mod in modules:
|
||||||
# Create user raw files modules in modules/ directory
|
# Create user raw files modules in modules/ directory
|
||||||
for module in raws_uris:
|
os.path.exists( modules[mod]["wrk"]) or \
|
||||||
if not os.path.exists(raws_uris[module]):
|
tools.create_file(modules[mod]["wrk"], modules[mod]["raw"])
|
||||||
tools.create_file(raws_uris[module], raws_sets[module])
|
|
||||||
|
|
||||||
# Create HTML module from raw files
|
# Create HTML file in srv (wip or www)
|
||||||
for module in create_html_mods:
|
if not modules[mod]["set"](srv):
|
||||||
if not create_html_mods[module](srv):
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
#
|
#================================================#
|
||||||
# Navbar Creation #
|
# Create header.html in server (wip/ or www/) #
|
||||||
#
|
# Remove empty lines and those starting with "#" #
|
||||||
|
# Copy other lines #
|
||||||
|
# modules/tyto_header.raw has default contents #
|
||||||
|
#------------------------------------------------#
|
||||||
|
def header_html_create(srv):
|
||||||
|
with open(domain.wrk_header, "r") as f:
|
||||||
|
header_raw = f.read().rsplit("\n")
|
||||||
|
header_html = ""
|
||||||
|
|
||||||
|
for line in header_raw:
|
||||||
|
if not line or \
|
||||||
|
line.isspace() or \
|
||||||
|
line.lstrip().startswith("#"):
|
||||||
|
continue
|
||||||
|
|
||||||
|
if not header_html: header_html = line
|
||||||
|
else: header_html = "%s\n%s"%(header_html, line)
|
||||||
|
|
||||||
|
tools.create_file(modules["header"][srv], header_html)
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
#========================================================#
|
||||||
|
# Create navbar.html in server (wip/ or www/) #
|
||||||
|
# If navbar is deactivated, create one HTML comment line #
|
||||||
|
# else, create HTML li lists from tyto_navbar.raw datas #
|
||||||
|
#--------------------------------------------------------#
|
||||||
def navbar_check(srv):
|
def navbar_check(srv):
|
||||||
# navbar is NOT activated in domain configuration file
|
# navbar is NOT activated in domain configuration file
|
||||||
navbar_contents = "<!-- Menu navbar -->"
|
navbar_html = "<!-- Menu navbar -->"
|
||||||
if srv == "wip": srv_file = domain.wip_navbar
|
|
||||||
elif srv == "www": srv_file = domain.www_navbar
|
|
||||||
|
|
||||||
if not domain.navbar:
|
if not domain.navbar:
|
||||||
tools.create_file(srv_file, navbar_contents)
|
tools.create_file(modules["navbar"][srv], navbar_html)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
# Create navbar HTML file in srv, from raw
|
# Create navbar HTML file in srv, from raw
|
||||||
if not navbar_html_create(srv_file):
|
if not navbar_html_create(srv):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
#=================================================#
|
||||||
#
|
# Create HTML li lists from tyto_navbar.raw datas #
|
||||||
# Create navbar HTML file in wip, from raw
|
#-------------------------------------------------#
|
||||||
#
|
def navbar_html_create(srv):
|
||||||
def navbar_html_create(srv_file):
|
|
||||||
items = False
|
items = False
|
||||||
|
|
||||||
|
html_indexes = {
|
||||||
|
"wip" : domain.wip,
|
||||||
|
"www" : domain.www
|
||||||
|
}
|
||||||
|
|
||||||
with open(domain.wrk_navbar, "r") as f:
|
with open(domain.wrk_navbar, "r") as f:
|
||||||
navbar_raw = f.read().rsplit("\n")
|
navbar_raw = f.read().rsplit("\n")
|
||||||
navbar_html = ""
|
navbar_html = ""
|
||||||
title = title_html = ""
|
|
||||||
|
|
||||||
|
|
||||||
for ln, line in enumerate(navbar_raw, 1):
|
for ln, line in enumerate(navbar_raw, 1):
|
||||||
if line.lstrip().startswith("#") or \
|
if line.lstrip().startswith("#") or \
|
||||||
|
@ -682,35 +758,97 @@ def navbar_html_create(srv_file):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
html_line = '<li class="site_menu_item"%s href="%s">%s</li>'
|
html_line = '<li class="site_menu_item"%s href="%s">%s</li>'
|
||||||
|
title_html = ""
|
||||||
|
|
||||||
# Get folder title (if set)
|
# Get directory name
|
||||||
if line.lstrip().startswith(">"):
|
|
||||||
title = line.lstrip()[1:].lstrip()
|
|
||||||
title_html = ' title="%s"'%title
|
|
||||||
continue
|
|
||||||
|
|
||||||
# Get directory name and check if exists
|
|
||||||
folder = line.lstrip()
|
folder = line.lstrip()
|
||||||
if not os.path.join(domain.wrk_articles, folder):
|
folder_uri = os.path.join(domain.wrk_articles, folder)
|
||||||
|
|
||||||
|
# Unused directory in articles/
|
||||||
|
if not os.path.exists(folder_uri):
|
||||||
post.error = \
|
post.error = \
|
||||||
debug.out(6, 'Navbar. %s) "%s"'%(
|
debug.out(6, 'Navbar. %s) "%s"'%(
|
||||||
ln, folder
|
ln, folder
|
||||||
), domain.wrk_navbar, True, 2, False)
|
), domain.wrk_navbar, True, 2, False)
|
||||||
return False
|
return False
|
||||||
else:
|
|
||||||
|
# Directory exists
|
||||||
|
# Unused index.tyto in wrk folder
|
||||||
|
wrk_index = os.path.join(folder, "index.tyto")
|
||||||
|
wrk_index_uri = os.path.join(folder_uri, "index.tyto")
|
||||||
|
if not os.path.exists(wrk_index_uri):
|
||||||
|
post.error = \
|
||||||
|
debug.out(5, 'Navbar. %s) "%s"'%(
|
||||||
|
ln, wrk_index
|
||||||
|
), domain.wrk_navbar, True, 2, False)
|
||||||
|
return False
|
||||||
|
|
||||||
|
# Unused index.html in srv
|
||||||
|
html_index_srv_uri = os.path.join(html_indexes[srv], folder)
|
||||||
|
html_index_srv_uri = os.path.join(html_index_srv_uri, "index.html")
|
||||||
|
if not os.path.exists(html_index_srv_uri):
|
||||||
|
post.error = \
|
||||||
|
debug.out(5, 'Navbar. %s) "%s"'%(
|
||||||
|
ln, html_index_srv_uri.rsplit(domain.srv_name)[1]
|
||||||
|
), domain.wrk_navbar, True, 2, False)
|
||||||
|
return False
|
||||||
|
|
||||||
|
# Load post configuration file in tmp module
|
||||||
|
# return if unused or post errors
|
||||||
|
db_id = tools.get_filesum(wrk_index_uri, False) + ".ini"
|
||||||
|
if not post.tmp_load(wrk_index, db_id):
|
||||||
|
return False
|
||||||
|
|
||||||
items = True
|
items = True
|
||||||
|
title_html = ' title="%s - %s"'%(post.tmp_title, post.tmp_about)
|
||||||
|
|
||||||
|
# Format HTML href uri
|
||||||
if not folder.startswith("/"):
|
if not folder.startswith("/"):
|
||||||
folder = "/%s"%folder
|
folder = "/%s"%folder
|
||||||
html_line = html_line%(title_html, folder, folder)
|
if not navbar_html:
|
||||||
if not navbar_html: navbar_html = html_line
|
navbar_html = html_line%(title_html, folder, folder)
|
||||||
else: navbar_html = "%s\n%s"%(navbar_html, html_line)
|
else:
|
||||||
title = title_html = ""
|
navbar_html = "%s\n%s"%(
|
||||||
|
navbar_html,
|
||||||
|
html_line%(title_html, folder, folder)
|
||||||
|
)
|
||||||
|
|
||||||
if not items:
|
if not items:
|
||||||
post.error = \
|
post.error = \
|
||||||
debug.out(9, 'Navbar', domain.wrk_navbar, True, 2, False)
|
debug.out(9, 'Navbar', domain.wrk_navbar, True, 2, False)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
tools.create_file(srv_file, tyto.module_navbar%navbar_html)
|
tools.create_file(modules["navbar"][srv], tyto.module_navbar%navbar_html)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
#
|
||||||
|
#
|
||||||
|
#
|
||||||
|
def sidebar_check(srv):
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
#================================================#
|
||||||
|
# Create footer.html in server (wip/ or www/) #
|
||||||
|
# Remove empty lines and those starting with "#" #
|
||||||
|
# Copy other lines #
|
||||||
|
# modules/tyto_footer.raw has default contents #
|
||||||
|
#------------------------------------------------#
|
||||||
|
def footer_html_create(srv):
|
||||||
|
with open(domain.wrk_footer, "r") as f:
|
||||||
|
footer_raw = f.read().rsplit("\n")
|
||||||
|
footer_html = ""
|
||||||
|
|
||||||
|
for line in footer_raw:
|
||||||
|
if not line or \
|
||||||
|
line.isspace() or \
|
||||||
|
line.lstrip().startswith("#"):
|
||||||
|
continue
|
||||||
|
|
||||||
|
if not footer_html: footer_html = line
|
||||||
|
else: footer_html = "%s\n%s"%(footer_html, line)
|
||||||
|
|
||||||
|
tools.create_file(modules["footer"][srv], footer_html)
|
||||||
|
return True
|
||||||
|
|
Binary file not shown.
|
@ -145,13 +145,10 @@ navbar_header = """#
|
||||||
# How to configure this file:
|
# How to configure this file:
|
||||||
# - Add one directory URI per line
|
# - Add one directory URI per line
|
||||||
# - - URI is from domain directory articles/
|
# - - URI is from domain directory articles/
|
||||||
# - - Option:
|
# ! Must contains an article "index.tyto" ready
|
||||||
# - - - Add title folder before the directory line "> Directory title"
|
|
||||||
|
|
||||||
# Examples:
|
# Examples:
|
||||||
# > All last news
|
|
||||||
# news !
|
# news !
|
||||||
# > About this website
|
|
||||||
# about/website
|
# about/website
|
||||||
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -145,13 +145,10 @@ navbar_header = """#
|
||||||
# Comment configurer ce fichier :
|
# Comment configurer ce fichier :
|
||||||
# - Ajouter un URI de dossier par ligne
|
# - Ajouter un URI de dossier par ligne
|
||||||
# - - URI depuis le dossier articles/ du domaine
|
# - - URI depuis le dossier articles/ du domaine
|
||||||
# - - Option :
|
# ! Doit contenir un article "index.tyto" prêt
|
||||||
# - - - Ajouter le titre du dossier avant la ligne "> TITRE du dossier"
|
|
||||||
|
|
||||||
# Exemples:
|
# Exemples:
|
||||||
# > Toutes les dernières nouvelles
|
|
||||||
# news
|
# news
|
||||||
# > À propos de ce site
|
|
||||||
# a-propos/website
|
# a-propos/website
|
||||||
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in New Issue