[1.9.58] wip --static ('hidden' yet tool)

This commit is contained in:
Cyrille L 2024-01-03 17:16:42 +01:00
parent 2f760d4d27
commit bceb629467
6 changed files with 94 additions and 5 deletions

View File

@ -8,6 +8,10 @@ Tyto - Littérateur
# CURRENTLY IN DEV (in devel branch) !
## [1.9.58]
- added [wip --static] to create static/ website server ('hidden' tool)
- - replace nginx comments modules call with contents modules in articles
## [1.9.57]
- new "css" target.
- - With [help] : show references styles

2
debian/control vendored
View File

@ -1,5 +1,5 @@
Package: tyto
Version: 1.9.57
Version: 1.9.58
Section: custom
Priority: optional
Architecture: all

View File

@ -1,5 +1,5 @@
#!/usr/bin/env python3
# version: 1.9.57
# version: 1.9.58
# Tyto - Littérateur
# Copyright (C) 2023 Cyrille Louarn <echolib+tyto@a-lec.org>

View File

@ -50,6 +50,7 @@ def get_arguments():
"domain" : False,
"sitemap" : False,
"css" : False,
"--static": False,
},
"modules" : {
"modules" : False,

View File

@ -234,3 +234,83 @@ def get_articles():
for uri in files:
wip.article(uri.rsplit(root_dir)[1])
#===========================================================#
# An "hidden" function to create static site in wip/ server #
# Copy current wip/ server to /static/ #
# Replace (nginx) modules comments with their contents #
#-----------------------------------------------------------#
def make_static_site():
srv_static_dir = domain.srv_domain + "static/"
# Clean static directory
if os.path.exists(srv_static_dir):
shutil.rmtree(srv_static_dir)
print("! Cleaned:", srv_static_dir)
try:
shutil.copytree(domain.wip, srv_static_dir, dirs_exist_ok=True)
print("+ Copytree wip/ to static/ server")
except:
return
# Set forbidden directories
nopaths = (
srv_static_dir + "files/",
srv_static_dir + "images",
srv_static_dir + "template",
)
srv_static_tpl = srv_static_dir + "template/"
modules_cont = \
{
1 : open(srv_static_tpl + "metas.html", "r"),
2 : open(srv_static_tpl + "header.html", "r"),
3 : open(srv_static_tpl + "navbar.html", "r"),
4 : open(srv_static_tpl + "sidebar.html", "r"),
5 : open(srv_static_tpl + "footer.html", "r"),
}
for mod in modules_cont:
modules_cont[mod] = modules_cont[mod].read()
modules_line = \
{
1 : '<!--# include virtual="/template/metas.html"-->',
2 : '<!--# include virtual="/template/header.html"-->',
3 : '<!--# include virtual="/template/navbar.html"-->',
4 : '<!--# include virtual="/template/sidebar.html"-->',
5 : '<!--# include virtual="/template/footer.html"-->',
}
# Get .html files
files = filter(os.path.isfile,
glob.glob(srv_static_dir + '**/*.html', recursive=True)
)
for post_uri in files:
if post_uri.startswith(nopaths):
continue
with open(post_uri, "r") as f:
wip_article = False
print("> Contents modules added", post_uri)
article = f.read().rsplit("\n")
for ln, line in enumerate(article):
if ln == 0 and line.endswith("Littérateur) -->"):
wip_article = True
break
if wip_article:
for mod in modules_line:
for ln, line in enumerate(article):
if line == modules_line[mod]:
article[ln] = modules_cont[mod]
with open(post_uri, 'w') as f:
for line in article:
# write each item on a new line
f.write("%s\n"%line)

View File

@ -36,7 +36,11 @@ def manage():
domain.is_active()
# Multiple articles process
if args.commands["targets"]["all"]:
if args.commands["targets"]["--static"]:
tools.make_static_site()
return
elif args.commands["targets"]["all"]:
articles()
# Treat target article