[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 !
## [1.9.19]
- working on 'check' process
- - Added post 'logo: URI' (for social network share + opt show on page)
## [1.9.18]
- working on 'check' process
- - added image: tag

View File

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

View File

@ -58,8 +58,8 @@ def ready():
def manage(action, target):
# target is "all"
if args.targets:
multiple_targets
return
multiple_targets
return
# target is not "all"
ready()
@ -139,7 +139,7 @@ def multiple_targets():
# One Line needed tags #
#----------------------#
def ol_tags():
global sitemap
global sitemap, src_uri
sitemap = "True"
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]):
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):
sitemap = "False"
@ -179,7 +186,17 @@ def ol_tags():
if not is_ol_tag(post.about[0], post.about[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
# 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
@ -193,12 +210,12 @@ def ol_tag_value(line, commas):
# reformat comma separated items, removing first spaces
if commas:
tuple_values = value.rsplit(",")
value = ""
for i, item in enumerate(tuple_values):
value = value + item.strip()
if i != len(tuple_values) - 1:
value = value + ","
tuple_values = value.rsplit(",")
value = ""
for i, item in enumerate(tuple_values):
value = value + item.strip()
if i != len(tuple_values) - 1:
value = value + ","
return value
@ -209,8 +226,8 @@ def ol_tag_value(line, commas):
#---------------------------#
def is_ol_tag(tag, value):
if not value:
post.error = debug.out(51, "%s ?"%tag, post.uri, True, 2, False)
return False
post.error = debug.out(51, "%s ?"%tag, post.uri, True, 2, False)
return False
return True
@ -243,32 +260,32 @@ def ml_tags():
c = 0 # Continue for next x lines, as tags are 3 lines values
for ln, line in enumerate(headers):
if c != 0:
c -= 1
continue
if not line or line.isspace() or line.startswith("#"): continue
if line.startswith(post.ml_tags[0]):
post.stats_links += 1
if not ml_tag_values(ln, post.ml_tags[0], post.stats_links):
return False # value errors
c = 2 ; continue
elif line.startswith(post.ml_tags[2]):
post.stats_files += 1
if not ml_tag_values(ln, post.ml_tags[2], post.stats_files):
return False # value errors
c = 2 ; continue
elif line.startswith(post.ml_tags[1]):
post.stats_images += 1
if not ml_tag_values(ln, post.ml_tags[1], post.stats_images):
return False # value errors
c = 2 ; continue
if c != 0:
c -= 1
continue
if not line or line.isspace() or line.startswith("#"): continue
if line.startswith(post.ml_tags[0]):
post.stats_links += 1
if not ml_tag_values(ln, post.ml_tags[0], post.stats_links):
return False # value errors
c = 2 ; continue
elif line.startswith(post.ml_tags[2]):
post.stats_files += 1
if not ml_tag_values(ln, post.ml_tags[2], post.stats_files):
return False # value errors
c = 2 ; continue
elif line.startswith(post.ml_tags[1]):
post.stats_images += 1
if not ml_tag_values(ln, post.ml_tags[1], post.stats_images):
return False # value errors
c = 2 ; continue
return True
@ -319,8 +336,6 @@ def ml_tag_values(ln, tag, stats):
return False
# Convert values to HTML (put in post database)
link_var = "%s_%s"%(tag.replace(":", ""), stats)
html_var = "html_%s"%stats
@ -341,8 +356,8 @@ def ml_tag_values(ln, tag, stats):
elif tag == post.ml_tags[1]:
section = "IMAGES"
post.stats_text_images += post.text_contents.count(tyto_value)
html_value = '<a href="%s" class="%s_image" target="%s" alt="%s">%s</a>'%(
value2, css, "%%s", value3, "%%s"
html_value = '<a href="%s" class="%s" target="%s" alt="%s">%s</a>'%(
value2, "%%s", "%%s", value3, "%%s"
)
post.cf.set(section, link_var, tyto_value)
@ -359,7 +374,9 @@ def ml_tag_values(ln, tag, stats):
# - ... for post directory #
#--------------------------------#
def is_value2_file_exists(ln, tag, val2):
global value2
global value2, src_uri
print("check: val2", tag, val2)
# uri "@..." means generic folders
if val2[0].startswith("@"):
@ -371,7 +388,7 @@ def is_value2_file_exists(ln, tag, val2):
value2 = src_uri = os.path.join("/files", val2)
# 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)
value2 = src_uri = os.path.join("/images", val2)
@ -379,7 +396,7 @@ def is_value2_file_exists(ln, tag, val2):
elif val2[0].startswith("/"):
val2 = val2[1:]
test_uri = os.path.join(domain.wrk_articles, val2)
src_uri = value2
src_uri = val2
# uri "..." means from legacy post folder
else:
@ -434,62 +451,64 @@ def sl_paired(markers):
# Tag is opened
if line.startswith(tags[0]):
# Tag was already opened
if opened:
post.error = \
debug.out(53, "%s) %s ... %s"%(
ln+1,
tags[0], tags[1]
), post.uri, True, 2, False)
return False
# Tag was already opened
if opened:
post.error = \
debug.out(53, "%s) %s ... %s"%(
ln+1,
tags[0], tags[1]
), post.uri, True, 2, False)
return False
# check next line if exists or is a closed tag
try:
next_line = post.contents.rsplit("\n")[ln]
if next_line.startswith(tags[1]):
post.error = \
debug.out(55, "%s) '%s'"%(ln, tags[0]), post.uri, True, 2, False)
return False
except:
post.error = \
debug.out(55, "%s) '%s'"%(ln, tags[0]), post.uri, True, 2, False)
return False
# check next line if exists or is a closed tag
try:
next_line = post.contents.rsplit("\n")[ln]
if next_line.startswith(tags[1]):
post.error = \
debug.out(55, "%s) '%s'"%(ln, tags[0]), post.uri, True, 2, False)
return False
except:
post.error = \
debug.out(55, "%s) '%s'"%(ln, tags[0]), post.uri, True, 2, False)
return False
opened = in_tag = True
closed = False
stats_opened += 1
opened = in_tag = True
closed = False
stats_opened += 1
# Tag is closed
if line.startswith(tags[1]):
# Tag was already closed
if closed:
post.error = \
debug.out(53, "%s) %s ... %s"%(
ln+1,
tags[0], tags[1]
), post.uri, True, 2, False)
return False
# Tag was already closed
if closed:
post.error = \
debug.out(53, "%s) %s ... %s"%(
ln+1,
tags[0], tags[1]
), post.uri, True, 2, False)
return False
closed = True
opened = False
stats_closed += 1
closed = True
opened = False
stats_closed += 1
if in_tag:
# Contents must be indented
if not line.startswith(tags):
if len(line) - len(line.lstrip()) < 3:
post.error = \
debug.out(54, "%s) '\t'%s..."%(ln+1, line[0:10]), post.uri, True, 2, False)
return False
line = ""
# Contents must be indented
if not line.startswith(tags):
if len(line) - len(line.lstrip()) < 3:
post.error = \
debug.out(54, "%s) '\t'%s..."%(
ln+1, line[0:10]
), post.uri, True, 2, False)
return False
line = ""
# Create new string, removing in_tag line if in bcodes or quotes
if markers in post.raw_contents:
if not new_text_contents: new_text_contents = line
else: new_text_contents = "%s\n%s"%(new_text_contents, line)
if not new_text_contents: new_text_contents = line
else: new_text_contents = "%s\n%s"%(new_text_contents, line)
texts = new_text_contents.rsplit("\n")
texts = new_text_contents.rsplit("\n")
# Create post.stats
post.cf.set("STATS_TEXTS", markers, str(stats_opened))
@ -500,37 +519,47 @@ def sl_paired(markers):
#============================#
# Check optional title tags #
# Count tyto + html comments #
# Add stat for logo #
# Return True/False #
#----------------------------#
def titles():
for ln, line in enumerate(texts, post.head_lines + 1):
print(">>", ln, line)
for ln, line in enumerate(texts, post.head_lines + 1):
if not line or line.isspace(): continue
if not line or line.isspace(): continue
# legacy Tyto Titles
if line.startswith(post.tyto_titles):
if not line[3:]:
post.error = \
debug.out(52, "%s. %s ?"%(ln, line), post.uri, True, 2, False)
return False
# legacy Tyto Titles
if line.startswith(post.tyto_titles):
if not line[3:]:
post.error = \
debug.out(52, "%s. %s ?"%(ln, line), post.uri, True, 2, False)
return False
# Avoic wanting #6 - #9 (but accept #1x.. #5x.. as comments...)
elif line[1].isdigit() and int(line[1]) >= 6:
post.error = \
debug.out(52, "%s) %s..."%(ln, line[0:10]), post.uri, True, 1, False)
return False
# Avoic wanting #6 - #9 (but accept #1x.. #5x.. as comments...)
elif line[1].isdigit() and int(line[1]) >= 6:
post.error = \
debug.out(52, "%s) %s..."%(ln, line[0:10]), post.uri, True, 1, False)
return False
post.stats_titles += 1
post.stats_titles += 1
# Count Tyto Comments
elif line.startswith("#"):
post.stats_tyto_text_coms += 1
# Count Tyto Comments
elif line.lstrip().startswith("#"):
post.stats_tyto_text_coms += 1
# Count HTML comments
elif line.startswith(post.text_comments):
post.stats_html_coms += 1
# Count HTML comments
elif line.lstrip().startswith(post.text_comments):
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
@ -538,6 +567,8 @@ def titles():
# Update post configuration file #
#--------------------------------#
def cf_update_values():
post.date = ("date:", tools.local_date(post.date[1]))
post.cf.set("DOMAIN", "name", domain.name)
post.cf.set("FILE", "id", post.uri_id)

View File

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

View File

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

View File

@ -54,6 +54,25 @@ def nowdate():
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 #
# src: True = Content #