|
2 | 2 |
|
3 | 3 | import requests as req, zipfile, io, markdown2 as md, sqlite3, os, shutil, tarfile
|
4 | 4 |
|
5 |
| -html_tmpl = """<html><head><link rel="stylesheet" type="text/css" href="../style.css"/></head><body><section id="tldr"><div id="page">%content%</div></section></body></html>""" |
| 5 | +html_tmpl = """<html><!-- Online page at {url} --> |
| 6 | + <head> |
| 7 | + <link rel="stylesheet" type="text/css" href="../style.css"/> |
| 8 | + </head> |
| 9 | + <body> |
| 10 | + <section id="tldr"> |
| 11 | + <div id="page">{content}</div> |
| 12 | + </section> |
| 13 | + </body> |
| 14 | +</html>""" |
6 | 15 |
|
| 16 | +online_url = "https://github.com/tldr-pages/tldr/blob/master/pages" |
7 | 17 | doc_source = "https://github.com/tldr-pages/tldr/archive/master.zip"
|
8 | 18 | docset_path = "tldrpages.docset"
|
9 | 19 | doc_path_contents = docset_path + "/Contents/"
|
|
54 | 64 | else:
|
55 | 65 | cur.execute('INSERT OR IGNORE INTO searchIndex(name, type, path) VALUES (?,?,?)', (cmd_name, 'Command', sub_dir+'/'+cmd_name+".html"))
|
56 | 66 | doc = markdowner.convert(archive.read(path))
|
57 |
| - doc = html_tmpl.replace("%content%", doc) |
| 67 | + doc = html_tmpl.format(url=online_url+'/'+sub_dir+'/'+cmd_name, content=doc) |
58 | 68 | with open(os.path.join(doc_path, path[len(doc_pref)+1:].replace(".md", ".html")), "wb") as html:
|
59 | 69 | html.write(doc.encode("utf-8"))
|
60 | 70 | db.commit()
|
61 | 71 | db.close()
|
62 | 72 |
|
63 | 73 | # Generate tldr pages index.html
|
64 | 74 | with open(os.path.join(doc_path, "index.html"), "w+") as html:
|
65 |
| - html.write('<html><head></head><body><h1>TLDR pages Docset</h1><br/>powered by <a href="http://tldr-pages.github.io">tldr-pages.github.io/</a>') |
| 75 | + html.write('<html><!-- Online page at '+online_url+' --><head></head><body><h1>TLDR pages Docset</h1><br/>powered by <a href="http://tldr-pages.github.io">tldr-pages.github.io/</a>') |
66 | 76 | for dir in os.listdir(doc_path):
|
67 | 77 | if os.path.isdir(os.path.join(doc_path, dir)):
|
68 | 78 | html.write("<h2>%s</h2><ul>" % dir)
|
|
0 commit comments