forked from CryHavoc/dottes
Add fulltitle to template fields.
fulltitle is title + [(" subtitle ")"] if subtitle is present. To do: extend full title to next and prev. this means exposing it in abcfield.py.
This commit is contained in:
parent
0f2b90c40d
commit
9e27b13c6b
32
abcfield.py
32
abcfield.py
|
@ -181,23 +181,18 @@ def convertMarkdown(t, latex):
|
||||||
def expandCustomMarkdown(t, dir, latex):
|
def expandCustomMarkdown(t, dir, latex):
|
||||||
# Given a match to (foo.abc), return a markdown link to the tune with the
|
# Given a match to (foo.abc), return a markdown link to the tune with the
|
||||||
# title (and subtitle, if present) of the tune as the text of the link.
|
# title (and subtitle, if present) of the tune as the text of the link.
|
||||||
def getTitle(m):
|
def getTitleLink(m):
|
||||||
fname = m.group(1) + ".abc"
|
fname = m.group(1) + ".abc"
|
||||||
path = pathlib.Path(dir, fname)
|
path = pathlib.Path(dir, fname)
|
||||||
with path.open() as f:
|
with path.open() as f:
|
||||||
title = getFieldDisplayText(f, dir, "T", latex=latex)
|
return "[" + getFullTitle(f, dir, latex=latex) + "](" + fname + ")"
|
||||||
f.seek(0)
|
return re.sub(r'<(.*?).abc>', getTitleLink, t)
|
||||||
subtitle = getFieldDisplayText(f, dir, "T", n=2, latex=latex)
|
|
||||||
if len(subtitle) > 0:
|
|
||||||
title = title + " (" + subtitle + ")"
|
|
||||||
return "[" + title + "](" + fname + ")"
|
|
||||||
return re.sub(r'<(.*?).abc>', getTitle, t)
|
|
||||||
|
|
||||||
# Return the raw text for a given field. Optionally the nth field is taken,
|
# Return the raw text for a given field. Optionally the nth field is taken,
|
||||||
# or the field data must start with a designated string to be recognised.
|
# or the field data must start with a designated string to be recognised.
|
||||||
def getFieldText(inf, field, n = 1, starts = None):
|
def getFieldText(lines, field, n = 1, starts = None):
|
||||||
res = ""
|
res = ""
|
||||||
for line in inf:
|
for line in lines:
|
||||||
line = line.strip()
|
line = line.strip()
|
||||||
if len(line) > 2 and line[1] == ':':
|
if len(line) > 2 and line[1] == ':':
|
||||||
if line[0] == "+" or (line[0] == field and line[2] == "+"):
|
if line[0] == "+" or (line[0] == field and line[2] == "+"):
|
||||||
|
@ -224,8 +219,8 @@ def getFieldText(inf, field, n = 1, starts = None):
|
||||||
return res
|
return res
|
||||||
|
|
||||||
# Return display text for a given field.
|
# Return display text for a given field.
|
||||||
def getFieldDisplayText(inf, dir, field, n = 1, starts = None, latex = False):
|
def getFieldDisplayText(lines, dir, field, n = 1, starts = None, latex = False):
|
||||||
res = getFieldText(inf, field, n, starts)
|
res = getFieldText(lines, field, n, starts)
|
||||||
if res:
|
if res:
|
||||||
res = convertAccents(res, latex)
|
res = convertAccents(res, latex)
|
||||||
if field.upper() == "T":
|
if field.upper() == "T":
|
||||||
|
@ -236,12 +231,19 @@ def getFieldDisplayText(inf, dir, field, n = 1, starts = None, latex = False):
|
||||||
res = convertMarkdown(expandCustomMarkdown(res, dir, latex), latex)
|
res = convertMarkdown(expandCustomMarkdown(res, dir, latex), latex)
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
# Return full title (title + [" (" + subtitle + ")"] if subtitle exists).
|
||||||
|
def getFullTitle(lines, dir, starts = None, latex = False):
|
||||||
|
title = getFieldDisplayText(lines, dir, "T", starts=starts, latex=latex)
|
||||||
|
subtitle = getFieldDisplayText(lines, dir, "T", n=2, starts=starts, latex=latex)
|
||||||
|
return title if len(subtitle) == 0 else title + " (" + subtitle + ")"
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
def process(inf, dir, options):
|
def process(f, dir, options):
|
||||||
|
lines = f.readlines()
|
||||||
if options.display:
|
if options.display:
|
||||||
line = getFieldDisplayText(inf, dir, options.field, options.index, options.starts, options.latex)
|
line = getFieldDisplayText(lines, dir, options.field, options.index, options.starts, options.latex)
|
||||||
else:
|
else:
|
||||||
line = getFieldText(inf, options.field, options.index, options.starts)
|
line = getFieldText(lines, options.field, options.index, options.starts)
|
||||||
if line:
|
if line:
|
||||||
print(line)
|
print(line)
|
||||||
return True
|
return True
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
# * name. The file base name. Base filename without extension.
|
# * name. The file base name. Base filename without extension.
|
||||||
# * title. The tune title.
|
# * title. The tune title.
|
||||||
# * subtitle. The tune subtitle (second Title field), if any.
|
# * subtitle. The tune subtitle (second Title field), if any.
|
||||||
|
# * fulltitle. The tune title followed, if it exists, by " (" subtitle ")"
|
||||||
# * tradition. The Morris tradition the dance tune is from.
|
# * tradition. The Morris tradition the dance tune is from.
|
||||||
# * composer. The tune composer.
|
# * composer. The tune composer.
|
||||||
# * key. The tune key.
|
# * key. The tune key.
|
||||||
|
@ -37,7 +38,7 @@ import argparse
|
||||||
import pathlib
|
import pathlib
|
||||||
import string
|
import string
|
||||||
|
|
||||||
from abcfield import getFieldDisplayText
|
from abcfield import getFieldDisplayText, getFullTitle
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
parser = argparse.ArgumentParser(description='Substitute values from ABC file into template.')
|
parser = argparse.ArgumentParser(description='Substitute values from ABC file into template.')
|
||||||
|
@ -68,6 +69,7 @@ if __name__ == "__main__":
|
||||||
vars["name"] = fname
|
vars["name"] = fname
|
||||||
vars["title"] = getFieldDisplayText(lines, fdir, "T", latex=args.latex)
|
vars["title"] = getFieldDisplayText(lines, fdir, "T", latex=args.latex)
|
||||||
vars["subtitle"] = getFieldDisplayText(lines, fdir, "T", n=2, latex=args.latex)
|
vars["subtitle"] = getFieldDisplayText(lines, fdir, "T", n=2, latex=args.latex)
|
||||||
|
vars["fulltitle"] = getFullTitle(lines, fdir, latex=args.latex)
|
||||||
vars["tradition"] = getFieldDisplayText(lines, fdir, "A", latex=args.latex)
|
vars["tradition"] = getFieldDisplayText(lines, fdir, "A", latex=args.latex)
|
||||||
vars["composer"] = getFieldDisplayText(lines, fdir, "C", latex=args.latex)
|
vars["composer"] = getFieldDisplayText(lines, fdir, "C", latex=args.latex)
|
||||||
vars["key"] = getFieldDisplayText(lines, fdir, "K", latex=args.latex)
|
vars["key"] = getFieldDisplayText(lines, fdir, "K", latex=args.latex)
|
||||||
|
|
|
@ -48,7 +48,7 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<p>${title} is in the key of ${key}.
|
<p>${fulltitle} is in the key of ${key}.
|
||||||
<div class="dottes-tune-learner">
|
<div class="dottes-tune-learner">
|
||||||
<div class="dottes-tune-learner-speed-column"></div>
|
<div class="dottes-tune-learner-speed-column"></div>
|
||||||
<div class="dottes-tune-learner-play-column"></div>
|
<div class="dottes-tune-learner-play-column"></div>
|
||||||
|
@ -149,7 +149,7 @@
|
||||||
<div class="dottes-tune-footer-learner-booke">
|
<div class="dottes-tune-footer-learner-booke">
|
||||||
<a class="dottes-tune-icon-link" href="${name}.html">
|
<a class="dottes-tune-icon-link" href="${name}.html">
|
||||||
<img class="dottes-tune-header-image" src="../img/music.png"
|
<img class="dottes-tune-header-image" src="../img/music.png"
|
||||||
alt="Tune dottes page" title="Go to dottes page for ${title}">
|
alt="Tune dottes page" title="Go to dottes page for ${fulltitle}">
|
||||||
</a>
|
</a>
|
||||||
<a class="dottes-tune-icon-link" href="index.html">
|
<a class="dottes-tune-icon-link" href="index.html">
|
||||||
<img class="dottes-tune-header-image" src="../img/book.png"
|
<img class="dottes-tune-header-image" src="../img/book.png"
|
||||||
|
|
|
@ -84,7 +84,7 @@
|
||||||
<div class="dottes-tune-footer-booke">
|
<div class="dottes-tune-footer-booke">
|
||||||
<a class="dottes-tune-icon-link" href="learner-${name}.html">
|
<a class="dottes-tune-icon-link" href="learner-${name}.html">
|
||||||
<img class="dottes-tune-header-image" src="../img/learner.png"
|
<img class="dottes-tune-header-image" src="../img/learner.png"
|
||||||
alt="Learner tune page" title="Go to learner page for ${title}">
|
alt="Learner tune page" title="Go to learner page for ${fulltitle}">
|
||||||
</a>
|
</a>
|
||||||
<a class="dottes-tune-icon-link" href="index.html">
|
<a class="dottes-tune-icon-link" href="index.html">
|
||||||
<img class="dottes-tune-header-image" src="../img/book.png"
|
<img class="dottes-tune-header-image" src="../img/book.png"
|
||||||
|
|
|
@ -1,16 +1,16 @@
|
||||||
<div class="dottes-tune-list-item">
|
<div class="dottes-tune-list-item">
|
||||||
<div class="dottes-tune-list-item-link">
|
<div class="dottes-tune-list-item-link">
|
||||||
<a class="dottes-tune-link" href="${name}.html">${title}</a>
|
<a class="dottes-tune-link" href="${name}.html">${fulltitle}</a>
|
||||||
</div>
|
</div>
|
||||||
<div class="dottes-tune-list-item-learner-link">
|
<div class="dottes-tune-list-item-learner-link">
|
||||||
<a class="dottes-tune-link" href="learner-${name}.html">
|
<a class="dottes-tune-link" href="learner-${name}.html">
|
||||||
<img class="dottes-tune-table-image" src="../img/learner.png" alt="Learner">
|
<img class="dottes-tune-table-image" src="../img/learner.png" alt="Learner page" title="Learner page for ${fulltitle}">
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
<div class="dottes-tune-list-item-image">
|
<div class="dottes-tune-list-item-image">
|
||||||
<a href="${name}.html">
|
<a href="${name}.html">
|
||||||
<img class="dottes-tune-table-image" src="firstline-${name}.png"
|
<img class="dottes-tune-table-image" src="firstline-${name}.png"
|
||||||
alt="${title} first line">
|
alt="${fulltitle} first line" title="${fulltitle} first line">
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in New Issue