plutopluto

git clone https://git.ce9e.org/plutopluto.git

commit
3bb7970b8d79760fdfab596d0662917b68b2b5ae
parent
a54e78aa6109ece5ffb529ee8393acdf48f8d871
Author
Tobias Bengfort <tobias.bengfort@posteo.de>
Date
2023-07-02 07:39
wip

Diffstat

M plutopluto/__init__.py 68 ++++++++++++++-----------------------------------------------
M plutopluto/index.html 3 ++-
M plutopluto/static/plutopluto.js 11 ++++++-----
M plutopluto/static/style.css 3 ++-

4 files changed, 25 insertions, 60 deletions


diff --git a/plutopluto/__init__.py b/plutopluto/__init__.py

@@ -19,51 +19,13 @@ __version__ = '1.2.0'
   19    19 app = Flask(__name__)
   20    20 
   21    21 
   22    -1 def clean_html(s):
   23    -1     """Strip possibly dangerous HTML."""
   24    -1 
   25    -1     allowed_tags = [
   26    -1         'p',
   27    -1         'a',
   28    -1         'ul',
   29    -1         'ol',
   30    -1         'li',
   31    -1         'blockquote',
   32    -1         'em',
   33    -1         'strong',
   34    -1         'img',
   35    -1         'video',
   36    -1         'h1',
   37    -1         'h2',
   38    -1         'h3',
   39    -1         'h4',
   40    -1         'h5',
   41    -1         'h6',
   42    -1         'pre',
   43    -1         'code',
   44    -1         'hr',
   45    -1         'table',
   46    -1         'tr',
   47    -1         'td',
   48    -1         'th',
   49    -1         'details',
   50    -1         'summary',
   51    -1     ]
   52    -1     allowed_attrs = ['href', 'src', 'alt', 'title']
   53    -1 
   54    -1     tree = BeautifulSoup(s)
   55    -1 
   56    -1     for tag in tree.find_all():
   57    -1         if tag.name not in allowed_tags:
   58    -1             if tag.name in ['script']:
   59    -1                 tag.extract()
   60    -1             else:
   61    -1                 tag.hidden = True
   62    -1         else:
   63    -1             for attr in set(tag.attrs) - set(allowed_attrs):
   64    -1                 del tag.attrs[attr]
   65    -1 
   66    -1     return str(tree)
   -1    22 def linebreaks(text):
   -1    23     html = (
   -1    24         text
   -1    25         .replace('\n\n', '</p><p>')
   -1    26         .replace('\n', '<br>')
   -1    27     )
   -1    28     return '<p>' + html + '</p>'
   67    29 
   68    30 
   69    31 @functools.lru_cache
@@ -84,16 +46,16 @@ def parse(url):
   84    46         d['title'] = item.get('title')
   85    47         d['link'] = item.get('link')
   86    48         d['source'] = feed.feed.get('title')
   -1    49         d['source_link'] = feed.feed.get('link')
   -1    50         d['content'] = item.get('description', '')
   -1    51         if '<' not in d['content']:
   -1    52             d['content'] = linebreaks(d['content'])
   87    53         if 'youtube' in url:
   88    -1             template = u'<img alt="%s" src="%s" />\n<div>%s</div>'
   89    -1             d['content'] = clean_html(template % (
   90    -1                 item['media_content'][0]['url'],
   -1    54             thumbnail = '<a href="%s"><img alt="" src="%s" /></a>' % (
   -1    55                 d['link'],
   91    56                 item['media_thumbnail'][0]['url'],
   92    -1                 item['media_description']))
   93    -1         elif 'content' in item:
   94    -1             d['content'] = clean_html(item['content'][0]['value'])
   95    -1         else:
   96    -1             d['content'] = clean_html(item.get('description'))
   -1    57             )
   -1    58             d['content'] = thumbnail + d['content']
   97    59         return d
   98    60 
   99    61     return {

diff --git a/plutopluto/index.html b/plutopluto/index.html

@@ -13,11 +13,12 @@
   13    13 	<template>
   14    14 		<article>
   15    15 			<header>
   16    -1 				<a class="source u-bold" href="{{link}}" title="{{title}}">{{source}}</a>
   -1    16 				<a class="source u-bold" href="{{source_link}}">{{source}}</a>
   17    17 				<span class="meta">
   18    18 					&middot; Posted on <a href="{{link}}">{{dt}}</a>
   19    19 				</span>
   20    20 			</header>
   -1    21 			<h2 class="title"><a href="{{link}}">{{title}}</a></h2>
   21    22 			{{{content}}}
   22    23 		</article>
   23    24 	</template>

diff --git a/plutopluto/static/plutopluto.js b/plutopluto/static/plutopluto.js

@@ -46,11 +46,12 @@ var appendEntries = function(entries) {
   46    46 		var li = document.createElement('li');
   47    47 		li.className = 'post';
   48    48 		li.innerHTML = template.innerHTML
   49    -1 			.replace('{{source}}', escapeHTML(entry.source))
   50    -1 			.replace('{{link}}', escapeHTML(entry.link))
   51    -1 			.replace('{{title}}', escapeHTML(entry.title))
   52    -1 			.replace('{{dt}}', escapeHTML(formatDate(entry.dt)))
   53    -1 			.replace('{{{content}}}', entry.content);
   -1    49 			.replaceAll('{{source}}', escapeHTML(entry.source))
   -1    50 			.replaceAll('{{source_link}}', escapeHTML(entry.source_link))
   -1    51 			.replaceAll('{{link}}', escapeHTML(entry.link))
   -1    52 			.replaceAll('{{title}}', escapeHTML(entry.title))
   -1    53 			.replaceAll('{{dt}}', escapeHTML(formatDate(entry.dt)))
   -1    54 			.replaceAll('{{{content}}}', entry.content);
   54    55 		stream.append(li);
   55    56 	});
   56    57 };

diff --git a/plutopluto/static/style.css b/plutopluto/static/style.css

@@ -76,7 +76,8 @@ hr {
   76    76 	font-size: small;
   77    77 }
   78    78 
   79    -1 .post header a {
   -1    79 .post header a,
   -1    80 .post .title a {
   80    81 	color: inherit;
   81    82 	text-decoration: none;
   82    83 }