Mercurial > codedump
comparison generatehtml.py @ 84:1eb7d6d7be1d
blog stuff
committer: GitHub <noreply@github.com>
| author | Paper <37962225+mrpapersonic@users.noreply.github.com> |
|---|---|
| date | Thu, 28 Jul 2022 16:50:25 -0400 |
| parents | |
| children | c24d5b83a726 |
comparison
equal
deleted
inserted
replaced
| 83:05803e046878 | 84:1eb7d6d7be1d |
|---|---|
| 1 # super simple | |
| 2 | |
| 3 import os | |
| 4 import sys | |
| 5 import html | |
| 6 | |
| 7 title = "Paper's blog" | |
| 8 | |
| 9 def addtitle(out_str, title): | |
| 10 # add stuff here | |
| 11 # The title in question: | |
| 12 out_str += """ <div class="entry">\n <h1>%s</h1>\n <pre>\n""" % html.escape(title.strip()) | |
| 13 return out_str | |
| 14 | |
| 15 def main(argv): | |
| 16 file = open(argv[1], 'r') | |
| 17 out = open(argv[2], 'w') | |
| 18 out_str = ( | |
| 19 """<!DOCTYPE html> | |
| 20 <head> | |
| 21 <title>%s</title> | |
| 22 <meta name="viewport" content="width=device-width;initial-scale=1.0" /> | |
| 23 <link rel="stylesheet" type="text/css" href="blog.css" /> | |
| 24 </head> | |
| 25 <body> | |
| 26 """ % (title)) | |
| 27 lines = file.readlines() | |
| 28 for line in range(len(lines)): | |
| 29 if lines[line][0] == "#": | |
| 30 out_str = addtitle(out_str, lines[line][1:]) | |
| 31 continue | |
| 32 # this sucks. | |
| 33 if lines[line][0:3] == "---" or len(lines)-line == 1: | |
| 34 if len(lines)-line == 1: | |
| 35 out_str += """%s\n""" % html.escape(lines[line].strip()) | |
| 36 out_str += " </pre>\n </div>\n" | |
| 37 continue | |
| 38 out_str += """%s\n""" % html.escape(lines[line].strip()) | |
| 39 out_str += "</body>" | |
| 40 print(out_str, file=out) | |
| 41 | |
| 42 if __name__ == "__main__": | |
| 43 main(sys.argv) |
