From 103fb07630fd9269bc0960e883e6463f4144b49b Mon Sep 17 00:00:00 2001 From: Carlos Galindo Date: Fri, 4 Apr 2025 17:41:14 +0000 Subject: [PATCH] Whitelabel songbook websites --- Makefile | 12 +++++++++++- res/templates/footer.html | 2 +- res/templates/head.html | 2 +- res/templates/header.html | 4 +++- res/templates/index.html | 2 +- res/templates/song.html | 2 +- res/templates/song_redir.html | 2 +- res/templates/songbook.html | 2 +- src/latex_scanner.py | 23 +++++++++++++++-------- 9 files changed, 35 insertions(+), 16 deletions(-) diff --git a/Makefile b/Makefile index dd4d579..55b676f 100644 --- a/Makefile +++ b/Makefile @@ -5,6 +5,10 @@ ALL_LESS := public/main.css public/index.css public/song.css ALL_TEMPLATES := $(wildcard res/templates/*.html) PY_SRC := $(wildcard src/**.py) +NAME ?= Cancionero San Leandro +AUTHOR ?= 2025 Carlos Galindo, Parroquia San Leandro +SLO_LINKS ?= false + all: public public/audios public/index.html static @@ -14,7 +18,13 @@ public: mkdir public public/index.html: $(ALL_TEMPLATES) $(PY_SRC) - python3 src/latex_scanner.py --latex latex/cancionero.tex --audios audios --other-latex latex/canciones/ + python3 src/latex_scanner.py \ + --latex latex/cancionero.tex \ + --audios audios \ + --other-latex latex/canciones/ \ + --title $(NAME) \ + --author $(AUTHOR) \ + --links $(SLO_LINKS) public/audios: audios public rm -f public/audios diff --git a/res/templates/footer.html b/res/templates/footer.html index 6d21935..0394098 100644 --- a/res/templates/footer.html +++ b/res/templates/footer.html @@ -1,6 +1,6 @@ diff --git a/res/templates/head.html b/res/templates/head.html index b2b1f0a..0d98673 100644 --- a/res/templates/head.html +++ b/res/templates/head.html @@ -1,5 +1,5 @@ -Cancionero - Parroquia San Leandro +{{ metadata.title }} diff --git a/res/templates/header.html b/res/templates/header.html index 41d48b1..4aa7767 100644 --- a/res/templates/header.html +++ b/res/templates/header.html @@ -1,5 +1,6 @@
-

Cancionero San Leandro

+

{{ metadata.title }}

+ {% if metadata.links %} + {% endif %}
diff --git a/res/templates/index.html b/res/templates/index.html index f791c25..342d4b6 100644 --- a/res/templates/index.html +++ b/res/templates/index.html @@ -1,7 +1,7 @@ - {% include "head.html" with path="." only %} + {% include "head.html" with path="." metadata=metadata only %} diff --git a/res/templates/song.html b/res/templates/song.html index 8b79de9..9cfac8c 100644 --- a/res/templates/song.html +++ b/res/templates/song.html @@ -1,7 +1,7 @@ - {% include "head.html" with path=".." only %} + {% include "head.html" with path=".." metadata=metadata only %} diff --git a/res/templates/song_redir.html b/res/templates/song_redir.html index 1024dce..500f87b 100644 --- a/res/templates/song_redir.html +++ b/res/templates/song_redir.html @@ -1,7 +1,7 @@ - {% include "head.html" with path=".." only %} + {% include "head.html" with path=".." metadata=metadata only %} diff --git a/res/templates/songbook.html b/res/templates/songbook.html index 0c423ff..154bcf9 100644 --- a/res/templates/songbook.html +++ b/res/templates/songbook.html @@ -1,7 +1,7 @@ - {% include "head.html" with path="." only %} + {% include "head.html" with path="." metadata=metadata only %} diff --git a/src/latex_scanner.py b/src/latex_scanner.py index 41926b4..47c03f9 100644 --- a/src/latex_scanner.py +++ b/src/latex_scanner.py @@ -288,15 +288,15 @@ class SongLoader: key=lambda s: s.number) return result - def print_index(self, index_file, dj_engine): - context = Context({'sorted_categories': self.sort_categories()}) + def print_index(self, index_file, dj_engine, metadata): + context = Context(dict({'sorted_categories': self.sort_categories()}, **metadata)) html = dj_engine.get_template("index.html").render(context) with open(index_file, 'w') as f: f.write(html) @staticmethod - def print_song(song, directory, dj_engine): - context = Context({'song': song}) + def print_song(song, directory, dj_engine, metadata): + context = Context(dict({'song': song}, **metadata)) num_dir = join(directory, "%03d" % song.number) mkdir(num_dir) with open(join(num_dir, "index.html"), 'w') as f: @@ -306,11 +306,11 @@ class SongLoader: with open(join(song_dir, "index.html"), 'w') as f: f.write(dj_engine.get_template("song.html").render(context)) - def generate_html(self, output_dir, dj_engine): + def generate_html(self, output_dir, dj_engine, metadata): mkdir(output_dir) for song in self.songs: - self.print_song(song, output_dir, dj_engine) - self.print_index(join(output_dir, "index.html"), dj_engine) + self.print_song(song, output_dir, dj_engine, metadata) + self.print_index(join(output_dir, "index.html"), dj_engine, metadata) def create_argparser(): @@ -323,6 +323,9 @@ def create_argparser(): parser.add_argument("--audios", required=False, nargs=1, default=[None], help="The folder containing the audio files.") parser.add_argument("--output-dir", required=False, nargs=1, default=["public"]) + parser.add_argument("--title", required=True, nargs=1, help="The title of the webpage") + parser.add_argument("--author", required=True, nargs=1, help="The author for the footer") + parser.add_argument("--links", required=False, nargs=1, default=["false"]) return parser @@ -333,4 +336,8 @@ if __name__ == '__main__': loader.scan_others(args.other_latex[0], int(args.other_index[0])) settings.configure(USE_TZ=False, USE_I18N=False) e = Engine(dirs=["res/templates/"]) - loader.generate_html(args.output_dir[0], e) + loader.generate_html(args.output_dir[0], e, { + 'title': args.title[0], + 'author': args.author[0], + 'links': args.links[0] == "true" + })