Michael Murtaugh
9 years ago
5 changed files with 257 additions and 5 deletions
@ -0,0 +1,23 @@ |
|||
#!/usr/bin/env python |
|||
|
|||
from __future__ import print_function |
|||
from argparse import ArgumentParser |
|||
import json, os |
|||
|
|||
def main(args): |
|||
p = ArgumentParser("") |
|||
p.add_argument("input", nargs="+", help="filenames") |
|||
p.add_argument("--indent", type=int, default=2, help="indent") |
|||
args = p.parse_args(args) |
|||
inputs = args.input |
|||
inputs.sort() |
|||
ret = [] |
|||
for p in inputs: |
|||
with open(p) as f: |
|||
meta = json.load(f) |
|||
ret.append(meta) |
|||
|
|||
if args.indent: |
|||
print (json.dumps(ret, indent=args.indent)) |
|||
else: |
|||
print (json.dumps(ret)) |
@ -0,0 +1,60 @@ |
|||
#!/usr/bin/env python |
|||
|
|||
from __future__ import print_function |
|||
from argparse import ArgumentParser |
|||
import json, os, re |
|||
from urllib import urlencode |
|||
from urllib2 import urlopen, HTTPError, URLError |
|||
from jinja2 import FileSystemLoader, Environment |
|||
|
|||
def group (items, key=lambda x: x): |
|||
ret = [] |
|||
keys = {} |
|||
for item in items: |
|||
k = key(item) |
|||
if k not in keys: |
|||
keys[k] = [] |
|||
keys[k].append(item) |
|||
for k in sorted(keys): |
|||
keys[k].sort() |
|||
ret.append(keys[k]) |
|||
return ret |
|||
|
|||
def main(args): |
|||
p = ArgumentParser("") |
|||
p.add_argument("input", nargs="+", help="filenames") |
|||
p.add_argument("--templates", default=None, help="templates path") |
|||
args = p.parse_args(args) |
|||
|
|||
tmpath = args.templates |
|||
if tmpath == None: |
|||
tmpath = os.path.split(os.path.abspath(__file__))[0] |
|||
tmpath = os.path.split(tmpath)[0] |
|||
tmpath = os.path.join(tmpath, "data", "templates") |
|||
|
|||
env = Environment(loader=FileSystemLoader(tmpath)) |
|||
template = env.get_template("pad_index.html") |
|||
|
|||
inputs = args.input |
|||
inputs.sort() |
|||
inputs = [x for x in inputs if os.path.isdir(x)] |
|||
|
|||
def base (x): |
|||
return re.sub(r"(\.html)|(\.diff\.html)|(\.meta\.json)|(\.txt)$", "", x) |
|||
|
|||
# TODO: MODIFY THIS TO MAKE THE OUTPUT JOINABLE with the collected META DATA |
|||
# evt: how can the metadata become a GRAPH structure!!! with each output DOCUMENT |
|||
# |
|||
print ("<ol>") |
|||
for x in inputs: |
|||
padid = x |
|||
metapath = os.path.join(x, "{0}.meta.json".format(padid)) |
|||
if os.path.exists(metapath): |
|||
print ("""<li><a href="{0}">{0}</a></li>""".format(x)) |
|||
with open(metapath) as f: |
|||
meta = json.load(f) |
|||
indexpath = os.path.join(x, "index.html") |
|||
with open(indexpath, "w") as f: |
|||
print (template.render(**meta).encode("utf-8"), file=f) |
|||
|
|||
print ("</ol>") |
@ -0,0 +1,128 @@ |
|||
<!DOCTYPE html> |
|||
<html> |
|||
<head> |
|||
<meta charset="utf-8"> |
|||
<style> |
|||
body { |
|||
overflow: hidden; |
|||
margin: 0; |
|||
padding: 0; |
|||
} |
|||
td { |
|||
vertical-align: top; |
|||
} |
|||
table ul { |
|||
margin: 0; |
|||
padding-left: 0; |
|||
list-style: none; |
|||
} |
|||
#content { |
|||
position: absolute; |
|||
left:0; |
|||
top: 0; |
|||
right: 0; |
|||
bottom: 0; |
|||
overflow: auto; |
|||
background: gray; |
|||
} |
|||
iframe { |
|||
position: absolute; |
|||
left: 0; top: 0; |
|||
width: 100%; |
|||
height: 100%; |
|||
border: none; |
|||
margin: 0; |
|||
padding: 0; |
|||
background: white; |
|||
} |
|||
#overlay { |
|||
position: absolute; |
|||
z-index: 10; |
|||
right: 20px; |
|||
top: 40px; |
|||
width: auto; |
|||
height: auto; |
|||
overflow: hidden; |
|||
background: black; |
|||
color: white; |
|||
padding: 10px; |
|||
font-size: 10px; |
|||
font-family: monospace; |
|||
} |
|||
#overlay a { |
|||
color: white; |
|||
text-decoration: none; |
|||
} |
|||
#overlay a:hover { |
|||
background: gray; |
|||
color: black; |
|||
} |
|||
a.active { |
|||
background: white !important; |
|||
color: black !important; |
|||
} |
|||
td.key { |
|||
font-style: italic; |
|||
} |
|||
#overlay.open {} |
|||
#overlay .closedcontent { display: block; } |
|||
#overlay.open .closedcontent { display: none; } |
|||
#overlay .opencontent { display: none; } |
|||
#overlay.open .opencontent { display: block; } |
|||
</style> |
|||
</head> |
|||
<body> |
|||
<div id="content"> |
|||
<iframe src="{{padid}}.html" id="frame" name="frame"></iframe> |
|||
<div id="overlay"> |
|||
<div class="closedcontent"> |
|||
versions |
|||
</div> |
|||
<table class="opencontent"> |
|||
<tr><td class="key">padid</td><td>{{padid}}</td></tr> |
|||
<tr><td class="key">lastedited</td><td>{{lastedited_iso}}</td></tr> |
|||
<tr><td class="key">revisions</td><td>{{revisions}}</td></tr> |
|||
<tr> |
|||
<td class="key">versions</td> |
|||
<td> |
|||
<ul> |
|||
<li><a href="{{padurl}}" target="frame">Etherpad (editable)</a><li> |
|||
<li><a href="{{padid}}.html" target="frame">HTML</a></li> |
|||
<li><a href="{{padid}}.txt" target="frame">plain text</a></li> |
|||
<li><a href="{{padid}}.diff.html" target="frame">HTML with authorship colors</a></li> |
|||
<li><a href="{{padid}}.meta.json" target="frame">Meta data (JSON)</a></li> |
|||
</ul> |
|||
</td> |
|||
</tr> |
|||
</table> |
|||
</div> |
|||
|
|||
<script> |
|||
(function () { |
|||
var frame = document.getElementById("frame"), |
|||
overlay = document.getElementById("overlay"); |
|||
frame.addEventListener("load", function () { |
|||
var loaded_href = frame.contentDocument.location.href, |
|||
links = document.querySelectorAll("#overlay a"); |
|||
// console.log("load", loaded_href); |
|||
for (var i=0, len=links.length; i<len; i++) { |
|||
var linkhref = links[i].href; |
|||
// console.log("*", linkhref); |
|||
if (linkhref == loaded_href) { |
|||
links[i].classList.add("active"); |
|||
} else { |
|||
links[i].classList.remove("active"); |
|||
} |
|||
} |
|||
}); |
|||
overlay.addEventListener("mouseenter", function () { |
|||
overlay.classList.add("open"); |
|||
}, false); |
|||
overlay.addEventListener("mouseleave", function () { |
|||
overlay.classList.remove("open"); |
|||
}, false); |
|||
|
|||
})() |
|||
</script> |
|||
</body> |
|||
</html> |
Loading…
Reference in new issue