diff --git a/CHANGELOG.md b/CHANGELOG.md index 5bab16f..4f6b1e4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/usr/bin/tyto b/src/usr/bin/tyto index 1c0911b..2d28505 100755 --- a/src/usr/bin/tyto +++ b/src/usr/bin/tyto @@ -1,5 +1,5 @@ #!/usr/bin/env python3 -# Version: 1.9.33 +# Version: 1.9.34 # 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 ea6f09a..60ace83 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__/tyto.cpython-311.pyc b/src/var/lib/tyto/program/__pycache__/tyto.cpython-311.pyc index c5e5e2a..67d1412 100644 Binary files a/src/var/lib/tyto/program/__pycache__/tyto.cpython-311.pyc and b/src/var/lib/tyto/program/__pycache__/tyto.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 2863a3a..20bf17d 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 70ab4f9..88ad2b1 100644 --- a/src/var/lib/tyto/program/post.py +++ b/src/var/lib/tyto/program/post.py @@ -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 diff --git a/src/var/lib/tyto/program/tyto.py b/src/var/lib/tyto/program/tyto.py index 9802265..0046ee5 100644 --- a/src/var/lib/tyto/program/tyto.py +++ b/src/var/lib/tyto/program/tyto.py @@ -161,14 +161,19 @@ module_header = """ """ -module_navbar = """ +module_navbar = """ """ -module_aside = """ +module_sidebar = """ + """ module_footer = """ diff --git a/src/var/lib/tyto/program/wip.py b/src/var/lib/tyto/program/wip.py index 52a5b39..8caefd8 100644 --- a/src/var/lib/tyto/program/wip.py +++ b/src/var/lib/tyto/program/wip.py @@ -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 = "" + html_line = '' 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 = '' - 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 = "" + 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 = "" + html_line = '
  • ' + \ + '' + \ + '
    ' + \ + '
    ' + \ + '

    %s

    ' + \ + '
    ' + \ + '' + \ + '
    ' + \ + '
    ' + \ + '
  • ' + + 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 = +""" diff --git a/src/var/lib/tyto/tpl_files/styles.css b/src/var/lib/tyto/tpl_files/styles.css index 5608a1b..0e7209b 100644 --- a/src/var/lib/tyto/tpl_files/styles.css +++ b/src/var/lib/tyto/tpl_files/styles.css @@ -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
    and