Add :reader
Uses wheezy.template, which is said to be fast and light. Provided template file is really basic, custom css suggested.master
parent
814ff46fbd
commit
f90958149e
|
@ -10,6 +10,13 @@ from StringIO import StringIO
|
|||
import json
|
||||
import csv
|
||||
|
||||
try:
|
||||
from wheezy.template.engine import Engine
|
||||
from wheezy.template.loader import DictLoader
|
||||
from wheezy.template.ext.core import CoreExtension
|
||||
except ImportError:
|
||||
Engine = DictLoader = CoreExtension = None
|
||||
|
||||
json.encoder.c_make_encoder = None
|
||||
|
||||
try:
|
||||
|
@ -353,6 +360,15 @@ class FeedParser(FeedBase):
|
|||
out.seek(0)
|
||||
return out.read()
|
||||
|
||||
def tohtml(self):
|
||||
if DictLoader is None:
|
||||
log('dep wheezy.template needed')
|
||||
|
||||
loader = DictLoader({'reader': open('reader.html.template').read()})
|
||||
engine = Engine(loader=loader, extensions=[CoreExtension()])
|
||||
template = engine.get_template('reader')
|
||||
return template.render({'feed':self}).encode('utf-8')
|
||||
|
||||
class FeedParserRSS(FeedParser):
|
||||
"""
|
||||
RSS Parser
|
||||
|
|
|
@ -644,6 +644,8 @@ def After(rss, options):
|
|||
return rss.tojson()
|
||||
elif options.csv:
|
||||
return rss.tocsv()
|
||||
elif options.reader:
|
||||
return rss.tohtml()
|
||||
else:
|
||||
return rss.tostring(xml_declaration=True, encoding='UTF-8')
|
||||
|
||||
|
@ -692,7 +694,7 @@ def cgi_app(environ, start_response):
|
|||
headers['status'] = '200 OK'
|
||||
headers['etag'] = '"%s"' % int(time.time())
|
||||
|
||||
if options.html:
|
||||
if options.html or options.reader:
|
||||
headers['content-type'] = 'text/html'
|
||||
elif options.debug or options.txt:
|
||||
headers['content-type'] = 'text/plain'
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
@require(feed)
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>@feed.title – via morss</title>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="description" content="@feed.desc (via morss)" />
|
||||
<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0;" />
|
||||
<link rel="stylesheet" href="https://thisisdallas.github.io/Simple-Grid/simpleGrid.css" />
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div id="header">
|
||||
<h1>@feed.title</h1>
|
||||
@if feed.desc:
|
||||
<h2>@feed.desc</h2>
|
||||
@end
|
||||
<p>- via morss</p>
|
||||
</div>
|
||||
|
||||
<div id="content" class="grid grid-pad">
|
||||
@for item in feed.items:
|
||||
<div class="col-1-3">
|
||||
<div class="item">
|
||||
<a class="title link" href="@item.link" target="_blank">@item.title</a>
|
||||
<div class="article">@item.content</div>
|
||||
</div>
|
||||
</div>
|
||||
@end
|
||||
</div>
|
||||
|
||||
<script>
|
||||
var items = document.getElementsByClassName('item')
|
||||
for (var i in items)
|
||||
items[i].onclick = function()
|
||||
{
|
||||
this.classList.toggle('active')
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue