mirror of
https://github.com/tildeclub/ttbp.git
synced 2026-06-19 19:29:23 +00:00
added permalinks
This commit is contained in:
46
bin/core.py
46
bin/core.py
@@ -46,10 +46,10 @@ def load_files():
|
||||
global FILES
|
||||
|
||||
FILES = []
|
||||
for file in os.listdir(DATA):
|
||||
filename = os.path.join(DATA, file)
|
||||
for filename in os.listdir(DATA):
|
||||
filename = os.path.join(DATA, filename)
|
||||
if os.path.isfile(filename) and os.path.splitext(filename)[1] == ".txt":
|
||||
FILES.append(file)
|
||||
FILES.append(filename)
|
||||
|
||||
FILES.sort()
|
||||
FILES.reverse()
|
||||
@@ -67,8 +67,9 @@ def write(outurl="default.html"):
|
||||
|
||||
outfile.write("\n")
|
||||
|
||||
for file in FILES:
|
||||
for line in write_entry(file):
|
||||
for filename in FILES:
|
||||
write_page(filename)
|
||||
for line in write_entry(filename):
|
||||
outfile.write(line)
|
||||
|
||||
outfile.write("\n")
|
||||
@@ -80,10 +81,35 @@ def write(outurl="default.html"):
|
||||
|
||||
return os.path.join(LIVE+USER,os.path.basename(os.path.realpath(WWW)),outurl)
|
||||
|
||||
def write_entry(file):
|
||||
def write_page(filename):
|
||||
# makes a single permalink page
|
||||
|
||||
outurl = os.path.join(WWW, "".join(parse_date(filename))+".html")
|
||||
outfile = open(outurl, "w")
|
||||
|
||||
outfile.write("<!--generated by the tilde.town blogging platform on "+time.strftime("%d %B %y")+"\nhttp://tilde.town/~endorphant/ttbp/-->\n\n")
|
||||
|
||||
for line in HEADER:
|
||||
outfile.write(line)
|
||||
|
||||
outfile.write("\n")
|
||||
|
||||
for line in write_entry(filename):
|
||||
outfile.write(line)
|
||||
|
||||
outfile.write("\n")
|
||||
|
||||
for line in FOOTER:
|
||||
outfile.write(line)
|
||||
|
||||
outfile.close()
|
||||
|
||||
return outurl
|
||||
|
||||
def write_entry(filename):
|
||||
# dump given file into entry format, return as list of strings
|
||||
|
||||
date = parse_date(file)
|
||||
date = parse_date(filename)
|
||||
|
||||
entry = [
|
||||
"\t\t<p><a name=\""+date[0]+date[1]+date[2]+"\"></a><br /><br /></p>\n",
|
||||
@@ -93,7 +119,7 @@ def write_entry(file):
|
||||
]
|
||||
|
||||
raw = []
|
||||
rawfile = open(os.path.join(DATA, file), "r")
|
||||
rawfile = open(os.path.join(DATA, filename), "r")
|
||||
|
||||
for line in rawfile:
|
||||
raw.append(line)
|
||||
@@ -104,7 +130,9 @@ def write_entry(file):
|
||||
if line == "\n":
|
||||
entry.append("</p>\n\t\t\t<p>")
|
||||
|
||||
entry.append("</p>\n\t\t</div>\n")
|
||||
entry.append("</p>\n")
|
||||
entry.append("\t\t\t<p style=\"font-size:.6em; font-color:#808080; text-align: right;\"><a href=\""+"".join(date)+".html\">permalink</a></p>\n")
|
||||
entry.append("\n\t\t</div>\n")
|
||||
|
||||
return entry
|
||||
|
||||
|
||||
Reference in New Issue
Block a user