From 09b83e3f175414f318d624f4872f1e5a9d44d182 Mon Sep 17 00:00:00 2001 From: Piotr Tabor Date: Sat, 21 Jun 2025 14:33:33 -0700 Subject: [PATCH 001/312] Change flows to use containers for spiewaj instead of wdw21. (#1) * Change flows to use containers for spiewaj instead of wdw21. * Fix creds. --- .github/workflows/generate_all.yml | 5 ++++- .github/workflows/generate_changed_pdf.yml | 5 ++++- .gitignore | 1 + containers/build_push_images.sh | 14 ++++++++------ 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/.github/workflows/generate_all.yml b/.github/workflows/generate_all.yml index a377d6c9..96a6d550 100644 --- a/.github/workflows/generate_all.yml +++ b/.github/workflows/generate_all.yml @@ -54,7 +54,10 @@ jobs: generate-artifacts: runs-on: ubuntu-latest container: - image: ghcr.io/wdw21/github-latex-worker:latest + image: ghcr.io/spiewaj/github-latex-worker:latest + credentials: + username: ${{ github.actor }} + password: ${{ secrets.github_token }} volumes: - ${{ github.workspace }}:/workspace steps: diff --git a/.github/workflows/generate_changed_pdf.yml b/.github/workflows/generate_changed_pdf.yml index 125f6054..d3a8b98d 100644 --- a/.github/workflows/generate_changed_pdf.yml +++ b/.github/workflows/generate_changed_pdf.yml @@ -9,7 +9,10 @@ jobs: Generate-artifacts: runs-on: ubuntu-latest container: - image: ghcr.io/wdw21/github-latex-worker:latest + image: ghcr.io/spiewaj/github-latex-worker:latest + credentials: + username: ${{ github.actor }} + password: ${{ secrets.github_token }} volumes: - ${{ github.workspace }}:/workspace steps: diff --git a/.gitignore b/.gitignore index 6c3cc281..7b5a5d53 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ npmtmp/ __pycache__/ node_modules/ *-download +.secrets diff --git a/containers/build_push_images.sh b/containers/build_push_images.sh index 04e464f7..40b068f3 100755 --- a/containers/build_push_images.sh +++ b/containers/build_push_images.sh @@ -2,21 +2,23 @@ SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +ORG="spiewaj" + set -e -x -#gh auth token | docker login ghcr.io -u ptabor --password-stdin # Authorization using: # - https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens # - https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-container-registry # The token is configured here: https://github.com/settings/tokens for scopes: delete:packages, repo, write:packages #echo "{PERSONAL_ACCESS_TOKEN}" | docker login ghcr.io -u ptabor --password-stdin +# If you forget - you need to regenerate. -cd "${SCRIPT_DIR}/.." -docker build -f "${SCRIPT_DIR}/Dockerfile" -t europe-docker.pkg.dev/wdw-21/songbook/github-latex-worker:latest --platform linux/amd64 . -docker image tag europe-docker.pkg.dev/wdw-21/songbook/github-latex-worker ghcr.io/wdw21/github-latex-worker:latest +cd "${SCRIPT_DIR}/.." +docker build -f "${SCRIPT_DIR}/Dockerfile" -t europe-docker.pkg.dev/$ORG/songbook/github-latex-worker:latest --platform linux/amd64 . -docker push europe-docker.pkg.dev/wdw-21/songbook/github-latex-worker:latest +docker image tag europe-docker.pkg.dev/$ORG/songbook/github-latex-worker ghcr.io/$ORG/github-latex-worker:latest +# docker push europe-docker.pkg.dev/$ORG/songbook/github-latex-worker:latest -docker push ghcr.io/wdw21/github-latex-worker:latest +docker push ghcr.io/$ORG/github-latex-worker:latest From 3e4aa1994347cd68f0f3ce0d2d4ba653201a4ca4 Mon Sep 17 00:00:00 2001 From: Piotr Tabor Date: Sun, 22 Jun 2025 03:58:47 -0700 Subject: [PATCH 002/312] Split CSSes between epub and html (#2) * Change flows to use containers for spiewaj instead of wdw21. * Fix creds. * Split CSS for kindle / epub from the web one. * Make CSS more compact... and navigation easier to click. * Use separate CSSes for published html * Navigation starts at 19 songs. * Dereference symlinks. * Fix render.js rendering. --- requirements.txt | 2 +- src/epub/create_epub.py | 27 +-- src/epub/templates/common.css | 13 ++ src/epub/templates/content.opf | 4 +- src/epub/templates/cover.xhtml | 2 +- src/epub/templates/index.css | 1 + src/epub/templates/index.xhtml | 2 +- src/epub/templates/song.css | 168 +----------------- src/epub/templates/song_common.css | 1 + src/epub/templates/songs.xhtml | 2 +- src/epub/templates/toc.xhtml | 2 +- src/epub/templates/toc_letter.xhtml | 2 +- src/html/create_songs_html.py | 4 +- src/html/css/common.css | 50 ++++++ .../template.css => html/css/index.css} | 2 + src/html/css/song.css | 1 + src/html/css/song_common.css | 168 ++++++++++++++++++ src/html/htmls_generator.py | 13 +- src/html/index_generator.py | 3 +- src/html/templates/index.xhtml | 8 +- 20 files changed, 283 insertions(+), 192 deletions(-) create mode 100644 src/epub/templates/common.css create mode 100755 src/epub/templates/index.css create mode 120000 src/epub/templates/song_common.css create mode 100644 src/html/css/common.css rename src/{epub/templates/template.css => html/css/index.css} (99%) create mode 100644 src/html/css/song.css create mode 100644 src/html/css/song_common.css diff --git a/requirements.txt b/requirements.txt index 6f55c472..3d8a425c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,7 @@ Jinja2~=3.1 #lxml==4.5.0 - `sudo apt-get install python3-lxml` (or similar) works better, as it's not python-native package. MarkupSafe~=2.1 -lxml~=4.9 +lxml PyICU>=2.7 pyyaml regex \ No newline at end of file diff --git a/src/epub/create_epub.py b/src/epub/create_epub.py index c35a4f5a..ce52df41 100644 --- a/src/epub/create_epub.py +++ b/src/epub/create_epub.py @@ -18,11 +18,13 @@ def actual_date(): def actual_datetime(): return str(datetime.now().strftime("%Y-%m-%d %H:%M")) +NO_NAV_LIMIT = 19 # # def name_of_file(song): # return os.path.splitext(os.path.split(song)[1])[0] +CSS_FILES = ["song.css", "common.css", "song_common.css", "index.css"] def create_content_opf(songbook, list_of_songs_meta, target_dir, pre_files=[], post_files=[]): tmp_path =os.path.join(sb.repo_dir(), "src", "epub", "templates", "content.opf") @@ -67,7 +69,7 @@ def create_toc_ncx(list_of_songs_meta, target_dir): last_letter='' playOrder=1 for i in range(len(list_of_songs_meta)): - if len(list_of_songs_meta) > 20 and last_letter != groupName(list_of_songs_meta[i].title()): + if len(list_of_songs_meta) > NO_NAV_LIMIT and last_letter != groupName(list_of_songs_meta[i].title()): last_letter = groupName(list_of_songs_meta[i].title()) parent_np = etree.SubElement(navmap, "navPoint") parent_np.attrib['id'] = 'p' + str(playOrder) @@ -110,7 +112,7 @@ def extract_toc_songs(list_of_songs_meta): group = None last_letter = None for i in range(len(list_of_songs_meta)): - if len(list_of_songs_meta) > 20 and last_letter != groupName(list_of_songs_meta[i].effectiveTitle()): + if len(list_of_songs_meta) > NO_NAV_LIMIT and last_letter != groupName(list_of_songs_meta[i].effectiveTitle()): group = groupName(list_of_songs_meta[i].effectiveTitle()) if not group in d: d[group] = [] @@ -250,12 +252,13 @@ def create_template_epub(songbook, target_path): path_tmp_meta = os.path.join(template_dir, "container.xml") resolveTemplate(songbook, path_tmp_meta, os.path.join(path_meta, "container.xml")) - path_tmp_css_song = os.path.join(template_dir, "song.css") - path_tmp_css_template = os.path.join(template_dir, "template.css") - path_tmp_mimetype = os.path.join(template_dir, "mimetype") + for css_file in CSS_FILES: + path_tmp_css = os.path.join(template_dir, css_file) + print("Linking CSS file: " + path_tmp_css + " to " + os.path.join(path_css, css_file)) + os.symlink(path_tmp_css, os.path.join(path_css, css_file)) + - shutil.copyfile(path_tmp_css_song, os.path.join(path_css, "song.css")) - shutil.copyfile(path_tmp_css_template, os.path.join(path_css, "template.css")) + path_tmp_mimetype = os.path.join(template_dir, "mimetype") shutil.copyfile(path_tmp_mimetype, os.path.join(path_epub, "mimetype")) shutil.copyfile(songbook.imageWebPath(), os.path.join(path_images, "cover." + songbook.imageWebExt())) @@ -300,11 +303,11 @@ def package_epub(songbook, target_dir, target_file="spiewnik.epub"): file_list = os.listdir(os.path.join(target_dir_epub, "OEBPS")) for file in file_list: if file != 'CSS': - myzip.write(os.path.join(target_dir_epub, "OEBPS", file), arcname=os.path.join("OEBPS", file)) - myzip.write(os.path.join(target_dir_epub, "OEBPS", "CSS", "template.css"), - arcname=os.path.join("OEBPS", "CSS", "template.css")) - myzip.write(os.path.join(target_dir_epub, "OEBPS", "CSS", "song.css"), - arcname=os.path.join("OEBPS", "CSS", "song.css")) + src_path = os.path.realpath(os.path.join(target_dir_epub, "OEBPS", file)) + myzip.write(src_path, arcname=os.path.join("OEBPS", file)) + for css_file in CSS_FILES: + src_path = os.path.realpath(os.path.join(target_dir_epub, "OEBPS", "CSS", css_file)) + myzip.write(src_path, arcname=os.path.join("OEBPS", "CSS", css_file)) myzip.write(os.path.join(target_dir_epub, "OEBPS", "images", "cover."+songbook.imageWebExt()), arcname=os.path.join("OEBPS", "images", "cover."+songbook.imageWebExt())) diff --git a/src/epub/templates/common.css b/src/epub/templates/common.css new file mode 100644 index 00000000..7cc7424c --- /dev/null +++ b/src/epub/templates/common.css @@ -0,0 +1,13 @@ +div.letters { + margin-top: 1em; + line-height: 5ex; + max-width: 35em; + text-align: center; +} + +div.letters a { + font-weight: bold; + font-size: x-large; + padding-left: 0.3em; + padding-right: 0.3em; +} \ No newline at end of file diff --git a/src/epub/templates/content.opf b/src/epub/templates/content.opf index 0deb8802..cda117f5 100755 --- a/src/epub/templates/content.opf +++ b/src/epub/templates/content.opf @@ -21,8 +21,10 @@ - + + + diff --git a/src/epub/templates/cover.xhtml b/src/epub/templates/cover.xhtml index f2ea5bae..ed705c47 100644 --- a/src/epub/templates/cover.xhtml +++ b/src/epub/templates/cover.xhtml @@ -3,7 +3,7 @@ :title: - +

:title:

diff --git a/src/epub/templates/index.css b/src/epub/templates/index.css new file mode 100755 index 00000000..d27a3162 --- /dev/null +++ b/src/epub/templates/index.css @@ -0,0 +1 @@ +@import url('common.css'); \ No newline at end of file diff --git a/src/epub/templates/index.xhtml b/src/epub/templates/index.xhtml index 9b3dcd74..47760d7c 100755 --- a/src/epub/templates/index.xhtml +++ b/src/epub/templates/index.xhtml @@ -3,7 +3,7 @@ Index - +

Index

diff --git a/src/epub/templates/song.css b/src/epub/templates/song.css index 4b8d16c3..2eec300f 100644 --- a/src/epub/templates/song.css +++ b/src/epub/templates/song.css @@ -1,166 +1,6 @@ -/* Kindle specyfic chords styling, as kindle stopped supporting 'width' property in the inline-block. */ - -body { - font-family: sans-serif; -} - -div.song_body { - width: max-content; - display: table; -} - -/* Per block settings - Chorus, Verses, Instrumental */ - -div.verse, div.chorus, div.other { - display: contents; -} - -div.chorus div.row span.lyric { - padding-left: 3ex; -} - -div.block_spacer { - display: table-row; - empty-cells: show; - height: 2.5ex; -} - -/* Per row settings*/ - -div.row { - display: table-row; - page-break-inside: avoid; - page-break-after: avoid; -} - -div.row:last-of-type { - page-break-after: auto; -} - -/* Lyrics */ - -span.block_id, span.lyric, span.chords, span.bis_inactive, span.bis_active, span.chords_ins { - display: table-cell; -} - -span.block_id { - padding-top: 1ex; - page-break-inside: avoid; - page-break-after: avoid; -} -/* margin-right: 0.5em;*/ -/*}*/ - -/* As there is no call-span in CSS we allow the instrumental row to overflow */ -span.chords_ins { - max-width: 5em; - padding-left: 1em; - text-overflow: ellipsis; - white-space: nowrap; -} - -/* Chords above the text */ - -span.lyric span.chunk { - display: inline-table; - /*border: 1px solid green;*/ - vertical-align: bottom; -} - -span.lyric span.chord { - display: table-row; - /*border: 1px solid orange;*/ - max-height: 0; -} - -span.lyric span.chord span.ch{ - display: table-cell; -} - -span.lyric span.content { - display: table-row; - /*border: 1px solid red;*/ - /*overflow-wrap: normal;*/ - /*white-space: nowrap;*/ - /*hyphens: none;*/ -} - -span.lyric span.content-i { - display: table-cell; - /*border: 1px solid red;*/ - white-space: pre-line; - overflow-wrap: normal; - /*white-space: nowrap;*/ - /*empty-cells: show;*/ - hyphens: none; - height: 2.2ex; -} - -span.ws { - display: inline-block; - opacity: 0; -} - -div.over_false span.lyric span.ch { - display: none; -} - -/*!* Generic styling*!*/ +@import url('song_common.css'); h1 { - text-align: left; -} - -span.lyric span.ch { - font-family: sans-serif; - font-size: xx-small; - font-weight: bolder; -} - -span.ch { - font-family: sans-serif; - font-weight: bolder; -} - -span.chords span.ch { - padding-right: 0.3em; -} - -span.chords { - padding-left: 1em; - padding-right: 1em; - max-width: 10em; - overflow-wrap: break-word; - - /* not sure if needed... commenting for now*/ - /* overflow-wrap: break-word;*/ - /* hyphens: none;*/ - /* white-space: nowrap;*/ -} - -span.content_creator { - margin-top: 0.0em; - font-style: italic; - font-weight: bold; - font-size: small; -} - -div.row > span.bis_inactive { - padding-right: 0.4em; - empty-cells: show; - width: 2em; -} - -div.row > span.bis_active { - padding-left: 0.4em; - padding-right: 0.3em; - border-right: solid; - empty-cells: show; - text-align: right; - width: 2em; /* fixed length makes it more likely on kindle to finish at the same place */ -} - -div.comment { - margin-top: 1.2em; - font-style: italic; -} + margin-top: 0.5em; + margin-bottom: 0.5em; +} \ No newline at end of file diff --git a/src/epub/templates/song_common.css b/src/epub/templates/song_common.css new file mode 120000 index 00000000..fb5f83f9 --- /dev/null +++ b/src/epub/templates/song_common.css @@ -0,0 +1 @@ +../../html/css/song_common.css \ No newline at end of file diff --git a/src/epub/templates/songs.xhtml b/src/epub/templates/songs.xhtml index 8f93443d..7f9550fd 100755 --- a/src/epub/templates/songs.xhtml +++ b/src/epub/templates/songs.xhtml @@ -3,7 +3,7 @@ Index - +

Piosenki

diff --git a/src/epub/templates/toc.xhtml b/src/epub/templates/toc.xhtml index 863899ad..9119f0d4 100755 --- a/src/epub/templates/toc.xhtml +++ b/src/epub/templates/toc.xhtml @@ -3,7 +3,7 @@ Spis piosenek - +