Browse Source

improve md generation, enable custom category characters

automate 2.0-rc3
mxmehl 6 months ago
parent
commit
faea470b10
Signed by: mxmehl GPG Key ID: 2704E4AB371E2E92
  1. 46
      scripts/create-index.py

46
scripts/create-index.py

@ -14,25 +14,34 @@ parser.add_argument("-t", "--type", dest="type",
args = parser.parse_args()
# HELPER FUNCTIONS
def md_line(songtype, songname, filename):
def md_song(filename, songname, songcat):
download = {}
# Always add PDF download to options
song_dl = "("
download['PDF'] = f"/songbook/{filename}.pdf"
for dltype, url in download.items():
song_dl += f'<a href="{url}">{dltype}</a>'
# only add inindented text for category items
if songtype == "category":
indent = ""
song_dl = ""
# indent text and add download info for songs
else:
indent = " "
# Always add PDF download to options
song_dl = " ("
download['PDF'] = f"/songbook/{filename}.pdf"
for dltype, url in download.items():
song_dl += f"[{dltype}]({url})"
song_dl += ")"
f.write(f' <li>{songname} {song_dl}</li>\n')
song_dl += ")"
f.write(f"{indent}1. {songname}{song_dl}\n")
def md_cat(songcat, songname):
"""Create necessary <ol> tags depending on category"""
if songcat == "END":
f.write("</ol></li><ol>\n")
else:
li_value = ord(songcat) - 64 # A = 1, Z = 26
if songcat == "A":
f.write("<ol>\n")
f.write(f'<li value="{li_value}">{songname}\n')
f.write("<ol>\n")
else:
f.write("</ol></li>\n")
f.write(f'<li value="{li_value}">{songname}\n')
f.write("<ol>\n")
# Prepare PDF file
pdf = FPDF(format = "A5")
@ -71,12 +80,15 @@ for file_name in sorted(glob.iglob(f'build/Songs/{SELECTION}*.pdf')):
pdf.set_font('courier', size=8, style="B")
pdf.cell(txt=f"{song_cat}. {song_name}", ln=1)
md_line("category", song_name, file_name)
md_cat(song_cat, song_name)
else:
pdf.set_font('courier', size=8)
pdf.cell(txt=f" {song_no}. {song_name}", ln=1)
md_line("song", song_name, file_name)
md_song(file_name, song_name, song_cat)
# close Markdown list
md_cat("END", "")
pdf.cell(txt="**Akkorde**", ln=1, markdown=True)

Loading…
Cancel
Save