html: in-dev of sidebar fonction : create sidebar.html in wip/template

This commit is contained in:
Cyrille L 2022-11-30 16:52:47 +01:00
parent 619ca17c10
commit aaf689a4fe
2 changed files with 74 additions and 14 deletions

View File

@ -45,9 +45,9 @@ trans = [
# Translations terms # # Translations terms #
# Only FR (default) and Other (english) # # Only FR (default) and Other (english) #
#---------------------------------------# #---------------------------------------#
def translations(): def translations(post_date):
global fl # fl = field lang global fl # fl = field lang
global post_date global sdb_date
# Default FR/fr # Default FR/fr
if re.match('fr', domain.domain_lang, re.IGNORECASE): fl = 0 if re.match('fr', domain.domain_lang, re.IGNORECASE): fl = 0
@ -57,6 +57,7 @@ def translations():
if fl == 0: if fl == 0:
fr_date = post_date.rsplit('-') fr_date = post_date.rsplit('-')
post_date = fr_date[2] + '/' + fr_date[1] + '/' + fr_date[0] post_date = fr_date[2] + '/' + fr_date[1] + '/' + fr_date[0]
sdb_date = post_date
#========================# #========================#
# Create FULL HTML5 Page # # Create FULL HTML5 Page #
@ -99,7 +100,7 @@ def html_main_page(wip_html):
log.append_f(check.post_logs, msg_log, 1) log.append_f(check.post_logs, msg_log, 1)
# Set some terms from lang domain # Set some terms from lang domain
translations() translations(post_date)
# External URL in metas (if exists in config domain) # External URL in metas (if exists in config domain)
if domain.domain_exturl: if domain.domain_exturl:

View File

@ -18,7 +18,9 @@
#********************************************************************** #**********************************************************************
import re, os, sys, subprocess 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 # # Manage sidebar command #
@ -52,17 +54,20 @@ def manage_sidebar(article, Opt):
#------------------------# #------------------------#
def loop_sidebar(create): def loop_sidebar(create):
Post_Err = False Post_Err = False
sdb_posts = [] sdb_posts = posts_uri = []
max_items = int(domain.domain_sdb_items) + 1 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() sdb_loaded = (open(domain.domain_sdb_load)).read()
for line in sdb_loaded.rsplit('\n'): for line in sdb_loaded.rsplit('\n'):
if create : print(line) if create : print(line)
elif line.startswith('#'): continue elif line.startswith('#'): continue
elif len(line) == 0 : continue elif len(line) == 0 : continue
else: 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) post_uri = '%s%s'%(domain.domain_articles, line)
posts_uri = posts_uri + [post_uri]
if not os.path.exists(post_uri): if not os.path.exists(post_uri):
print(':< From URI: %s. Unused file: %s'%(line, post_uri)) print(':< From URI: %s. Unused file: %s'%(line, post_uri))
Post_Err = True Post_Err = True
@ -76,16 +81,69 @@ def loop_sidebar(create):
msg_log = 'Sidebar > Not created. Mismatch some article\'s URI' msg_log = 'Sidebar > Not created. Mismatch some article\'s URI'
log.append_f(domain.tyto_logs, msg_log, 1) log.append_f(domain.tyto_logs, msg_log, 1)
else: else:
print(sdb_posts) for item, post in sdb_posts, posts_uri:
for item in sdb_posts: db_article = '%s%s.conf'%(domain.domain_db, item)
if os.path.exists(db_article):
if os.path.exists('%s%s.conf'%(domain.domain_db, item)): print("OK for",item, post)
print("OK for",item) create_sdb_item(db_article)
else: 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 = '<li class="sidebar-item">\n' + \
' <a href="%s"\n'%post_short_uri + \
' class="sidebar-post-link"\n' + \
' title="%s">\n'%post_title + \
' <p class="sidebar-item_title">\n' + \
' %s\n'%post_title + \
' </p>\n' + \
' <p class="sidebar-post-metas">\n' + \
' <span id="%s"\n'%post_author + \
' title="%s %s %s">%s %s</span>\n'%(
post_author, html.trans[13][html.fl], post_title,
html.trans[9][html.fl], post_author
) + \
' <span id="sep">, %s</span>\n'%html.trans[10][html.fl] + \
' <span id="date">%s</span>\n'%html.sdb_date + \
' </p>\n' + \
' <p class="sidebar-post-about">\n' + \
' %s\n'%post_about + \
' </p>\n' + \
' </a>\n' + \
'</li>'
with open(sidebar_file, 'w') as file:
for line in sdb_html_item.rsplit('\n'):
file.write('%s%s\n'%(8*' ', line))
#=====================# #=====================#
# Create sidebar file # # Create sidebar file #
# from choosen lang #
#---------------------# #---------------------#
def create_sdb_load(): def create_sdb_load():
sdb_file_fr = '# Nom: Tyto - Littérateur\n' + \ sdb_file_fr = '# Nom: Tyto - Littérateur\n' + \
@ -126,3 +184,4 @@ def create_sdb_load():
domain.domain_sdb_load domain.domain_sdb_load
) )
log.append_f(domain.tyto_logs, msg_log, 0) log.append_f(domain.tyto_logs, msg_log, 0)