[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) !
|
||||
|
||||
## [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]
|
||||
- Working on creating modules (header, navbar, sidebar, header)
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@ tyto
|
|||
## Working on
|
||||
- 'wip' action processes
|
||||
- Create HTML full page from article
|
||||
- Create/Manage modules (header, navbar, sidebar, footer)
|
||||
|
||||
## ToDo
|
||||
- thinking about creating an auto top article menu from titles
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
Package: tyto
|
||||
Version: 1.9.32
|
||||
Version: 1.9.33
|
||||
Section: custom
|
||||
Priority: optional
|
||||
Architecture: all
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#!/usr/bin/env python3
|
||||
# Version: 1.9.32
|
||||
# Version: 1.9.33
|
||||
# Updated: 2023-10-18 1697613100
|
||||
# Tyto - Littérateur
|
||||
|
||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -154,6 +154,48 @@ def cf_load():
|
|||
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 #
|
||||
#--------------------------------#
|
||||
|
|
|
@ -115,7 +115,7 @@ def create_dirs(path):
|
|||
debug.out(203, "True", path, False, 0, False)
|
||||
except:
|
||||
# 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):
|
||||
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
|
||||
# navbar, sidebar, header, footer
|
||||
if not get_modules("wip"):
|
||||
|
@ -595,14 +600,16 @@ def convert_list(markdown_str, mark_b, mark_c):
|
|||
# - footer #
|
||||
#--------------------------------------------#
|
||||
def get_modules(srv):
|
||||
global modules
|
||||
|
||||
# Modules settings
|
||||
"""
|
||||
raws_uris = {
|
||||
"header" : domain.wrk_header,
|
||||
"navbar" : domain.wrk_navbar,
|
||||
"sidebar" : domain.wrk_sidebar,
|
||||
"footer" : domain.wrk_footer
|
||||
}
|
||||
|
||||
raws_sets = \
|
||||
{
|
||||
"header" : tyto.module_header%(
|
||||
|
@ -625,56 +632,125 @@ def get_modules(srv):
|
|||
),
|
||||
"footer" : tyto.module_footer,
|
||||
}
|
||||
"""
|
||||
modules = \
|
||||
{
|
||||
"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
|
||||
},
|
||||
}
|
||||
|
||||
create_html_mods = {
|
||||
"header" : navbar_check,
|
||||
}
|
||||
|
||||
# Create user raw files modules in modules/ directory
|
||||
for module in raws_uris:
|
||||
if not os.path.exists(raws_uris[module]):
|
||||
tools.create_file(raws_uris[module], raws_sets[module])
|
||||
# Manage modules
|
||||
# Create raw files, and set html "srv" file
|
||||
for mod in modules:
|
||||
# Create user raw files modules in modules/ directory
|
||||
os.path.exists( modules[mod]["wrk"]) or \
|
||||
tools.create_file(modules[mod]["wrk"], modules[mod]["raw"])
|
||||
|
||||
# Create HTML module from raw files
|
||||
for module in create_html_mods:
|
||||
if not create_html_mods[module](srv):
|
||||
# Create HTML file in srv (wip or www)
|
||||
if not modules[mod]["set"](srv):
|
||||
return False
|
||||
|
||||
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):
|
||||
# navbar is NOT activated in domain configuration file
|
||||
navbar_contents = "<!-- Menu navbar -->"
|
||||
if srv == "wip": srv_file = domain.wip_navbar
|
||||
elif srv == "www": srv_file = domain.www_navbar
|
||||
|
||||
navbar_html = "<!-- Menu navbar -->"
|
||||
if not domain.navbar:
|
||||
tools.create_file(srv_file, navbar_contents)
|
||||
tools.create_file(modules["navbar"][srv], navbar_html)
|
||||
return True
|
||||
|
||||
# Create navbar HTML file in srv, from raw
|
||||
if not navbar_html_create(srv_file):
|
||||
if not navbar_html_create(srv):
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
|
||||
#
|
||||
# Create navbar HTML file in wip, from raw
|
||||
#
|
||||
def navbar_html_create(srv_file):
|
||||
#=================================================#
|
||||
# Create HTML li lists from tyto_navbar.raw datas #
|
||||
#-------------------------------------------------#
|
||||
def navbar_html_create(srv):
|
||||
items = False
|
||||
|
||||
html_indexes = {
|
||||
"wip" : domain.wip,
|
||||
"www" : domain.www
|
||||
}
|
||||
|
||||
with open(domain.wrk_navbar, "r") as f:
|
||||
navbar_raw = f.read().rsplit("\n")
|
||||
navbar_html = ""
|
||||
title = title_html = ""
|
||||
|
||||
|
||||
|
||||
for ln, line in enumerate(navbar_raw, 1):
|
||||
if line.lstrip().startswith("#") or \
|
||||
not line or \
|
||||
|
@ -682,35 +758,97 @@ def navbar_html_create(srv_file):
|
|||
continue
|
||||
|
||||
html_line = '<li class="site_menu_item"%s href="%s">%s</li>'
|
||||
title_html = ""
|
||||
|
||||
# Get folder title (if set)
|
||||
if line.lstrip().startswith(">"):
|
||||
title = line.lstrip()[1:].lstrip()
|
||||
title_html = ' title="%s"'%title
|
||||
continue
|
||||
# Get directory name
|
||||
folder = line.lstrip()
|
||||
folder_uri = os.path.join(domain.wrk_articles, folder)
|
||||
|
||||
# Get directory name and check if exists
|
||||
folder = line.lstrip()
|
||||
if not os.path.join(domain.wrk_articles, folder):
|
||||
# Unused directory in articles/
|
||||
if not os.path.exists(folder_uri):
|
||||
post.error = \
|
||||
debug.out(6, 'Navbar. %s) "%s"'%(
|
||||
ln, folder
|
||||
), domain.wrk_navbar, True, 2, False)
|
||||
return False
|
||||
|
||||
# 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
|
||||
title_html = ' title="%s - %s"'%(post.tmp_title, post.tmp_about)
|
||||
|
||||
# Format HTML href uri
|
||||
if not folder.startswith("/"):
|
||||
folder = "/%s"%folder
|
||||
if not navbar_html:
|
||||
navbar_html = html_line%(title_html, folder, folder)
|
||||
else:
|
||||
items = True
|
||||
if not folder.startswith("/"):
|
||||
folder = "/%s"%folder
|
||||
html_line = html_line%(title_html, folder, folder)
|
||||
if not navbar_html: navbar_html = html_line
|
||||
else: navbar_html = "%s\n%s"%(navbar_html, html_line)
|
||||
title = title_html = ""
|
||||
navbar_html = "%s\n%s"%(
|
||||
navbar_html,
|
||||
html_line%(title_html, folder, folder)
|
||||
)
|
||||
|
||||
if not items:
|
||||
post.error = \
|
||||
debug.out(9, 'Navbar', domain.wrk_navbar, True, 2, 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
|
||||
|
||||
|
||||
#
|
||||
#
|
||||
#
|
||||
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:
|
||||
# - Add one directory URI per line
|
||||
# - - URI is from domain directory articles/
|
||||
# - - Option:
|
||||
# - - - Add title folder before the directory line "> Directory title"
|
||||
# ! Must contains an article "index.tyto" ready
|
||||
|
||||
# Examples:
|
||||
# > All last news
|
||||
# news !
|
||||
# > About this website
|
||||
# about/website
|
||||
#------------------------------------------------------------------------------
|
||||
"""
|
||||
|
|
|
@ -145,13 +145,10 @@ navbar_header = """#
|
|||
# Comment configurer ce fichier :
|
||||
# - Ajouter un URI de dossier par ligne
|
||||
# - - URI depuis le dossier articles/ du domaine
|
||||
# - - Option :
|
||||
# - - - Ajouter le titre du dossier avant la ligne "> TITRE du dossier"
|
||||
# ! Doit contenir un article "index.tyto" prêt
|
||||
|
||||
# Exemples:
|
||||
# > Toutes les dernières nouvelles
|
||||
# news
|
||||
# > À propos de ce site
|
||||
# a-propos/website
|
||||
#------------------------------------------------------------------------------
|
||||
"""
|
||||
|
|
Loading…
Reference in New Issue