Whitelabel songbook websites

This commit is contained in:
Carlos Galindo 2025-04-04 17:41:14 +00:00
parent bc4e7ed51d
commit 103fb07630
9 changed files with 35 additions and 16 deletions

View file

@ -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

View file

@ -1,6 +1,6 @@
<footer>
<p>
&copy; 2023 Carlos Galindo, Parroquia San Leandro
&copy; {{ metadata.author }}
<a href="https://gitlab.com/parroquia-san-leandro/cancionero-web"><span>Código fuente</span></a>
</p>
</footer>

View file

@ -1,5 +1,5 @@
<meta charset="UTF-8">
<title>Cancionero - Parroquia San Leandro</title>
<title>{{ metadata.title }}</title>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<link rel="icon" type="image/svg+xml" href="{{ path|urlencode }}/favicon.svg"/>
<link rel="stylesheet" type="text/css" href="{{ path|urlencode }}/main.css"/>

View file

@ -1,5 +1,6 @@
<header>
<h1><a href="{{ path }}">Cancionero San Leandro</a></h1>
<h1><a href="{{ path }}">{{ metadata.title }}</a></h1>
{% if metadata.links %}
<nav class="nav">
<ul>
<li><a href="https://sanleandrovalencia.es/"><span id="nav-web">Parroquia San Leandro</span></a></li>
@ -7,4 +8,5 @@
<li><a href="https://sanleandrovalencia.es/cancionero/"><span>Cancionero en PDF</span></a></li>
</ul>
</nav>
{% endif %}
</header>

View file

@ -1,7 +1,7 @@
<!DOCTYPE html>
<html lang="es">
<head>
{% include "head.html" with path="." only %}
{% include "head.html" with path="." metadata=metadata only %}
<link rel="stylesheet" type="text/css" href="index.css"/>
</head>
<body>

View file

@ -1,7 +1,7 @@
<!DOCTYPE html>
<html lang="es">
<head>
{% include "head.html" with path=".." only %}
{% include "head.html" with path=".." metadata=metadata only %}
<link rel="stylesheet" type="text/css" href="../song.css"/>
<script async src="../song.js"></script>
</head>

View file

@ -1,7 +1,7 @@
<!DOCTYPE html>
<html lang="es">
<head>
{% include "head.html" with path=".." only %}
{% include "head.html" with path=".." metadata=metadata only %}
<meta http-equiv="refresh" content="0; url = ../{{ song.url|urlencode }}">
</head>
<body>

View file

@ -1,7 +1,7 @@
<!DOCTYPE html>
<html lang="en">
<head>
{% include "head.html" with path="." only %}
{% include "head.html" with path="." metadata=metadata only %}
<link rel="stylesheet" type="text/css" href="song.css"/>
<link rel="stylesheet" type="text/css" href="index.css"/>
<script async src="song.js"></script>

View file

@ -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"
})