- commit
- ba6a83b5e41f3144642580a6e8fd0409c4ee1e78
- parent
- 3bb7970b8d79760fdfab596d0662917b68b2b5ae
- Author
- Tobias Bengfort <tobias.bengfort@posteo.de>
- Date
- 2023-07-02 07:39
Revert "wip" This reverts commit 3bb7970b8d79760fdfab596d0662917b68b2b5ae.
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, 60 insertions, 25 deletions
diff --git a/plutopluto/__init__.py b/plutopluto/__init__.py
@@ -19,13 +19,51 @@ __version__ = '1.2.0' 19 19 app = Flask(__name__) 20 20 21 2122 -1 def linebreaks(text):23 -1 html = (24 -1 text25 -1 .replace('\n\n', '</p><p>')26 -1 .replace('\n', '<br>')27 -1 )28 -1 return '<p>' + html + '</p>'-1 22 def clean_html(s): -1 23 """Strip possibly dangerous HTML.""" -1 24 -1 25 allowed_tags = [ -1 26 'p', -1 27 'a', -1 28 'ul', -1 29 'ol', -1 30 'li', -1 31 'blockquote', -1 32 'em', -1 33 'strong', -1 34 'img', -1 35 'video', -1 36 'h1', -1 37 'h2', -1 38 'h3', -1 39 'h4', -1 40 'h5', -1 41 'h6', -1 42 'pre', -1 43 'code', -1 44 'hr', -1 45 'table', -1 46 'tr', -1 47 'td', -1 48 'th', -1 49 'details', -1 50 'summary', -1 51 ] -1 52 allowed_attrs = ['href', 'src', 'alt', 'title'] -1 53 -1 54 tree = BeautifulSoup(s) -1 55 -1 56 for tag in tree.find_all(): -1 57 if tag.name not in allowed_tags: -1 58 if tag.name in ['script']: -1 59 tag.extract() -1 60 else: -1 61 tag.hidden = True -1 62 else: -1 63 for attr in set(tag.attrs) - set(allowed_attrs): -1 64 del tag.attrs[attr] -1 65 -1 66 return str(tree) 29 67 30 68 31 69 @functools.lru_cache @@ -46,16 +84,16 @@ def parse(url): 46 84 d['title'] = item.get('title') 47 85 d['link'] = item.get('link') 48 86 d['source'] = feed.feed.get('title')49 -1 d['source_link'] = feed.feed.get('link')50 -1 d['content'] = item.get('description', '')51 -1 if '<' not in d['content']:52 -1 d['content'] = linebreaks(d['content'])53 87 if 'youtube' in url:54 -1 thumbnail = '<a href="%s"><img alt="" src="%s" /></a>' % (55 -1 d['link'],-1 88 template = u'<img alt="%s" src="%s" />\n<div>%s</div>' -1 89 d['content'] = clean_html(template % ( -1 90 item['media_content'][0]['url'], 56 91 item['media_thumbnail'][0]['url'],57 -1 )58 -1 d['content'] = thumbnail + d['content']-1 92 item['media_description'])) -1 93 elif 'content' in item: -1 94 d['content'] = clean_html(item['content'][0]['value']) -1 95 else: -1 96 d['content'] = clean_html(item.get('description')) 59 97 return d 60 98 61 99 return {
diff --git a/plutopluto/index.html b/plutopluto/index.html
@@ -13,12 +13,11 @@ 13 13 <template> 14 14 <article> 15 15 <header>16 -1 <a class="source u-bold" href="{{source_link}}">{{source}}</a>-1 16 <a class="source u-bold" href="{{link}}" title="{{title}}">{{source}}</a> 17 17 <span class="meta"> 18 18 · Posted on <a href="{{link}}">{{dt}}</a> 19 19 </span> 20 20 </header>21 -1 <h2 class="title"><a href="{{link}}">{{title}}</a></h2>22 21 {{{content}}} 23 22 </article> 24 23 </template>
diff --git a/plutopluto/static/plutopluto.js b/plutopluto/static/plutopluto.js
@@ -46,12 +46,11 @@ var appendEntries = function(entries) {
46 46 var li = document.createElement('li');
47 47 li.className = 'post';
48 48 li.innerHTML = template.innerHTML
49 -1 .replaceAll('{{source}}', escapeHTML(entry.source))
50 -1 .replaceAll('{{source_link}}', escapeHTML(entry.source_link))
51 -1 .replaceAll('{{link}}', escapeHTML(entry.link))
52 -1 .replaceAll('{{title}}', escapeHTML(entry.title))
53 -1 .replaceAll('{{dt}}', escapeHTML(formatDate(entry.dt)))
54 -1 .replaceAll('{{{content}}}', entry.content);
-1 49 .replace('{{source}}', escapeHTML(entry.source))
-1 50 .replace('{{link}}', escapeHTML(entry.link))
-1 51 .replace('{{title}}', escapeHTML(entry.title))
-1 52 .replace('{{dt}}', escapeHTML(formatDate(entry.dt)))
-1 53 .replace('{{{content}}}', entry.content);
55 54 stream.append(li);
56 55 });
57 56 };
diff --git a/plutopluto/static/style.css b/plutopluto/static/style.css
@@ -76,8 +76,7 @@ hr {
76 76 font-size: small;
77 77 }
78 78
79 -1 .post header a,
80 -1 .post .title a {
-1 79 .post header a {
81 80 color: inherit;
82 81 text-decoration: none;
83 82 }