diff --git a/CHANGELOG.md b/CHANGELOG.md index 1945be0..5bab16f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/README.md b/README.md index b8323d5..3e75292 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/debian/control b/debian/control index 0b08938..1104f3e 100644 --- a/debian/control +++ b/debian/control @@ -1,5 +1,5 @@ Package: tyto -Version: 1.9.32 +Version: 1.9.33 Section: custom Priority: optional Architecture: all diff --git a/src/usr/bin/tyto b/src/usr/bin/tyto index 54aaa26..1c0911b 100755 --- a/src/usr/bin/tyto +++ b/src/usr/bin/tyto @@ -1,5 +1,5 @@ #!/usr/bin/env python3 -# Version: 1.9.32 +# Version: 1.9.33 # Updated: 2023-10-18 1697613100 # Tyto - Littérateur diff --git a/src/var/lib/tyto/program/__pycache__/post.cpython-311.pyc b/src/var/lib/tyto/program/__pycache__/post.cpython-311.pyc index e417c3e..ea6f09a 100644 Binary files a/src/var/lib/tyto/program/__pycache__/post.cpython-311.pyc and b/src/var/lib/tyto/program/__pycache__/post.cpython-311.pyc differ diff --git a/src/var/lib/tyto/program/__pycache__/tools.cpython-311.pyc b/src/var/lib/tyto/program/__pycache__/tools.cpython-311.pyc index 61c55d8..1349020 100644 Binary files a/src/var/lib/tyto/program/__pycache__/tools.cpython-311.pyc and b/src/var/lib/tyto/program/__pycache__/tools.cpython-311.pyc differ diff --git a/src/var/lib/tyto/program/__pycache__/wip.cpython-311.pyc b/src/var/lib/tyto/program/__pycache__/wip.cpython-311.pyc index 4085ffa..2863a3a 100644 Binary files a/src/var/lib/tyto/program/__pycache__/wip.cpython-311.pyc and b/src/var/lib/tyto/program/__pycache__/wip.cpython-311.pyc differ diff --git a/src/var/lib/tyto/program/post.py b/src/var/lib/tyto/program/post.py index 678bd99..70ab4f9 100644 --- a/src/var/lib/tyto/program/post.py +++ b/src/var/lib/tyto/program/post.py @@ -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 # #--------------------------------# diff --git a/src/var/lib/tyto/program/tools.py b/src/var/lib/tyto/program/tools.py index ed7f251..a2ab867 100644 --- a/src/var/lib/tyto/program/tools.py +++ b/src/var/lib/tyto/program/tools.py @@ -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) #============================# diff --git a/src/var/lib/tyto/program/wip.py b/src/var/lib/tyto/program/wip.py index 3425b59..52a5b39 100644 --- a/src/var/lib/tyto/program/wip.py +++ b/src/var/lib/tyto/program/wip.py @@ -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 = "" - if srv == "wip": srv_file = domain.wip_navbar - elif srv == "www": srv_file = domain.www_navbar - + navbar_html = "" 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 = '