Add microformats to singles pages

master
trémeur 5 months ago
parent d3d579840a
commit e684db95fe

@ -92,14 +92,14 @@ def linkgen(ficno,output="output.html",local=False):
# write ao3 link if there is one # write ao3 link if there is one
try: try:
if fileread.ao3slug: if fileread.ao3slug:
filewrite.write("<li class=\"ao3link\"><a ") filewrite.write("<li class=\"ao3link\"><a class=\"u-syndication")
try: try:
if fileread.ao3locked: if fileread.ao3locked:
filewrite.write("class=\"locked\" ") filewrite.write(" locked")
except: except:
if fileread.locked: if fileread.locked:
filewrite.write("class=\"locked\" ") filewrite.write(" locked")
filewrite.write("href=\"https://archiveofourown.org/works/" + str(fileread.ao3slug) + "\">AO3</a></li>\n") filewrite.write("\" href=\"https://archiveofourown.org/works/" + str(fileread.ao3slug) + "\">AO3</a></li>\n")
except: except:
pass pass
# write fedi share link if there is one # write fedi share link if there is one
@ -250,7 +250,7 @@ def linkgen(ficno,output="output.html",local=False):
except: except:
pass pass
def ficgen(ficno,unique=False,output="output.html",local=False): def ficgen(ficno,unique=False,output="output.html",local=False,single=False):
# convert to three-digit number # convert to three-digit number
if ficno < 10: if ficno < 10:
ficnostring = "00" + str(ficno) ficnostring = "00" + str(ficno)
@ -284,11 +284,14 @@ def ficgen(ficno,unique=False,output="output.html",local=False):
if revealed == True: if revealed == True:
# write to output file # write to output file
filewrite = open(output, "a") filewrite = open(output, "a")
filewrite.write("<div class=\"fic\"") filewrite.write("<div class=\"fic")
if single:
filewrite.write(" h-entry")
filewrite.write("\"")
# give the div an id if requested # give the div an id if requested
if unique: if unique:
filewrite.write(" id=\"fic" + ficnostring + "\"") filewrite.write(" id=\"fic" + ficnostring + "\"")
filewrite.write(">\n<h1><span class=\"ficnoprelim\">no. </span><span class=\"ficno\"><a href=\"") filewrite.write(">\n<h1><span class=\"ficnoprelim\">no. </span><span class=\"ficno\"><a class=\"u-url\" href=\"")
if local: if local:
filewrite.write("/home/mdd/Documents/proj/fic-archive/build/single/" + ficnostring + "/index.html") filewrite.write("/home/mdd/Documents/proj/fic-archive/build/single/" + ficnostring + "/index.html")
else: else:
@ -307,7 +310,7 @@ def ficgen(ficno,unique=False,output="output.html",local=False):
filewrite.write("</span>") filewrite.write("</span>")
# write title if requested # write title if requested
if fileread.showtitle: if fileread.showtitle:
filewrite.write(" <span class=\"fictitle\">" + fileread.title) filewrite.write(" <span class=\"fictitle p-name\">" + fileread.title)
try: try:
if transread.showtitle: if transread.showtitle:
filewrite.write("/" + transread.title) filewrite.write("/" + transread.title)
@ -322,26 +325,26 @@ def ficgen(ficno,unique=False,output="output.html",local=False):
pass pass
if fileread.status == "abandoned": if fileread.status == "abandoned":
filewrite.write(" <span class=\"abandoned\"> (abandoned)</span>") filewrite.write(" <span class=\"abandoned\"> (abandoned)</span>")
filewrite.write("</h1>\n<ul class=\"ficmeta\">\n<li class=\"ficdate\"><i>Date:</i> ") filewrite.write("</h1>\n<div class=\"e-content\">\n<ul class=\"ficmeta\">\n<li class=\"ficdate\"><i>Date:</i> ")
# write date, date range if ranged or translation # write date, date range if ranged or translation
if fileread.status == "incomplete": if fileread.status == "incomplete":
filewrite.write((fileread.datewords[0])["date"].strftime("%-d %B %Y") + "") filewrite.write("<time datetime=\"" + (fileread.datewords[0])["date"].strftime("%Y-%m-%d") + "\" class=\"dt-published\">" + (fileread.datewords[0])["date"].strftime("%-d %B %Y") + "</time>")
else: else:
try: try:
if transread.status == "incomplete": if transread.status == "incomplete":
filewrite.write((fileread.datewords[0])["date"].strftime("%-d %B %Y") + "") filewrite.write("<time datetime=\"" + (fileread.datewords[0])["date"].strftime("%Y-%m-%d") + "\" class=\"dt-published\">" + (fileread.datewords[0])["date"].strftime("%-d %B %Y") + "</time>")
else: else:
if fileread.translation: if fileread.translation:
if (transread.datewords[-1])["date"].year == (fileread.datewords[0])["date"].year: if (transread.datewords[-1])["date"].year == (fileread.datewords[0])["date"].year:
if (transread.datewords[-1])["date"].month == (fileread.datewords[0])["date"].month: if (transread.datewords[-1])["date"].month == (fileread.datewords[0])["date"].month:
if (transread.datewords[-1])["date"].date == (fileread.datewords[0])["date"].date: if (transread.datewords[-1])["date"].date == (fileread.datewords[0])["date"].date:
filewrite.write((fileread.datewords[0])["date"].strftime("%-d %B %Y")) filewrite.write("<time datetime=\"" + (fileread.datewords[0])["date"].strftime("%Y-%m-%d") + "\" class=\"dt-published\">" + (fileread.datewords[0])["date"].strftime("%-d %B %Y") + "</time>")
else: else:
filewrite.write((fileread.datewords[0])["date"].strftime("%-d") + "" + (transread.datewords[-1])["date"].strftime("%-d %B %Y")) filewrite.write("<time datetime=\"" + (fileread.datewords[0])["date"].strftime("%Y-%m-%d") + "\" class=\"dt-published\">" + (fileread.datewords[0])["date"].strftime("%-d") + "</time><time datetime=\"" + (transread.datewords[-1])["date"].strftime("%Y-%m-%d") + "\" class=\"dt-updated\">" + (transread.datewords[-1])["date"].strftime("%-d %B %Y") + "</time>")
else: else:
filewrite.write((fileread.datewords[0])["date"].strftime("%-d %B") + "" + (transread.datewords[-1])["date"].strftime("%-d %B %Y")) filewrite.write("<time datetime=\"" + (fileread.datewords[0])["date"].strftime("%Y-%m-%d") + "\" class=\"dt-published\">" + (fileread.datewords[0])["date"].strftime("%-d %B") + "</time><time datetime=\"" + (transread.datewords[-1])["date"].strftime("%Y-%m-%d") + "\" class=\"dt-updated\">" + (transread.datewords[-1])["date"].strftime("%-d %B %Y") + "<time>")
else: else:
filewrite.write((fileread.datewords[0])["date"].strftime("%-d %B %Y") + "" + (transread.datewords[-1])["date"].strftime("%-d %B %Y")) filewrite.write("<time datetime=\"" + (fileread.datewords[0])["date"].strftime("%Y-%m-%d") + "\" class=\"dt-published\">" + (fileread.datewords[0])["date"].strftime("%-d %B %Y") + "</time><time datetime=\"" + (transread.datewords[-1])["date"].strftime("%Y-%m-%d") + "\" class=\"dt-updated\">" + (transread.datewords[-1])["date"].strftime("%-d %B %Y") + "</time>")
except: except:
try: try:
filewrite.write(fileread.approxdate) filewrite.write(fileread.approxdate)
@ -349,13 +352,13 @@ def ficgen(ficno,unique=False,output="output.html",local=False):
if (fileread.datewords[0])["date"].year == (fileread.datewords[-1])["date"].year: if (fileread.datewords[0])["date"].year == (fileread.datewords[-1])["date"].year:
if (fileread.datewords[0])["date"].month == (fileread.datewords[-1])["date"].month: if (fileread.datewords[0])["date"].month == (fileread.datewords[-1])["date"].month:
if (fileread.datewords[0])["date"] == (fileread.datewords[-1])["date"]: if (fileread.datewords[0])["date"] == (fileread.datewords[-1])["date"]:
filewrite.write((fileread.datewords[-1])["date"].strftime("%-d %B %Y")) filewrite.write("<time datetime=\"" + (fileread.datewords[-1])["date"].strftime("%Y-%m-%d") + "\" class=\"dt-published\">" + (fileread.datewords[-1])["date"].strftime("%-d %B %Y") + "</time>")
else: else:
filewrite.write((fileread.datewords[0])["date"].strftime("%-d") + "" + (fileread.datewords[-1])["date"].strftime("%-d %B %Y")) filewrite.write("<time datetime=\"" + (fileread.datewords[0])["date"].strftime("%Y-%m-%d") + "\" class=\"dt-published\">" + (fileread.datewords[0])["date"].strftime("%-d") + "</time><time datetime=\"" + (fileread.datewords[-1])["date"].strftime("%Y-%m-%d") + "\" class=\"dt-updated\">" + (fileread.datewords[-1])["date"].strftime("%-d %B %Y") + "</time>")
else: else:
filewrite.write((fileread.datewords[0])["date"].strftime("%-d %B") + "" + (fileread.datewords[-1])["date"].strftime("%-d %B %Y")) filewrite.write("<time datetime=\"" + (fileread.datewords[0])["date"].strftime("%Y-%m-%d") + "\" class=\"dt-published\">" + (fileread.datewords[0])["date"].strftime("%-d %B") + "</time><time datetime=\"" + (fileread.datewords[-1])["date"].strftime("%Y-%m-%d") + "\" class=\"dt-updated\">" + (fileread.datewords[-1])["date"].strftime("%-d %B %Y") + "</time>")
else: else:
filewrite.write((fileread.datewords[0])["date"].strftime("%-d %B %Y") + "" + (fileread.datewords[-1])["date"].strftime("%-d %B %Y")) filewrite.write("<time datetime=\"" + (fileread.datewords[0])["date"].strftime("%Y-%m-%d") + "\" class=\"dt-published\">" + (fileread.datewords[0])["date"].strftime("%-d %B %Y") + "</time><time datetime=\"" + (fileread.datewords[-1])["date"].strftime("%Y-%m-%d") + "\" class=\"dt-updated\">" + (fileread.datewords[-1])["date"].strftime("%-d %B %Y") + "</time>")
# write wordcount # write wordcount
sumwords = 0 sumwords = 0
for instalment in fileread.datewords: for instalment in fileread.datewords:
@ -384,13 +387,13 @@ def ficgen(ficno,unique=False,output="output.html",local=False):
filewrite.write(" (" + fileread.ratingreason + ")") filewrite.write(" (" + fileread.ratingreason + ")")
except: except:
pass pass
filewrite.write("</span></li>\n<li class=\"fandom\"><i>Fandom: </i>") filewrite.write("</li>\n<li class=\"fandom\"><i>Fandom: </i><span class=\"p-category\">")
# write fandom # write fandom
try: try:
filewrite.write(fileread.fandomtext) filewrite.write(fileread.fandomtext)
except: except:
filewrite.write("/".join(fileread.fandom)) filewrite.write("/".join(fileread.fandom))
filewrite.write("</li>\n") filewrite.write("</span></li>\n")
# write characters in pov, main, secondary categories, if they exist # write characters in pov, main, secondary categories, if they exist
try: try:
filewrite.write("<li class=\"characters\"><i>Characters: </i>" + fileread.charactertext + "</li>\n") filewrite.write("<li class=\"characters\"><i>Characters: </i>" + fileread.charactertext + "</li>\n")
@ -602,4 +605,7 @@ def ficgen(ficno,unique=False,output="output.html",local=False):
linkgen(ficno,output,local) linkgen(ficno,output,local)
filewrite = open(output, "a") filewrite = open(output, "a")
filewrite.write("</div>\n") filewrite.write("</div>\n")
if single:
filewrite.write("<div id=\"federation\" hidden=\"from-humans\">\n<a class=\"u-bridgy-fed\" href=\"https://fed.brid.gy/\"></a>\n<a rel=\"author\" class=\"p-author h-card\" href=\"/\">“tré”<img class=\"u-photo\" src=\"/ab.png\"></a>\n</div>\n")
filewrite.write("</div>\n")
filewrite.close() filewrite.close()

@ -37,11 +37,11 @@ def singlepage(ficno,directory,local=False):
headerfooter.headerwrite(output,"Fic no. " + ficnostring,"Fic no. <span id=\"ficno\">" + ficnostring + "</span>","",False,local) headerfooter.headerwrite(output,"Fic no. " + ficnostring,"Fic no. <span id=\"ficno\">" + ficnostring + "</span>","",False,local)
try: try:
if fileread.original: if fileread.original:
makeheader.ficgen(fileread.original,False,output,local) makeheader.ficgen(fileread.original,False,output,local,True)
else: else:
makeheader.ficgen(ficno,False,output,local) makeheader.ficgen(ficno,False,output,local,True)
except: except:
makeheader.ficgen(ficno,False,output,local) makeheader.ficgen(ficno,False,output,local,True)
if singlestatus: if singlestatus:
filewrite = open(output, "a") filewrite = open(output, "a")
filewrite.write("<iframe src=\"") filewrite.write("<iframe src=\"")

Loading…
Cancel
Save