[1.9.19] - 'check', added post logo set and configs
This commit is contained in:
parent
cc0d43e4c9
commit
9393bdc01a
|
@ -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
|
||||||
|
|
|
@ -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>
|
||||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -58,8 +58,8 @@ def ready():
|
||||||
def manage(action, target):
|
def manage(action, target):
|
||||||
# target is "all"
|
# target is "all"
|
||||||
if args.targets:
|
if args.targets:
|
||||||
multiple_targets
|
multiple_targets
|
||||||
return
|
return
|
||||||
|
|
||||||
# target is not "all"
|
# target is not "all"
|
||||||
ready()
|
ready()
|
||||||
|
@ -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
|
||||||
|
|
||||||
|
|
||||||
|
@ -193,12 +210,12 @@ def ol_tag_value(line, commas):
|
||||||
|
|
||||||
# reformat comma separated items, removing first spaces
|
# reformat comma separated items, removing first spaces
|
||||||
if commas:
|
if commas:
|
||||||
tuple_values = value.rsplit(",")
|
tuple_values = value.rsplit(",")
|
||||||
value = ""
|
value = ""
|
||||||
for i, item in enumerate(tuple_values):
|
for i, item in enumerate(tuple_values):
|
||||||
value = value + item.strip()
|
value = value + item.strip()
|
||||||
if i != len(tuple_values) - 1:
|
if i != len(tuple_values) - 1:
|
||||||
value = value + ","
|
value = value + ","
|
||||||
|
|
||||||
return value
|
return value
|
||||||
|
|
||||||
|
@ -209,8 +226,8 @@ def ol_tag_value(line, commas):
|
||||||
#---------------------------#
|
#---------------------------#
|
||||||
def is_ol_tag(tag, value):
|
def is_ol_tag(tag, value):
|
||||||
if not value:
|
if not value:
|
||||||
post.error = debug.out(51, "%s ?"%tag, post.uri, True, 2, False)
|
post.error = debug.out(51, "%s ?"%tag, post.uri, True, 2, False)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
@ -243,32 +260,32 @@ def ml_tags():
|
||||||
|
|
||||||
c = 0 # Continue for next x lines, as tags are 3 lines values
|
c = 0 # Continue for next x lines, as tags are 3 lines values
|
||||||
for ln, line in enumerate(headers):
|
for ln, line in enumerate(headers):
|
||||||
if c != 0:
|
if c != 0:
|
||||||
c -= 1
|
c -= 1
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if not line or line.isspace() or line.startswith("#"): continue
|
if not line or line.isspace() or line.startswith("#"): continue
|
||||||
|
|
||||||
if line.startswith(post.ml_tags[0]):
|
if line.startswith(post.ml_tags[0]):
|
||||||
post.stats_links += 1
|
post.stats_links += 1
|
||||||
if not ml_tag_values(ln, post.ml_tags[0], post.stats_links):
|
if not ml_tag_values(ln, post.ml_tags[0], post.stats_links):
|
||||||
return False # value errors
|
return False # value errors
|
||||||
|
|
||||||
c = 2 ; continue
|
c = 2 ; continue
|
||||||
|
|
||||||
elif line.startswith(post.ml_tags[2]):
|
elif line.startswith(post.ml_tags[2]):
|
||||||
post.stats_files += 1
|
post.stats_files += 1
|
||||||
if not ml_tag_values(ln, post.ml_tags[2], post.stats_files):
|
if not ml_tag_values(ln, post.ml_tags[2], post.stats_files):
|
||||||
return False # value errors
|
return False # value errors
|
||||||
|
|
||||||
c = 2 ; continue
|
c = 2 ; continue
|
||||||
|
|
||||||
elif line.startswith(post.ml_tags[1]):
|
elif line.startswith(post.ml_tags[1]):
|
||||||
post.stats_images += 1
|
post.stats_images += 1
|
||||||
if not ml_tag_values(ln, post.ml_tags[1], post.stats_images):
|
if not ml_tag_values(ln, post.ml_tags[1], post.stats_images):
|
||||||
return False # value errors
|
return False # value errors
|
||||||
|
|
||||||
c = 2 ; continue
|
c = 2 ; continue
|
||||||
|
|
||||||
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:
|
||||||
|
@ -434,62 +451,64 @@ def sl_paired(markers):
|
||||||
|
|
||||||
# Tag is opened
|
# Tag is opened
|
||||||
if line.startswith(tags[0]):
|
if line.startswith(tags[0]):
|
||||||
# Tag was already opened
|
# Tag was already opened
|
||||||
if 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 = \
|
post.error = \
|
||||||
debug.out(53, "%s) %s ... %s"%(
|
debug.out(55, "%s) '%s'"%(ln, tags[0]), post.uri, True, 2, False)
|
||||||
ln+1,
|
|
||||||
tags[0], tags[1]
|
|
||||||
), post.uri, True, 2, False)
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# check next line if exists or is a closed tag
|
opened = in_tag = True
|
||||||
try:
|
closed = False
|
||||||
next_line = post.contents.rsplit("\n")[ln]
|
stats_opened += 1
|
||||||
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
|
|
||||||
|
|
||||||
# Tag is closed
|
# Tag is closed
|
||||||
if line.startswith(tags[1]):
|
if line.startswith(tags[1]):
|
||||||
# Tag was already closed
|
# Tag was already closed
|
||||||
if closed:
|
if closed:
|
||||||
post.error = \
|
post.error = \
|
||||||
debug.out(53, "%s) %s ... %s"%(
|
debug.out(53, "%s) %s ... %s"%(
|
||||||
ln+1,
|
ln+1,
|
||||||
tags[0], tags[1]
|
tags[0], tags[1]
|
||||||
), post.uri, True, 2, False)
|
), post.uri, True, 2, False)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
closed = True
|
closed = True
|
||||||
opened = False
|
opened = False
|
||||||
stats_closed += 1
|
stats_closed += 1
|
||||||
|
|
||||||
|
|
||||||
if in_tag:
|
if in_tag:
|
||||||
# Contents must be indented
|
# Contents must be indented
|
||||||
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..."%(
|
||||||
return False
|
ln+1, line[0:10]
|
||||||
line = ""
|
), post.uri, True, 2, False)
|
||||||
|
return False
|
||||||
|
line = ""
|
||||||
|
|
||||||
# Create new string, removing in_tag line if in bcodes or quotes
|
# Create new string, removing in_tag line if in bcodes or quotes
|
||||||
if markers in post.raw_contents:
|
if markers in post.raw_contents:
|
||||||
if not new_text_contents: new_text_contents = line
|
if not new_text_contents: new_text_contents = line
|
||||||
else: new_text_contents = "%s\n%s"%(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
|
# Create post.stats
|
||||||
post.cf.set("STATS_TEXTS", markers, str(stats_opened))
|
post.cf.set("STATS_TEXTS", markers, str(stats_opened))
|
||||||
|
@ -500,36 +519,46 @@ 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
|
||||||
|
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
|
# Avoic wanting #6 - #9 (but accept #1x.. #5x.. as comments...)
|
||||||
if line.startswith(post.tyto_titles):
|
elif line[1].isdigit() and int(line[1]) >= 6:
|
||||||
if not line[3:]:
|
post.error = \
|
||||||
post.error = \
|
debug.out(52, "%s) %s..."%(ln, line[0:10]), post.uri, True, 1, False)
|
||||||
debug.out(52, "%s. %s ?"%(ln, line), post.uri, True, 2, False)
|
return False
|
||||||
return False
|
|
||||||
|
|
||||||
# Avoic wanting #6 - #9 (but accept #1x.. #5x.. as comments...)
|
post.stats_titles += 1
|
||||||
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
|
# Count Tyto Comments
|
||||||
|
elif line.lstrip().startswith("#"):
|
||||||
|
post.stats_tyto_text_coms += 1
|
||||||
|
|
||||||
# Count Tyto Comments
|
# Count HTML comments
|
||||||
elif line.startswith("#"):
|
elif line.lstrip().startswith(post.text_comments):
|
||||||
post.stats_tyto_text_coms += 1
|
post.stats_html_coms += 1
|
||||||
|
|
||||||
# Count HTML comments
|
# Add stat for [] when user wants to show logo in post
|
||||||
elif line.startswith(post.text_comments):
|
elif line.lstrip().startswith("_image:logo"):
|
||||||
post.stats_html_coms += 1
|
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)
|
||||||
|
|
|
@ -227,7 +227,7 @@ def cf_update_values(write):
|
||||||
|
|
||||||
cf_set_value("DOMAIN", "name", name)
|
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")
|
date = cf_set_value("DOMAIN", "date", "date")
|
||||||
about = cf_set_value("DOMAIN", "about", "about")
|
about = cf_set_value("DOMAIN", "about", "about")
|
||||||
mail = cf_set_value("DOMAIN", "mail", "mail")
|
mail = cf_set_value("DOMAIN", "mail", "mail")
|
||||||
|
@ -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")
|
||||||
|
|
|
@ -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]
|
||||||
|
|
||||||
|
|
|
@ -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 #
|
||||||
|
|
Loading…
Reference in New Issue