[1.9.18] - image tag, value 2 uri check, fix domain conf file

This commit is contained in:
Cyrille L 2023-10-04 01:02:29 +02:00
parent ad632fc63d
commit cc0d43e4c9
8 changed files with 79 additions and 36 deletions

View File

@ -9,6 +9,13 @@ Tyto - Littérateur
# CURRENTLY IN DEV !
## [1.9.18]
- working on 'check' process
- - added image: tag
- - added value 2 (tag line 2) uri check (generic, root, post)
- - some corrections for domain config file
- - prepared html values for wip
## [1.9.17]
- working on 'check' process
- - dev on checking file used in some post header tags

View File

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

View File

@ -237,7 +237,6 @@ def is_valid_date(date):
# Written using 3 lines #
#----------------------------#
def ml_tags():
I_tag = post.ml_tags[1] # image:
R_tag = post.ml_tags[3] # raw:
C_tag = post.ml_tags[4] # code:
A_tag = post.ml_tags[5] # abbr:
@ -263,7 +262,13 @@ def ml_tags():
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
@ -276,6 +281,8 @@ def ml_tags():
# Return True/False (if no value) #
#----------------------------------------#
def ml_tag_values(ln, tag, stats):
global value2
# Get 3 lines values
value1 = headers[ln].rsplit(":")[1].lstrip()
value2 = headers[ln+1].lstrip()
@ -312,9 +319,7 @@ def ml_tag_values(ln, tag, stats):
return False
# Convert values to HTML (put in post database)
html_value = '<a href="%s" class="%s" target="%s" alt="%s">%s</a>'%(
value2, css, "%%s", value3, value1
)
link_var = "%s_%s"%(tag.replace(":", ""), stats)
html_var = "html_%s"%stats
@ -322,11 +327,23 @@ def ml_tag_values(ln, tag, stats):
if tag == post.ml_tags[0]:
section = "LINKS"
post.stats_text_links += post.text_contents.count(tyto_value)
html_value = '<a href="%s" class="%s" target="%s" alt="%s">%s</a>'%(
value2, css, "%%s", value3, value1
)
elif tag == post.ml_tags[2]:
section = "FILES"
post.stats_text_files += post.text_contents.count(tyto_value)
html_value = '<a href="%s" class="%s_file" target="%s" alt="%s">%s</a>'%(
value2, css, "%%s", value3, value1
)
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"
)
post.cf.set(section, link_var, tyto_value)
post.cf.set(section, html_var, html_value)
@ -341,34 +358,45 @@ def ml_tag_values(ln, tag, stats):
# - /... for root work directory #
# - ... for post directory #
#--------------------------------#
def is_value2_file_exists(ln, tag, value2):
def is_value2_file_exists(ln, tag, val2):
global value2
# uri "@..." means generic folders
if value2[0].startswith("@"):
# Set defaut directory for files in /files
wrk_df = domain.wrk_files
if val2[0].startswith("@"):
if val2[1] == "/": val2 = val2[2:]
else: val2 = val2[1:]
#Set directory for files
test_uri = os.path.join(domain.wrk_files + val2)
value2 = src_uri = os.path.join("/files", val2)
# Set directory for images in /images
if tag == post.ml_tags[1]: # image:
wrk_df = domain.wrk_images
value2 = value2[1:]
test_uri = os.path.join(domain.wrk_images, val2)
value2 = src_uri = os.path.join("/images", val2)
# uri "/..." means from wrk root folder
elif value2[0].startswith("/"):
wrk_df = domain.wrk_articles
value2 = value2[1:]
elif val2[0].startswith("/"):
val2 = val2[1:]
test_uri = os.path.join(domain.wrk_articles, val2)
src_uri = value2
# uri "..." means from legacy post folder
else:
wrk_df = os.path.dirname(post.uri) + "/"
test_uri = os.path.dirname(post.uri) + "/" + val2
value2 = "./" + val2
src_uri = test_uri.rsplit("articles/")[1]
# Check if file exists
file_uri = wrk_df + value2
if not os.path.exists(file_uri):
if not os.path.exists(test_uri):
post.error = \
debug.out(5, "%s) %s"%(ln, tag), file_uri, True, 2, False)
debug.out(5, "%s) %s"%(ln, tag), test_uri, True, 2, False)
return False
# Add file to [SOURCE_FILES] post database
post.stats_total_files += 1
post.cf.set("SOURCE_FILES", "file_%s"%post.stats_total_files, src_uri)
return True
@ -523,10 +551,10 @@ def cf_update_values():
post.cf.set("HEADERS", "tags", post.tags[1])
post.cf.set("HEADERS", "authors", post.author[1])
post.cf.set("HEADERS", "sitemap", str(sitemap))
post.cf.set("HEADERS", "static", str(domain.static))
post.cf.set("CHECK", "hash", post.wrk_id)
post.cf.set("CHECK", "date", chk_date)
post.cf.set("CHECK", "static", str(domain.static))
post.cf.set("WIP", "web", "%s%s"%(domain.wip_url, post.wrk_target))
post.cf.set("WIP", "uri", "%s%s"%(domain.wip, post.wrk_target))
@ -537,11 +565,13 @@ def cf_update_values():
stats_tyto_all_coms = post.stats_tyto_text_coms + post.stats_tyto_head_coms
post.cf.set("STATS_FILE", "lines", str(post.lines))
post.cf.set("STATS_FILE", "tyto_coms", str(stats_tyto_all_coms))
post.cf.set("STATS_FILE", "files", str(post.stats_total_files))
post.cf.set("STATS_HEADERS", "lines", str(post.head_lines))
post.cf.set("STATS_HEADERS", "tyto_coms", str(post.stats_tyto_head_coms))
post.cf.set("STATS_HEADERS", "links", str(post.stats_links))
post.cf.set("STATS_HEADERS", "files", str(post.stats_files))
post.cf.set("STATS_HEADERS", "tyto_coms", str(post.stats_tyto_head_coms))
post.cf.set("STATS_HEADERS", "images", str(post.stats_images))
post.cf.set("STATS_TEXTS", "lines", str(post.text_lines))
post.cf.set("STATS_TEXTS", "tyto_coms", str(post.stats_tyto_text_coms))
@ -549,6 +579,7 @@ def cf_update_values():
post.cf.set("STATS_TEXTS", "titles", str(post.stats_titles))
post.cf.set("STATS_TEXTS", "links", str(post.stats_text_links))
post.cf.set("STATS_TEXTS", "files", str(post.stats_text_files))
post.cf.set("STATS_TEXTS", "images", str(post.stats_text_images))
with open(post.cf_uri, "w") as f:
post.cf.write(f)

View File

@ -110,9 +110,9 @@ def cf_exists():
#=========================================#
# Guess and return www_url from name #
# Guess and return wip_url from name #
#-----------------------------------------#
def create_www_url():
def create_wip_url():
www_url = "https://www-wip.%s/"
len_cn = name.count(".")
@ -605,9 +605,9 @@ except:
# Domain Configuration directory
wrk_dir = user_dir.rsplit("articles/")[0]
wrk_articles = os.path.join(wrk_dir, "articles/")
wrk_images = os.path.join(wrk_dir, "articles/images/")
wrk_files = os.path.join(wrk_dir, "articles/files/")
wrk_tpl = os.path.join(wrk_dir, "template/")
wrk_images = os.path.join(wrk_dir, "images/")
wrk_files = os.path.join(wrk_dir, "files/")
wrk_mods = os.path.join(wrk_dir, "modules/")
wrk_db = os.path.join(wrk_dir, ".db/")

View File

@ -174,9 +174,10 @@ snpic = ("snpic:", False)
# Multiple lines (3)
ml_tags = ("link:", "image:", "file:", "raw:", "code:", "abbr:")
ml_marks = {
"link:" : "__",
"file:" : "--",
"abbr:" : "::"
"link:" : "__",
"file:" : "--",
"image:" : "_image:",
"abbr:" : "::"
}
# Markers with uri in value2
@ -223,8 +224,11 @@ stats_raws = 0
stats_codes = 0
stats_abbrs = 0
stats_text_links = 0
stats_text_files = 0
stats_total_files = 0
stats_text_links = 0
stats_text_files = 0
stats_text_images = 0
@ -236,11 +240,10 @@ ini_template = """[DOMAIN]
[FILE]
[HEADERS]
static =
snpic =
[CHECK]
static
static =
[WIP]
static =
@ -260,6 +263,8 @@ static =
[ABBRS]
[SOURCE_FILES]
[STATS_FILE]
[STATS_HEADERS]