[1.9.58] wip --static ('hidden' yet tool)
This commit is contained in:
parent
2f760d4d27
commit
bceb629467
|
@ -8,6 +8,10 @@ Tyto - Littérateur
|
||||||
|
|
||||||
# CURRENTLY IN DEV (in devel branch) !
|
# 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]
|
## [1.9.57]
|
||||||
- new "css" target.
|
- new "css" target.
|
||||||
- - With [help] : show references styles
|
- - With [help] : show references styles
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
Package: tyto
|
Package: tyto
|
||||||
Version: 1.9.57
|
Version: 1.9.58
|
||||||
Section: custom
|
Section: custom
|
||||||
Priority: optional
|
Priority: optional
|
||||||
Architecture: all
|
Architecture: all
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
# version: 1.9.57
|
# version: 1.9.58
|
||||||
# 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>
|
||||||
|
|
|
@ -50,6 +50,7 @@ def get_arguments():
|
||||||
"domain" : False,
|
"domain" : False,
|
||||||
"sitemap" : False,
|
"sitemap" : False,
|
||||||
"css" : False,
|
"css" : False,
|
||||||
|
"--static": False,
|
||||||
},
|
},
|
||||||
"modules" : {
|
"modules" : {
|
||||||
"modules" : False,
|
"modules" : False,
|
||||||
|
|
|
@ -234,3 +234,83 @@ def get_articles():
|
||||||
for uri in files:
|
for uri in files:
|
||||||
wip.article(uri.rsplit(root_dir)[1])
|
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)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -36,7 +36,11 @@ def manage():
|
||||||
domain.is_active()
|
domain.is_active()
|
||||||
|
|
||||||
# Multiple articles process
|
# Multiple articles process
|
||||||
if args.commands["targets"]["all"]:
|
if args.commands["targets"]["--static"]:
|
||||||
|
tools.make_static_site()
|
||||||
|
return
|
||||||
|
|
||||||
|
elif args.commands["targets"]["all"]:
|
||||||
articles()
|
articles()
|
||||||
|
|
||||||
# Treat target article
|
# Treat target article
|
||||||
|
|
Loading…
Reference in New Issue