diff --git a/CHANGELOG.md b/CHANGELOG.md index ed0fce2..57e5928 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/debian/control b/debian/control index 803bba9..0884438 100644 --- a/debian/control +++ b/debian/control @@ -1,5 +1,5 @@ Package: tyto -Version: 1.9.57 +Version: 1.9.58 Section: custom Priority: optional Architecture: all diff --git a/src/usr/bin/tyto b/src/usr/bin/tyto index 27938d1..648b617 100755 --- a/src/usr/bin/tyto +++ b/src/usr/bin/tyto @@ -1,5 +1,5 @@ #!/usr/bin/env python3 -# version: 1.9.57 +# version: 1.9.58 # Tyto - Littérateur # Copyright (C) 2023 Cyrille Louarn diff --git a/src/var/lib/tyto/program/args.py b/src/var/lib/tyto/program/args.py index f82fc20..f6b66db 100644 --- a/src/var/lib/tyto/program/args.py +++ b/src/var/lib/tyto/program/args.py @@ -50,6 +50,7 @@ def get_arguments(): "domain" : False, "sitemap" : False, "css" : False, + "--static": False, }, "modules" : { "modules" : False, diff --git a/src/var/lib/tyto/program/tools.py b/src/var/lib/tyto/program/tools.py index bfca103..5d5aeb4 100644 --- a/src/var/lib/tyto/program/tools.py +++ b/src/var/lib/tyto/program/tools.py @@ -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 : '', + 2 : '', + 3 : '', + 4 : '', + 5 : '', + } + + # 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) + + diff --git a/src/var/lib/tyto/program/wip.py b/src/var/lib/tyto/program/wip.py index 55e6cd5..69afa5f 100644 --- a/src/var/lib/tyto/program/wip.py +++ b/src/var/lib/tyto/program/wip.py @@ -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 @@ -779,8 +783,8 @@ def create_db(): post.cf_set("FILES", "file_%s"%nbr, post.datas["files"][nbr][1]) post.cf_write() - post.cf_load() - + post.cf_load() + #===============# # MAIN settings #==============================================================