Skip to content

Commit 8bac0b3

Browse files
committed
Add support for online redirection
- https://kapeli.com/docsets#onlineRedirection
1 parent dad15f1 commit 8bac0b3

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

generator.py

+13-3
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,18 @@
22

33
import requests as req, zipfile, io, markdown2 as md, sqlite3, os, shutil, tarfile
44

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>"""
615

16+
online_url = "https://github.com/tldr-pages/tldr/blob/master/pages"
717
doc_source = "https://github.com/tldr-pages/tldr/archive/master.zip"
818
docset_path = "tldrpages.docset"
919
doc_path_contents = docset_path + "/Contents/"
@@ -54,15 +64,15 @@
5464
else:
5565
cur.execute('INSERT OR IGNORE INTO searchIndex(name, type, path) VALUES (?,?,?)', (cmd_name, 'Command', sub_dir+'/'+cmd_name+".html"))
5666
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)
5868
with open(os.path.join(doc_path, path[len(doc_pref)+1:].replace(".md", ".html")), "wb") as html:
5969
html.write(doc.encode("utf-8"))
6070
db.commit()
6171
db.close()
6272

6373
# Generate tldr pages index.html
6474
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>')
6676
for dir in os.listdir(doc_path):
6777
if os.path.isdir(os.path.join(doc_path, dir)):
6878
html.write("<h2>%s</h2><ul>" % dir)

0 commit comments

Comments
 (0)