[1.9.34]
This commit is contained in:
parent
461c15c46e
commit
238b886bea
|
@ -10,6 +10,13 @@ Tyto - Littérateur
|
|||
|
||||
# CURRENTLY IN DEV (in devel branch) !
|
||||
|
||||
## [1.9.34]
|
||||
- Working on creating modules
|
||||
- - fixes typos codes
|
||||
- - header, navbar, sidebar = ok
|
||||
- - toto footer contents and testing things
|
||||
- - Manage modules with an ini db file to avoid creating HTML updated modules
|
||||
|
||||
## [1.9.33]
|
||||
- Working on creating modules (header, navbar, sidebar, header)
|
||||
- - Added working header module
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#!/usr/bin/env python3
|
||||
# Version: 1.9.33
|
||||
# Version: 1.9.34
|
||||
# Updated: 2023-10-18 1697613100
|
||||
# Tyto - Littérateur
|
||||
|
||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -157,40 +157,49 @@ def cf_load():
|
|||
#======================================#
|
||||
# Load another post configuration file #
|
||||
#--------------------------------------#
|
||||
def tmp_load(wrk_post, db_id):
|
||||
def tmp_load(wrk_post, wrk_post_uri):
|
||||
global error
|
||||
|
||||
db_tmp_uri = os.path.join(domain.wrk_db, db_id)
|
||||
post_tmp_uri = os.path.join(domain.wrk_articles, wrk_post)
|
||||
db_uri = os.path.join(
|
||||
domain.wrk_db,
|
||||
tools.get_filesum(wrk_post_uri, False) + ".ini"
|
||||
)
|
||||
|
||||
if not os.path.exists(db_tmp_uri):
|
||||
if not os.path.exists(db_uri):
|
||||
error = \
|
||||
debug.out(5, wrk_post, db_tmp_uri, True, 2, False)
|
||||
debug.out(5, wrk_post, db_uri, True, 2, False)
|
||||
return False
|
||||
|
||||
global tmp_cf
|
||||
tmp_cf = ""
|
||||
tmp_cf = configparser.ConfigParser()
|
||||
tmp_cf.read(tmp_uri)
|
||||
tmp_cf.read(db_uri)
|
||||
|
||||
if tmp_cf.get("CHECK", "errors"):
|
||||
if tmp_cf.getboolean("CHECK", "errors"):
|
||||
error = \
|
||||
debug.out(10, "True", db_tmp_uri, True, 2, False)
|
||||
debug.out(10, "True", db_uri, True, 2, False)
|
||||
return False
|
||||
|
||||
global tmp_title, tmp_about
|
||||
global tmp_title, tmp_about, tmp_logo
|
||||
try:
|
||||
tmp_title = tmp_cf.get("HEADERS", "title")
|
||||
except:
|
||||
error = \
|
||||
debug.out(51, "title:", post_tmp_uri, True, 2, False)
|
||||
debug.out(51, "title:", wrk_post_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)
|
||||
debug.out(51, "about:", wrk_post_uri, True, 2, False)
|
||||
return False
|
||||
|
||||
try:
|
||||
tmp_logo = tmp_cf.get("HEADERS", "logo")
|
||||
except:
|
||||
error = \
|
||||
debug.out(51, "logo:", wrk_post_uri, True, 2, False)
|
||||
return False
|
||||
|
||||
return True
|
||||
|
|
|
@ -161,14 +161,19 @@ module_header = """<!-- Header (logo, description) -->
|
|||
</div<
|
||||
</header>"""
|
||||
|
||||
module_navbar = """<!-- Menu navbar -->
|
||||
module_navbar = """<!-- Website Menu navbar -->
|
||||
<nav id="site_menu">
|
||||
<menu id="site_menu_items">
|
||||
%s
|
||||
</menu>
|
||||
</nav>"""
|
||||
|
||||
module_aside = """<!-- Aside articles navigation -->
|
||||
module_sidebar = """<!-- Website Sidebar -->
|
||||
<aside id="site_sidebar">
|
||||
<ul id="site_sidebar_items">
|
||||
%s
|
||||
</ul>
|
||||
</aside>
|
||||
"""
|
||||
|
||||
module_footer = """<!-- Website footer-->
|
||||
|
|
|
@ -35,7 +35,7 @@
|
|||
# file program :
|
||||
#--------------------------
|
||||
|
||||
import sys, os
|
||||
import sys, os, configparser
|
||||
import args, debug, tyto, tools, post, domain, check, langs
|
||||
|
||||
|
||||
|
@ -105,6 +105,11 @@ def convert(target):
|
|||
for key, directory in domain.cf.items("WIP_DIRS"):
|
||||
tools.create_dirs(directory)
|
||||
|
||||
# Warn if unused registred file in wrk template/ directory
|
||||
for key, uri in domain.cf.items("USER_TEMPLATE_FILES"):
|
||||
os.path.exists(uri) or \
|
||||
debug.out(5, key, uri, True, 1, False)
|
||||
|
||||
# Check/Create modules files
|
||||
# navbar, sidebar, header, footer
|
||||
if not get_modules("wip"):
|
||||
|
@ -591,6 +596,27 @@ def convert_list(markdown_str, mark_b, mark_c):
|
|||
#=========#
|
||||
# Modules #====================================================================
|
||||
#---------#
|
||||
#==================================#
|
||||
# Create modules ini database file #
|
||||
# return False if: #
|
||||
# - datas changed #
|
||||
# - not created #
|
||||
#----------------------------------#
|
||||
def modules_db():
|
||||
global db_mods_uri, mods_cf
|
||||
|
||||
db_mods_uri = os.path.join(domain.wrk_mods, ".modules.ini")
|
||||
|
||||
if not os.path.exists(db_mods_uri):
|
||||
tools.create_file(db_mods_uri, ini_mods)
|
||||
|
||||
mods_cf = configparser.ConfigParser()
|
||||
mods_cf.read(db_mods_uri)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#============================================#
|
||||
# Check / Create modules files (.raw + .html #
|
||||
# process: "wip" or "www" #
|
||||
|
@ -599,40 +625,10 @@ def convert_list(markdown_str, mark_b, mark_c):
|
|||
# - header #
|
||||
# - footer #
|
||||
#--------------------------------------------#
|
||||
def get_modules(srv):
|
||||
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%(
|
||||
"/template/%s"%domain.logo, domain.about,
|
||||
"/template/%s"%domain.logo, domain.about, domain.about,
|
||||
domain.title,
|
||||
domain.about
|
||||
),
|
||||
"navbar" : langs.logs.navbar_header%(
|
||||
domain.title, domain.wrk_articles,
|
||||
domain.wrk_navbar,
|
||||
domain.wip_navbar,
|
||||
domain.www_navbar
|
||||
),
|
||||
"sidebar" : langs.logs.sidebar_header%(
|
||||
domain.title, domain.wrk_articles,
|
||||
domain.wrk_sidebar,
|
||||
domain.wip_sidebar,
|
||||
domain.www_sidebar
|
||||
),
|
||||
"footer" : tyto.module_footer,
|
||||
}
|
||||
"""
|
||||
modules = \
|
||||
{
|
||||
"header" : {
|
||||
|
@ -680,16 +676,43 @@ def get_modules(srv):
|
|||
},
|
||||
}
|
||||
|
||||
# Avois creating again module if files are same
|
||||
modules_db()
|
||||
mods_cf_write = False
|
||||
|
||||
# Manage modules
|
||||
# Create raw files, and set html "srv" file
|
||||
for mod in modules:
|
||||
create_html_module = False
|
||||
|
||||
# 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 file in srv (wip or www)
|
||||
if not modules[mod]["set"](srv):
|
||||
return False
|
||||
if os.path.exists(modules[mod]["wrk"]):
|
||||
cur_raw_id = tools.get_filesum(modules[mod]["wrk"], True)
|
||||
mod_raw_id = mods_cf.get(mod.upper(), "raw")
|
||||
if cur_raw_id != mod_raw_id:
|
||||
mods_cf.set(mod.upper(), "raw", cur_raw_id)
|
||||
mods_cf_write = True
|
||||
create_html_module = True
|
||||
|
||||
else:
|
||||
tools.create_file(modules[mod]["wrk"], modules[mod]["raw"])
|
||||
mods_cf.set(mod.upper(), "raw", cur_raw_id)
|
||||
mods_cf_write = True
|
||||
create_html_module = True
|
||||
|
||||
# Unused module HTML file
|
||||
if not os.path.exists(modules[mod][srv]):
|
||||
create_html_module = True
|
||||
|
||||
# Create HTML module if needed (raw updated, or unused html file)
|
||||
if create_html_module:
|
||||
print(">> HTML", mod)
|
||||
if not modules[mod]["set"](srv):
|
||||
return False
|
||||
|
||||
if mods_cf_write:
|
||||
with open(db_mods_uri, "w") as f:
|
||||
mods_cf.write(f)
|
||||
|
||||
return True
|
||||
|
||||
|
@ -700,7 +723,7 @@ def get_modules(srv):
|
|||
# Copy other lines #
|
||||
# modules/tyto_header.raw has default contents #
|
||||
#------------------------------------------------#
|
||||
def header_html_create(srv):
|
||||
def header_html_create(srv):
|
||||
with open(domain.wrk_header, "r") as f:
|
||||
header_raw = f.read().rsplit("\n")
|
||||
header_html = ""
|
||||
|
@ -737,11 +760,11 @@ def navbar_check(srv):
|
|||
return True
|
||||
|
||||
#=================================================#
|
||||
# navbar is True in domain configuration file #
|
||||
# Create HTML li lists from tyto_navbar.raw datas #
|
||||
#-------------------------------------------------#
|
||||
def navbar_html_create(srv):
|
||||
items = False
|
||||
|
||||
items = False
|
||||
html_indexes = {
|
||||
"wip" : domain.wip,
|
||||
"www" : domain.www
|
||||
|
@ -749,19 +772,23 @@ def navbar_html_create(srv):
|
|||
|
||||
with open(domain.wrk_navbar, "r") as f:
|
||||
navbar_raw = f.read().rsplit("\n")
|
||||
navbar_html = ""
|
||||
navbar_html = "<!-- Website Menu Directories -->"
|
||||
html_line = '<li class="site_menu_item"%s>' + \
|
||||
'<a class="%s site_menu_link" href="%s">%s</a></li>'
|
||||
|
||||
for ln, line in enumerate(navbar_raw, 1):
|
||||
if line.lstrip().startswith("#") or \
|
||||
not line or \
|
||||
line.isspace():
|
||||
continue
|
||||
|
||||
# Get directory name and link name (if separated by "#")
|
||||
try:
|
||||
folder = line.lstrip().rsplit("#")[0].rstrip()
|
||||
link_name = line.lstrip().rsplit("#")[1].lstrip().rstrip()
|
||||
except:
|
||||
link_name = folder = line.lstrip().rstrip()
|
||||
|
||||
html_line = '<li class="site_menu_item"%s href="%s">%s</li>'
|
||||
title_html = ""
|
||||
|
||||
# Get directory name
|
||||
folder = line.lstrip()
|
||||
folder_uri = os.path.join(domain.wrk_articles, folder)
|
||||
|
||||
# Unused directory in articles/
|
||||
|
@ -795,23 +822,19 @@ def navbar_html_create(srv):
|
|||
|
||||
# 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):
|
||||
if not post.tmp_load(wrk_index, wrk_index_uri):
|
||||
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:
|
||||
navbar_html = "%s\n%s"%(
|
||||
navbar_html,
|
||||
html_line%(title_html, folder, folder)
|
||||
)
|
||||
navbar_html = "%s\n%s"%(
|
||||
navbar_html,
|
||||
html_line%(title_html, domain.css, folder, link_name)
|
||||
)
|
||||
|
||||
if not items:
|
||||
post.error = \
|
||||
|
@ -823,10 +846,121 @@ def navbar_html_create(srv):
|
|||
return True
|
||||
|
||||
|
||||
#
|
||||
#
|
||||
#
|
||||
#=========================================================#
|
||||
# Create sidebar.html in server (wip/ or www/) #
|
||||
# If sidebar is deactivated, create one HTML comment line #
|
||||
# else, create HTML li lists from tyto_sidebar.raw datas #
|
||||
#---------------------------------------------------------#
|
||||
def sidebar_check(srv):
|
||||
# sidebar is NOT activated (= 0) in domain configuration file
|
||||
sidebar_html = "<!-- Website sidebar articles -->"
|
||||
if int(domain.sidebar_items) == 0:
|
||||
tools.create_file(modules["sidebar"][srv], sidebar_html)
|
||||
return True
|
||||
|
||||
# Create sidebar HTML file in srv, from raw
|
||||
if not sidebar_html_create(srv):
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
|
||||
#==================================================#
|
||||
# sidebar_items > 0 in domain configuration file #
|
||||
# Create HTML li lists from tyto_sidebar.raw datas #
|
||||
#--------------------------------------------------#
|
||||
def sidebar_html_create(srv):
|
||||
max_items = int(domain.sidebar_items)
|
||||
items = 0
|
||||
html_post_uri = {
|
||||
"wip" : domain.wip,
|
||||
"www" : domain.www
|
||||
}
|
||||
|
||||
with open(domain.wrk_sidebar, "r") as f:
|
||||
sidebar_raw = f.read().rsplit("\n")
|
||||
sidebar_html = "<!-- Website Sidebar articles -->"
|
||||
html_line = '<li class="site_sidebar_item">' + \
|
||||
'<a class="site_sidebar_link" href="%s">' + \
|
||||
'<div class="site_sidebar_block">' + \
|
||||
'<header class="site_sidebar_header">' + \
|
||||
'<p class="site_sidebar_title">%s</p>' + \
|
||||
'</header>' + \
|
||||
'<footer class="site_sidebar_footer">' + \
|
||||
'<img class="site_sidebar_image" src="%s" alt="%s">' + \
|
||||
'<p class="site_sidebar_about">%s</p>' + \
|
||||
'</footer>' + \
|
||||
'</div>' + \
|
||||
'</a>' + \
|
||||
'</li>'
|
||||
|
||||
for ln, line in enumerate(sidebar_raw, 1):
|
||||
# User wants max_items
|
||||
if items > max_items:
|
||||
break
|
||||
|
||||
if line.lstrip().startswith("#") or \
|
||||
not line or \
|
||||
line.isspace():
|
||||
continue
|
||||
|
||||
# Set post uri from line
|
||||
wrk_post = line.lstrip()
|
||||
wrk_post_uri = os.path.join(domain.wrk_articles, wrk_post)
|
||||
|
||||
# Unused file in articles/
|
||||
if not os.path.exists(wrk_post_uri):
|
||||
post.error = \
|
||||
debug.out(5, "Sidebar. %s) %s"%(
|
||||
ln, wrk_post
|
||||
), wrk_post_uri, True, 2, False)
|
||||
return False
|
||||
|
||||
# Set HTML post uri in srv
|
||||
srv_post_uri = os.path.join(
|
||||
html_post_uri[srv],
|
||||
wrk_post[:-4] + "html"
|
||||
)
|
||||
|
||||
# Unused HTML post
|
||||
if not os.path.exists(srv_post_uri):
|
||||
post.error = \
|
||||
debug.out(5, "Sidebar. %s) %s"%(
|
||||
ln, wrk_post
|
||||
), srv_post_uri, True, 2, False)
|
||||
return False
|
||||
|
||||
# Load post configuration file in tmp module
|
||||
# return if unused or post errors
|
||||
if not post.tmp_load(wrk_post, wrk_post_uri):
|
||||
return False
|
||||
|
||||
# Post can be added to list
|
||||
items += 1
|
||||
if not wrk_post.startswith("/"):
|
||||
wrk_post = "/" + wrk_post
|
||||
wrk_post = wrk_post[:-4] + "html"
|
||||
if wrk_post.endswith("index.html"):
|
||||
wrk_post = wrk_post[:-10]
|
||||
sidebar_html = "%s\n%s"%(
|
||||
sidebar_html,
|
||||
html_line%(
|
||||
wrk_post,
|
||||
post.tmp_title,
|
||||
'/%s'%post.tmp_logo.rsplit(domain.www_url)[1],
|
||||
post.tmp_title,
|
||||
post.tmp_about,
|
||||
)
|
||||
)
|
||||
|
||||
# sidebar configuration error
|
||||
if items == 0:
|
||||
post.error = \
|
||||
debug.out(9, 'Sidebar', domain.wrk_sidebar, True, 2, False)
|
||||
return False
|
||||
|
||||
|
||||
tools.create_file(modules["sidebar"][srv], tyto.module_sidebar%sidebar_html)
|
||||
return True
|
||||
|
||||
|
||||
|
@ -852,3 +986,21 @@ def footer_html_create(srv):
|
|||
|
||||
tools.create_file(modules["footer"][srv], footer_html)
|
||||
return True
|
||||
|
||||
|
||||
#======#
|
||||
# MAIN #=======================================================================
|
||||
#======#
|
||||
ini_mods = """
|
||||
[HEADER]
|
||||
raw =
|
||||
|
||||
[NAVBAR]
|
||||
raw =
|
||||
|
||||
[SIDEBAR]
|
||||
raw =
|
||||
|
||||
[FOOTER]
|
||||
raw =
|
||||
"""
|
||||
|
|
|
@ -31,6 +31,8 @@ p#site_infos_text {}
|
|||
nav#site_menu {}
|
||||
menu#site_menu_items {}
|
||||
li.site_menu_item {}
|
||||
/* also a.tyto {} */
|
||||
a.site_menu_link {}
|
||||
|
||||
|
||||
/* div contains <article> and <aside> */
|
||||
|
@ -122,3 +124,19 @@ a.post_logo {}
|
|||
img.post_logo {}
|
||||
/* Legacy image link has also a.tyto OR a.MYCUSTOMCSS */
|
||||
img.tyto {}
|
||||
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
* Sidebar navigation
|
||||
*/
|
||||
aside#site_sidebar {}
|
||||
ul#site_sidebar_items {}
|
||||
li.site_sidebar_item {}
|
||||
/* Around div.site_sidebar_block */
|
||||
a.site_sidebar_link {}
|
||||
div.site_sidebar_block {}
|
||||
header.site_sidebar_header {}
|
||||
p.site_sidebar_title {}
|
||||
footer.site_sidebar_footer {}
|
||||
img.site_sidebar_image {}
|
||||
p.site_sidebar_about {}
|
||||
|
|
Binary file not shown.
|
@ -146,6 +146,9 @@ navbar_header = """#
|
|||
# - Add one directory URI per line
|
||||
# - - URI is from domain directory articles/
|
||||
# ! Must contains an article "index.tyto" ready
|
||||
# Option:
|
||||
# - Default link name : directory
|
||||
# - Add "# Link Name" to change it
|
||||
|
||||
# Examples:
|
||||
# news !
|
||||
|
|
|
@ -146,6 +146,9 @@ navbar_header = """#
|
|||
# - Ajouter un URI de dossier par ligne
|
||||
# - - URI depuis le dossier articles/ du domaine
|
||||
# ! Doit contenir un article "index.tyto" prêt
|
||||
# Option :
|
||||
# - Nom du lien par défaut : directory
|
||||
# - Ajouter "# Nom du Lien" pour le changer
|
||||
|
||||
# Exemples:
|
||||
# news
|
||||
|
|
Loading…
Reference in New Issue