diff --git a/archive.py b/archive.py index 03f8be9..e69430a 100644 --- a/archive.py +++ b/archive.py @@ -3,11 +3,11 @@ # vim: set fileencoding=utf-8 : __author__ = "Peter Molnar" -__copyright__ = "Copyright 2017, Peter Molnar" +__copyright__ = "Copyright 2018, Peter Molnar" __license__ = "GPLv3" -__version__ = "2.0" +__version__ = "2.2.0" __maintainer__ = "Peter Molnar" -__email__ = "hello@petermolnar.eu" +__email__ = "mail@petermolnar.net" __status__ = "Production" """ diff --git a/envelope.py b/envelope.py index bca89f9..bd73b62 100644 --- a/envelope.py +++ b/envelope.py @@ -1,3 +1,35 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +# vim: set fileencoding=utf-8 : + +__author__ = "Peter Molnar" +__copyright__ = "Copyright 2017-2018, Peter Molnar" +__license__ = "GPLv3" +__version__ = "2.1.0" +__maintainer__ = "Peter Molnar" +__email__ = "mail@petermolnar.net" +__status__ = "Production" + +""" + fancy email module of NASG + Copyright (C) 2017-2018 Peter Molnar + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +""" + + from email.mime.multipart import MIMEMultipart from email.mime.text import MIMEText from email.mime.image import MIMEImage diff --git a/nasg.py b/nasg.py index b602bd9..859cc82 100644 --- a/nasg.py +++ b/nasg.py @@ -5,9 +5,9 @@ __author__ = "Peter Molnar" __copyright__ = "Copyright 2017-2018, Peter Molnar" __license__ = "GPLv3" -__version__ = "2.1.0" +__version__ = "2.2.0" __maintainer__ = "Peter Molnar" -__email__ = "hello@petermolnar.eu" +__email__ = "mail@petermolnar.net" __status__ = "Production" """ @@ -194,9 +194,10 @@ class Category(NoDupeContainer): pagedir = 'page' taxonomy = 'category' - def __init__(self, name=''): + def __init__(self, name='', is_front=False): self.name = name self.topics = NoDupeContainer() + self.is_front = is_front super().__init__() def append(self, post): @@ -297,6 +298,7 @@ class Category(NoDupeContainer): tmplvars = { 'taxonomy': { + 'add_welcome': self.is_front, 'title': self.title, 'name': self.name, 'lastmod': arrow.get(self.mtime).format( @@ -364,16 +366,23 @@ class Category(NoDupeContainer): fg.updated(arrow.get(self.mtime).to('utc').datetime) for p in reversed(posttmpls): - link = '%s/%s' % (shared.site.get('url'), p.get('slug')) + link = '%s/%s/' % (shared.site.get('url'), p.get('slug')) dt = arrow.get(p.get('pubtime')).to('utc') + content = p.get('html') + if p.get('photo'): + content = "%s\n\n%s" % (p.get('photo'), content) + fe = fg.add_entry() fe.id(link) - fe.link(href='%s/' % (link)) + fe.link(href=link) fe.title(p.get('title')) fe.published(dt.datetime) fe.updated(dt.datetime) - fe.content(content=p.get('html'), type='CDATA') + fe.content( + content, + type='CDATA' + ) fe.rights('%s %s %s' % ( dt.format('YYYY'), shared.site.get('author').get('name'), @@ -383,6 +392,9 @@ class Category(NoDupeContainer): with open(o, 'wb') as f: f.write(fg.atom_str(pretty=True)) + #with open(o.replace('.xml', '.rss'), 'wb') as f: + #f.write(fg.rss_str(pretty=True)) + # ping pubsub r = requests.post( shared.site.get('websub').get('hub'), @@ -397,7 +409,12 @@ class Category(NoDupeContainer): pagination = shared.config.getint('display', 'pagination') pages = ceil(len(self.data) / pagination) page = 1 + + while page <= pages: + add_welcome = False + if (self.is_front and page == 1): + add_welcome = True # list relevant post templates start = int((page - 1) * pagination) end = int(start + pagination) @@ -413,6 +430,7 @@ class Category(NoDupeContainer): # is overcomplicated tmplvars = { 'taxonomy': { + 'add_welcome': add_welcome, 'title': self.title, 'name': self.name, 'page': page, @@ -489,6 +507,8 @@ class Singular(object): wdb.finish() def queue_webmentions(self): + if self.is_future: + return wdb = shared.WebmentionQueue() for target in self.urls_to_ping: if not wdb.exists(self.url, target, self.published): @@ -727,6 +747,10 @@ class Singular(object): return "RE: %s" % self.is_reply return self.published.format(shared.ARROWFORMAT['display']) + @property + def review(self): + return self.meta.get('review', False) + @property def summary(self): s = self.meta.get('summary', '') @@ -785,12 +809,20 @@ class Singular(object): 'reactions': self.reactions, 'syndicate': self.syndicate, 'tags': self.tags, - 'photo': False + 'photo': False, + 'enclosure': False, + 'review': self.review } if self.photo: self._tmplvars.update({ - 'photo': str(self.photo) + 'photo': str(self.photo), + 'enclosure': { + 'mime': self.photo.mime_type, + 'size': self.photo.mime_size, + 'url': self.photo.href + } }) + return self._tmplvars async def render(self): @@ -844,6 +876,16 @@ class WebImage(object): 'tags': list(set(self.meta.get('Subject', []))), } + @property + def mime_type(self): + return str(self.meta.get('MIMEType', 'image/jpeg')) + + @property + def mime_size(self): + if not self.is_downsizeable: + return int(os.path.getsize(self.fpath)) + return int(self.sizes[-1][1]['fsize']) + @property def href(self): if len(self.target): @@ -996,7 +1038,8 @@ class WebImage(object): 'crop', size, fallback=False - ) + ), + 'fsize': os.path.getsize(fpath) } )) return sorted(sizes, reverse=False) @@ -1175,7 +1218,6 @@ class WebImage(object): height ) - @property def tmplvars(self): src_width, src_height = self.src_size @@ -1481,7 +1523,7 @@ def build(): sdb = shared.SearchDB() magic = MagicPHP() - collector_front = Category() + collector_front = Category(is_front=True) collector_categories = NoDupeContainer() sitemap = {} diff --git a/router.py b/router.py index ee989e4..554db49 100644 --- a/router.py +++ b/router.py @@ -5,9 +5,9 @@ __author__ = "Peter Molnar" __copyright__ = "Copyright 2017-2018, Peter Molnar" __license__ = "GPLv3" -__version__ = "2.1.0" +__version__ = "2.2.0" __maintainer__ = "Peter Molnar" -__email__ = "hello@petermolnar.eu" +__email__ = "mail@petermolnar.net" __status__ = "Production" """ diff --git a/shared.py b/shared.py index 6180b48..0ef4399 100644 --- a/shared.py +++ b/shared.py @@ -5,9 +5,9 @@ __author__ = "Peter Molnar" __copyright__ = "Copyright 2017-2018, Peter Molnar" __license__ = "GPLv3" -__version__ = "2.1.0" +__version__ = "2.2.0" __maintainer__ = "Peter Molnar" -__email__ = "hello@petermolnar.eu" +__email__ = "mail@petermolnar.net" __status__ = "Production" """ @@ -431,6 +431,7 @@ class SearchDB(BaseDB): return False def search_by_query(self, query): + logging.info("query is: %s", query) ret = {} cursor = self.db.cursor() cursor.execute('''SELECT diff --git a/templates/Category.html b/templates/Category.html index d08f15e..a8f3111 100644 --- a/templates/Category.html +++ b/templates/Category.html @@ -5,13 +5,21 @@ {% include 'block_header_close.html' %} +{% if taxonomy.add_welcome %} + +{% endif %} +
diff --git a/templates/Category_article.html b/templates/Category_article.html index d2467b0..02bec3b 100644 --- a/templates/Category_article.html +++ b/templates/Category_article.html @@ -11,7 +11,7 @@ - Atom feed + XML feed

diff --git a/templates/Comment.html b/templates/Comment.html index cd2e9a7..e3d1aa8 100644 --- a/templates/Comment.html +++ b/templates/Comment.html @@ -1,9 +1,12 @@
  • - - +{% if 'webmention' != comment.type %} + + {{ comment.type }} +{% endif %} + from {% if comment.author.url %} @@ -12,7 +15,7 @@ {% else %} {{ comment.author.name }} {% endif %} - +
    {% if 'webmention' == comment.type %} @@ -20,9 +23,5 @@
    {{ comment.source }} -{% else %} - - {{ comment.type }} - {% endif %}
  • diff --git a/templates/Singular.html b/templates/Singular.html index 1b53143..d0e3ea5 100644 --- a/templates/Singular.html +++ b/templates/Singular.html @@ -17,6 +17,23 @@

    {% include 'Singular_title.html' %}

    +{% if post.review %} +
    +

    Review summary

    +

    + {{ post.review.title }} +

    +

    + + {{ post.review.rating }} + out of + 5 + +

    +

    {{ post.review.summary }}

    +
    +{% endif %} + {% if post.summary %}
    {{ post.summary }} @@ -34,66 +51,72 @@
    - {% if post.syndicate|length %}
    diff --git a/templates/WebImage.html b/templates/WebImage.html index 6680c29..fa8f206 100644 --- a/templates/WebImage.html +++ b/templates/WebImage.html @@ -3,7 +3,7 @@ {{ photo.alt }} {% if photo.target %}{% endif %}
    -{{ photo.alt }}{% if photo.is_photo %} - photo by {{ photo.author }} +{{ photo.alt }}{% if photo.is_photo %} - photo by {{ photo.author }}
    {% if photo.exif.camera %}
    Camera
    diff --git a/templates/archiveindex.html b/templates/archiveindex.html deleted file mode 100644 index 1d9a579..0000000 --- a/templates/archiveindex.html +++ /dev/null @@ -1,23 +0,0 @@ -{% include 'block_header_open.html' %} -{% include 'block_header_close.html' %} - -
    -{% for tname, posts in taxonomies %} -
    - {{ tname }} [{{ posts|length }}] -
      - {% for post in posts %} -
    1. - {{ post.title }} -
      - - {{ post.url }} - -
    2. - {% endfor %} -
    -
    -{% endfor %} -
    - -{% include 'block_footer.html' %} diff --git a/templates/block_footer.html b/templates/block_footer.html index 90fe33e..b2af476 100644 --- a/templates/block_footer.html +++ b/templates/block_footer.html @@ -1,13 +1,13 @@