From 3eaed2eaa8aca0b872aad4d8637eb8af680a1997 Mon Sep 17 00:00:00 2001 From: Carlos Galindo Date: Fri, 25 Dec 2020 21:49:59 +0100 Subject: [PATCH] Add categories and favicon * Reorganize resource directories (templates, less, static) * Show categories on index * Add favicon --- Makefile | 25 +++---- res/html/index.html | 25 ------- res/{ => less}/colors.less | 0 res/{ => less}/index.less | 8 +++ res/{ => less}/main.less | 0 res/{ => less}/song.less | 0 res/static/favicon.svg | 89 +++++++++++++++++++++++++ res/{ => static}/repeat-sign.svg | 0 res/{ => static}/sizes.js | 0 res/{ => static}/transpose.js | 7 +- res/{html => templates}/footer.html | 0 res/{html => templates}/head.html | 5 +- res/{html => templates}/header.html | 0 res/templates/index.html | 35 ++++++++++ res/{html => templates}/song.html | 34 +++++----- res/{html => templates}/song_redir.html | 0 src/latex_scanner.py | 16 +++-- 17 files changed, 180 insertions(+), 64 deletions(-) delete mode 100644 res/html/index.html rename res/{ => less}/colors.less (100%) rename res/{ => less}/index.less (88%) rename res/{ => less}/main.less (100%) rename res/{ => less}/song.less (100%) create mode 100644 res/static/favicon.svg rename res/{ => static}/repeat-sign.svg (100%) rename res/{ => static}/sizes.js (100%) rename res/{ => static}/transpose.js (90%) rename res/{html => templates}/footer.html (100%) rename res/{html => templates}/head.html (77%) rename res/{html => templates}/header.html (100%) create mode 100644 res/templates/index.html rename res/{html => templates}/song.html (81%) rename res/{html => templates}/song_redir.html (100%) diff --git a/Makefile b/Makefile index e63cb59..7c3713f 100644 --- a/Makefile +++ b/Makefile @@ -1,34 +1,29 @@ -.PHONY=static all clean svg js css +.PHONY=static all clean -ALL_CSS := $(patsubst res/%.less,public/%.css,$(wildcard res/*.less)) -ALL_JS := $(patsubst res/%.js,public/%.js,$(wildcard res/*.js)) -ALL_SVG := $(patsubst res/%.svg,public/%.svg,$(wildcard res/*.svg)) -ALL_TEMPLATES := $(wildcard res/html/*.html) +ALL_STATIC := $(patsubst res/static/%,public/%,$(wildcard res/static/*)) +ALL_LESS := $(patsubst res/less/%.less,public/%.css,$(wildcard res/less/*.less)) +ALL_TEMPLATES := $(wildcard res/templates/*.html) +PY_SRC := $(wildcard src/**.py) -all: public/index.html -static: css js svg +all: public public/audios public/index.html static -css: $(ALL_CSS) - -js: $(ALL_JS) - -svg: $(ALL_SVG) +static: $(ALL_LESS) $(ALL_STATIC) public: mkdir public -public/index.html: static public public/audios $(ALL_TEMPLATES) +public/index.html: $(ALL_TEMPLATES) $(PY_SRC) python3 src/latex_scanner.py --latex latex/cancionero.tex --audios audios public/audios: audios public rm -f public/audios ln -s ../audios public/audios -public/%.css: res/%.less +public/%.css: res/less/%.less lessc $< $@ -public/%: res/% +public/%: res/static/% cp $< $@ clean: diff --git a/res/html/index.html b/res/html/index.html deleted file mode 100644 index 7915f53..0000000 --- a/res/html/index.html +++ /dev/null @@ -1,25 +0,0 @@ - - - - {% include "head.html" with path="." only %} - - - - {% include "header.html" with path="." %} -

Índice

- Las canciones sin acordes están marcadas en rojo. -
    - {% for song in songs %} - -
  1. - {{ song.number }}. - {{ song.name }} - {% if song.author %} por {{ song.author }} {% endif %} - {% if song.origin %} basado en {{ song.origin }} {% endif %} -
  2. -
    - {% endfor %} -
- {% include "footer.html" %} - - \ No newline at end of file diff --git a/res/colors.less b/res/less/colors.less similarity index 100% rename from res/colors.less rename to res/less/colors.less diff --git a/res/index.less b/res/less/index.less similarity index 88% rename from res/index.less rename to res/less/index.less index 97775dc..b0ff5ac 100644 --- a/res/index.less +++ b/res/less/index.less @@ -30,6 +30,14 @@ } } } +ul.songs { + width: 100%; + margin: 1em auto; + li { + display: inline-block; + margin: .2em; + } +} span.noChords { background-color: @nochordscolor; padding: 0.3em 0.4em; diff --git a/res/main.less b/res/less/main.less similarity index 100% rename from res/main.less rename to res/less/main.less diff --git a/res/song.less b/res/less/song.less similarity index 100% rename from res/song.less rename to res/less/song.less diff --git a/res/static/favicon.svg b/res/static/favicon.svg new file mode 100644 index 0000000..64660f1 --- /dev/null +++ b/res/static/favicon.svg @@ -0,0 +1,89 @@ + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + diff --git a/res/repeat-sign.svg b/res/static/repeat-sign.svg similarity index 100% rename from res/repeat-sign.svg rename to res/static/repeat-sign.svg diff --git a/res/sizes.js b/res/static/sizes.js similarity index 100% rename from res/sizes.js rename to res/static/sizes.js diff --git a/res/transpose.js b/res/static/transpose.js similarity index 90% rename from res/transpose.js rename to res/static/transpose.js index 1f295db..b694682 100644 --- a/res/transpose.js +++ b/res/static/transpose.js @@ -31,7 +31,12 @@ function setTransposeSelector(n) { while (n < -6) { n += 12 } - document.getElementById("transposeSelect").value = n + ts = document.getElementById("transposeSelect") + if (n > 0) { + ts.value = "+" + n + } else { + ts.value = n + } } function getTranspose() { diff --git a/res/html/footer.html b/res/templates/footer.html similarity index 100% rename from res/html/footer.html rename to res/templates/footer.html diff --git a/res/html/head.html b/res/templates/head.html similarity index 77% rename from res/html/head.html rename to res/templates/head.html index 1873632..b2b1f0a 100644 --- a/res/html/head.html +++ b/res/templates/head.html @@ -1,7 +1,8 @@ Cancionero - Parroquia San Leandro - + + {% if specific_css %} -{% endif %} \ No newline at end of file +{% endif %} diff --git a/res/html/header.html b/res/templates/header.html similarity index 100% rename from res/html/header.html rename to res/templates/header.html diff --git a/res/templates/index.html b/res/templates/index.html new file mode 100644 index 0000000..412cdc0 --- /dev/null +++ b/res/templates/index.html @@ -0,0 +1,35 @@ + + + + {% include "head.html" with path="." only %} + + + + {% include "header.html" with path="." %} +

Índice

+ + Las canciones sin acordes están marcadas en rojo. +
    + {% for category, songs in sorted_categories.items %} +

    {{ category|title }}

    + {% for song in songs %} + +
  1. + {{ song.number }}. + {{ song.name }} + {% if song.author %} por {{ song.author }} {% endif %} + {% if song.origin %} basada en {{ song.origin }} {% endif %} +
  2. +
    + {% endfor %} + {% endfor %} +
+ {% include "footer.html" %} + + \ No newline at end of file diff --git a/res/html/song.html b/res/templates/song.html similarity index 81% rename from res/html/song.html rename to res/templates/song.html index 6ad94fc..712bc66 100644 --- a/res/html/song.html +++ b/res/templates/song.html @@ -10,11 +10,12 @@ {% include "header.html" with path=".." %}

{{ song.name}}

+ Categoría: {{ song.category|title }} {% if song.author %} -
Autor: {{ song.author }}
+ por {{ song.author }} {% endif %} {% if song.origin %} -
Basada en: {{ song.origin }}
+ basada en: {{ song.origin }} {% endif %}

Ajustes

@@ -29,19 +30,19 @@ @@ -104,7 +105,8 @@ {% endfor %} Ver archivo original (LaTeX) Índice + Categoría: {{ song.category|title }}
{% include "footer.html" %} - \ No newline at end of file + diff --git a/res/html/song_redir.html b/res/templates/song_redir.html similarity index 100% rename from res/html/song_redir.html rename to res/templates/song_redir.html diff --git a/src/latex_scanner.py b/src/latex_scanner.py index 506198d..a9449b1 100644 --- a/src/latex_scanner.py +++ b/src/latex_scanner.py @@ -38,9 +38,8 @@ class SongLoader: self.category = None self.categories = [] self.songs = [] - self.scan(latex_file) - self.memory = {} self.audio_dir = audio_dir + self.scan(latex_file) def scan(self, latex_file): main_file = open(latex_file, 'r') @@ -228,9 +227,16 @@ class SongLoader: continue current_verse.add_line(Line(text, extras)) + def sort_categories(self): + result = {} + for c in self.categories: + result[c] = sorted([s for s in self.songs if s.category == c], + key=lambda s: s.number) + return result + def print_index(self, index_file, dj_engine): - songs = sorted(self.songs, key=lambda s: s.number) - html = dj_engine.get_template("index.html").render(Context({'songs': songs})) + context = Context({'sorted_categories': self.sort_categories()}) + html = dj_engine.get_template("index.html").render(context) with open(index_file, 'w') as f: f.write(html) @@ -264,5 +270,5 @@ if __name__ == '__main__': args = parse_args() loader = SongLoader(args.latex[0], args.audios[0]) settings.configure(USE_TZ=False, USE_I18N=False) - e = Engine(dirs=["res/html/"]) + e = Engine(dirs=["res/templates/"]) loader.generate_html(args.output_dir[0], e)