[1.9.19] - 'check', added post logo set and configs

This commit is contained in:
Cyrille L 2023-10-05 16:44:06 +02:00
parent cc0d43e4c9
commit 9393bdc01a
10 changed files with 169 additions and 120 deletions

View File

@ -9,6 +9,10 @@ Tyto - Littérateur
# CURRENTLY IN DEV ! # CURRENTLY IN DEV !
## [1.9.19]
- working on 'check' process
- - Added post 'logo: URI' (for social network share + opt show on page)
## [1.9.18] ## [1.9.18]
- working on 'check' process - working on 'check' process
- - added image: tag - - added image: tag

View File

@ -1,6 +1,6 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
# Version: 1.9.18 # Version: 1.9.19
# Updated: 2023-10-04 1696374079 # Updated: 2023-10-05 1696512944
# Tyto - Littérateur # Tyto - Littérateur
# Copyright (C) 2023 Cyrille Louarn <echolib+tyto@a-lec.org> # Copyright (C) 2023 Cyrille Louarn <echolib+tyto@a-lec.org>

View File

@ -139,7 +139,7 @@ def multiple_targets():
# One Line needed tags # # One Line needed tags #
#----------------------# #----------------------#
def ol_tags(): def ol_tags():
global sitemap global sitemap, src_uri
sitemap = "True" sitemap = "True"
for ln, line in enumerate(headers, 1): for ln, line in enumerate(headers, 1):
@ -166,6 +166,13 @@ def ol_tags():
elif not post.tags[1] and line.startswith(post.tags[0]): elif not post.tags[1] and line.startswith(post.tags[0]):
post.tags = (post.tags[0], ol_tag_value(line, True)) post.tags = (post.tags[0], ol_tag_value(line, True))
# Optional tags
# -------------
elif not post.logo[1] and line.startswith(post.logo[0]):
post.logo = (post.logo[0], ol_tag_value(line, False))
logo_ln = ln
elif line.startswith(post.nositemap): elif line.startswith(post.nositemap):
sitemap = "False" sitemap = "False"
@ -180,6 +187,16 @@ def ol_tags():
if not is_ol_tag(post.author[0], post.author[1]): return False if not is_ol_tag(post.author[0], post.author[1]): return False
if not is_ol_tag(post.tags[0], post.tags[1]): return False if not is_ol_tag(post.tags[0], post.tags[1]): return False
# Default domain logo for this post
src_uri = "%stemplate/%s"%(domain.www_url, domain.logo)
# logo is set with specific uri
if is_value2_file_exists(logo_ln, "logo:", post.logo[1]):
src_uri = "%s%s"%(domain.www_url, src_uri)
else:
return False
post.logo = (post.logo[0], src_uri)
post.cf.set("HEADERS", "logo", src_uri)
return True return True
@ -319,8 +336,6 @@ def ml_tag_values(ln, tag, stats):
return False return False
# Convert values to HTML (put in post database) # Convert values to HTML (put in post database)
link_var = "%s_%s"%(tag.replace(":", ""), stats) link_var = "%s_%s"%(tag.replace(":", ""), stats)
html_var = "html_%s"%stats html_var = "html_%s"%stats
@ -341,8 +356,8 @@ def ml_tag_values(ln, tag, stats):
elif tag == post.ml_tags[1]: elif tag == post.ml_tags[1]:
section = "IMAGES" section = "IMAGES"
post.stats_text_images += post.text_contents.count(tyto_value) post.stats_text_images += post.text_contents.count(tyto_value)
html_value = '<a href="%s" class="%s_image" target="%s" alt="%s">%s</a>'%( html_value = '<a href="%s" class="%s" target="%s" alt="%s">%s</a>'%(
value2, css, "%%s", value3, "%%s" value2, "%%s", "%%s", value3, "%%s"
) )
post.cf.set(section, link_var, tyto_value) post.cf.set(section, link_var, tyto_value)
@ -359,7 +374,9 @@ def ml_tag_values(ln, tag, stats):
# - ... for post directory # # - ... for post directory #
#--------------------------------# #--------------------------------#
def is_value2_file_exists(ln, tag, val2): def is_value2_file_exists(ln, tag, val2):
global value2 global value2, src_uri
print("check: val2", tag, val2)
# uri "@..." means generic folders # uri "@..." means generic folders
if val2[0].startswith("@"): if val2[0].startswith("@"):
@ -371,7 +388,7 @@ def is_value2_file_exists(ln, tag, val2):
value2 = src_uri = os.path.join("/files", val2) value2 = src_uri = os.path.join("/files", val2)
# Set directory for images in /images # Set directory for images in /images
if tag == post.ml_tags[1]: # image: if tag == post.ml_tags[1] or tag == post.logo[0]: # image:
test_uri = os.path.join(domain.wrk_images, val2) test_uri = os.path.join(domain.wrk_images, val2)
value2 = src_uri = os.path.join("/images", val2) value2 = src_uri = os.path.join("/images", val2)
@ -379,7 +396,7 @@ def is_value2_file_exists(ln, tag, val2):
elif val2[0].startswith("/"): elif val2[0].startswith("/"):
val2 = val2[1:] val2 = val2[1:]
test_uri = os.path.join(domain.wrk_articles, val2) test_uri = os.path.join(domain.wrk_articles, val2)
src_uri = value2 src_uri = val2
# uri "..." means from legacy post folder # uri "..." means from legacy post folder
else: else:
@ -480,7 +497,9 @@ def sl_paired(markers):
if not line.startswith(tags): if not line.startswith(tags):
if len(line) - len(line.lstrip()) < 3: if len(line) - len(line.lstrip()) < 3:
post.error = \ post.error = \
debug.out(54, "%s) '\t'%s..."%(ln+1, line[0:10]), post.uri, True, 2, False) debug.out(54, "%s) '\t'%s..."%(
ln+1, line[0:10]
), post.uri, True, 2, False)
return False return False
line = "" line = ""
@ -500,12 +519,11 @@ def sl_paired(markers):
#============================# #============================#
# Check optional title tags # # Check optional title tags #
# Count tyto + html comments # # Count tyto + html comments #
# Add stat for logo #
# Return True/False # # Return True/False #
#----------------------------# #----------------------------#
def titles(): def titles():
for ln, line in enumerate(texts, post.head_lines + 1): for ln, line in enumerate(texts, post.head_lines + 1):
print(">>", ln, line)
if not line or line.isspace(): continue if not line or line.isspace(): continue
# legacy Tyto Titles # legacy Tyto Titles
@ -524,13 +542,24 @@ def titles():
post.stats_titles += 1 post.stats_titles += 1
# Count Tyto Comments # Count Tyto Comments
elif line.startswith("#"): elif line.lstrip().startswith("#"):
post.stats_tyto_text_coms += 1 post.stats_tyto_text_coms += 1
# Count HTML comments # Count HTML comments
elif line.startswith(post.text_comments): elif line.lstrip().startswith(post.text_comments):
post.stats_html_coms += 1 post.stats_html_coms += 1
# Add stat for [] when user wants to show logo in post
elif line.lstrip().startswith("_image:logo"):
post.stats_text_images += 1
link_var = "image_%s"%(post.stats_images+1)
link_val = "_image:logo"
html_var = "html_%s"%(post.stats_images+1)
html_val = '<a href="%s" class="%s" target="%s" alt="%s">%s</a>'%(
post.logo[1], "%%s", "%%s", post.title[1], "%%s")
post.cf.set("IMAGES", link_var, link_val)
post.cf.set("IMAGES", html_var, html_val)
return True return True
@ -538,6 +567,8 @@ def titles():
# Update post configuration file # # Update post configuration file #
#--------------------------------# #--------------------------------#
def cf_update_values(): def cf_update_values():
post.date = ("date:", tools.local_date(post.date[1]))
post.cf.set("DOMAIN", "name", domain.name) post.cf.set("DOMAIN", "name", domain.name)
post.cf.set("FILE", "id", post.uri_id) post.cf.set("FILE", "id", post.uri_id)

View File

@ -347,6 +347,7 @@ def cf_update_values(write):
# TEMPLATE_FILENAMES # TEMPLATE_FILENAMES
# ================== # ==================
global favicon, logo, styles, rss, stats
favicon = cf_set_value("TEMPLATE_FILENAMES", "favicon", "") favicon = cf_set_value("TEMPLATE_FILENAMES", "favicon", "")
if not favicon: if not favicon:
favicon = cf_set_value("TEMPLATE_FILENAMES", "favicon", "favicon.png") favicon = cf_set_value("TEMPLATE_FILENAMES", "favicon", "favicon.png")

View File

@ -146,8 +146,6 @@ def cf_valid():
wip_hash = cf.get("WIP", "hash") wip_hash = cf.get("WIP", "hash")
www_hash = cf.get("WWW", "hash") www_hash = cf.get("WWW", "hash")
print("post: chk_hash", chk_hash)
#======# #======#
# MAIN #======================================================================= # MAIN #=======================================================================
@ -169,7 +167,7 @@ date = ("date:", False)
tags = ("tags:", False) tags = ("tags:", False)
author = ("author:", False) author = ("author:", False)
# optional # optional
snpic = ("snpic:", False) logo = ("logo:", False)
# Multiple lines (3) # Multiple lines (3)
ml_tags = ("link:", "image:", "file:", "raw:", "code:", "abbr:") ml_tags = ("link:", "image:", "file:", "raw:", "code:", "abbr:")
@ -240,16 +238,12 @@ ini_template = """[DOMAIN]
[FILE] [FILE]
[HEADERS] [HEADERS]
snpic =
[CHECK] [CHECK]
static =
[WIP] [WIP]
static =
[WWW] [WWW]
static =
[LINKS] [LINKS]

View File

@ -54,6 +54,25 @@ def nowdate():
return(now.strftime('%Y-%m-%d %H:%M:%S')) return(now.strftime('%Y-%m-%d %H:%M:%S'))
#
# convert int date to local date
# Return date (only year) for post database
#
def local_date(date):
date = date.rsplit(" ")[0] # if nowdate()
year = date.rsplit("-")[0]
month = date.rsplit("-")[1]
day = date.rsplit("-")[2]
dates = {
"fr" : "%s/%s/%s"%(day, month, year),
"en" : date,
}
return dates[domain.lang]
#========================# #========================#
# Return sum of src file # # Return sum of src file #
# src: True = Content # # src: True = Content #