diff --git a/src/var/lib/tyto/program/html.py b/src/var/lib/tyto/program/html.py index 113f843..807dcfc 100644 --- a/src/var/lib/tyto/program/html.py +++ b/src/var/lib/tyto/program/html.py @@ -45,9 +45,9 @@ trans = [ # Translations terms # # Only FR (default) and Other (english) # #---------------------------------------# -def translations(): +def translations(post_date): global fl # fl = field lang - global post_date + global sdb_date # Default FR/fr if re.match('fr', domain.domain_lang, re.IGNORECASE): fl = 0 @@ -57,6 +57,7 @@ def translations(): if fl == 0: fr_date = post_date.rsplit('-') post_date = fr_date[2] + '/' + fr_date[1] + '/' + fr_date[0] + sdb_date = post_date #========================# # Create FULL HTML5 Page # @@ -99,7 +100,7 @@ def html_main_page(wip_html): log.append_f(check.post_logs, msg_log, 1) # Set some terms from lang domain - translations() + translations(post_date) # External URL in metas (if exists in config domain) if domain.domain_exturl: diff --git a/src/var/lib/tyto/program/sidebar.py b/src/var/lib/tyto/program/sidebar.py index 6096e3e..ac846ef 100644 --- a/src/var/lib/tyto/program/sidebar.py +++ b/src/var/lib/tyto/program/sidebar.py @@ -18,7 +18,9 @@ #********************************************************************** import re, os, sys, subprocess -import log, domain, check +import log, domain, check, html + +sidebar_file = '%ssidebar.html'%domain.srv_wip_template #========================# # Manage sidebar command # @@ -52,17 +54,20 @@ def manage_sidebar(article, Opt): #------------------------# def loop_sidebar(create): Post_Err = False - sdb_posts = [] + sdb_posts = posts_uri = [] max_items = int(domain.domain_sdb_items) + 1 - counter = 0 # TO not count more than set in config + counter = 0 # To not set more than set in config sdb_loaded = (open(domain.domain_sdb_load)).read() for line in sdb_loaded.rsplit('\n'): if create : print(line) elif line.startswith('#'): continue elif len(line) == 0 : continue else: - if line.startswith('/'): line = line[1:len(line)] + if line.startswith('/'): line = line[1:len(line)] # No need /... + post_uri = '%s%s'%(domain.domain_articles, line) + posts_uri = posts_uri + [post_uri] + if not os.path.exists(post_uri): print(':< From URI: %s. Unused file: %s'%(line, post_uri)) Post_Err = True @@ -76,16 +81,69 @@ def loop_sidebar(create): msg_log = 'Sidebar > Not created. Mismatch some article\'s URI' log.append_f(domain.tyto_logs, msg_log, 1) else: - print(sdb_posts) - for item in sdb_posts: - - if os.path.exists('%s%s.conf'%(domain.domain_db, item)): - print("OK for",item) + for item, post in sdb_posts, posts_uri: + db_article = '%s%s.conf'%(domain.domain_db, item) + if os.path.exists(db_article): + print("OK for",item, post) + create_sdb_item(db_article) else: - print('Err for',item) - + msg_log = 'Sidebar > Article not yet ready: %s'%post + log.append_f(domain.tyto_logs, msg_log, 1) + + +#==========================================# +# Create HTML item in sidebar from article # +#------------------------------------------# +def create_sdb_item(db_article): + # Load DB for specific article + exec(open(db_article).read(),globals()) + + # Get article URL from filepath + post_short_uri = post_file.replace(domain.domain_articles, '/') + post_short_uri = post_short_uri.replace(".tyto", ".html") + # URL do not need /index.html + if post_short_uri.endswith('index.html'): + post_short_uri = post_short_uri.replace('index.html', '') + + # Article must have same hash from chk and wip + if not post_wip[0] == post_chk[0]: + print(':< Article has changed and needs to be checked first') + return(1) + + # Create sidebar.html + html.translations(post_date) + + sdb_html_item = '