From a506d9d18fe98cf667e45566b3f7be3dd47bbdd3 Mon Sep 17 00:00:00 2001 From: Peter Molnar Date: Wed, 28 Mar 2018 14:19:14 +0000 Subject: [PATCH] - added special templates option per category - changed layout for journal/articles: single page, per year grouping - adaptimg wide view --- nasg.py | 111 ++++++++++++++++++---- shared.py | 42 --------- templates/Category.html | 8 +- templates/Category_article.html | 49 ++++++++++ templates/Category_journal.html | 1 + templates/Category_photo.html | 86 ----------------- templates/Comment.html | 44 ++++----- templates/Singular.html | 42 ++++++--- templates/Singular_title.html | 5 +- templates/WebImage.html | 12 +-- templates/block_footer.html | 7 +- templates/block_header_close.html | 11 +-- templates/style-dark.css | 151 ++++++++++++++++++------------ templates/symbols.svg | 6 -- 14 files changed, 310 insertions(+), 265 deletions(-) create mode 100644 templates/Category_article.html create mode 120000 templates/Category_journal.html delete mode 100644 templates/Category_photo.html diff --git a/nasg.py b/nasg.py index 9ac75dc..ce2448c 100644 --- a/nasg.py +++ b/nasg.py @@ -196,9 +196,17 @@ class Category(NoDupeContainer): def __init__(self, name=''): self.name = name + self.topics = NoDupeContainer() super().__init__() def append(self, post): + if len(post.tags) == 1: + topic = post.tags[0] + if topic not in self.topics: + t = NoDupeContainer() + self.topics.append(topic, t) + t = self.topics[topic] + t.append(post.pubtime, post) return super().append(post.pubtime, post) @property @@ -222,6 +230,19 @@ class Category(NoDupeContainer): shared.config.get('common', 'domain') ]) + @property + def is_altrender(self): + return os.path.exists( + os.path.join( + shared.config.get('dirs', 'tmpl'), + "%s_%s.html" % ( + self.__class__.__name__, + self.name + ) + ) + ) + + @property def url(self): if self.name: @@ -253,7 +274,70 @@ class Category(NoDupeContainer): os.makedirs(x) return x - def write_feed(self, posttmpls): + def write_html(self, path, content): + with open(path, 'wt') as out: + logging.debug('writing file %s', path) + out.write(content) + os.utime(path, (self.mtime, self.mtime)) + + + async def render(self): + if self.is_altrender: + self.render_onepage() + else: + self.render_paginated() + self.render_feed() + + def render_onepage(self): + years = {} + for k in list(sorted(self.data.keys(), reverse=True)): + post = self.data[k] + year = int(arrow.get(post.pubtime).format('YYYY')) + if year not in years: + years.update({year: []}) + years[year].append(post.tmplvars) + + tmplvars = { + 'taxonomy': { + 'title': self.title, + 'name': self.name, + 'lastmod': arrow.get(self.mtime).format( + shared.ARROWFORMAT['rcf'] + ), + 'url': self.url, + 'feed': "%s/%s/" % ( + self.url, + shared.config.get('site', 'feed') + ), + }, + 'site': shared.site, + 'by_year': years + } + dirname = self.path_paged(1) + o = os.path.join(dirname, self.indexfile) + logging.info( + "Rendering category %s to %s", + self.name, + o + ) + tmplfile = "%s_%s.html" % ( + self.__class__.__name__, + self.name + ) + r = shared.j2.get_template(tmplfile).render(tmplvars) + self.write_html(o, r) + + + def render_feed(self): + start = 0 + end = int(shared.config.getint('display', 'pagination')) + posttmpls = [ + self.data[k].tmplvars + for k in list(sorted( + self.data.keys(), + reverse=True + ))[start:end] + ] dirname = self.path_paged(1, feed=True) o = os.path.join(dirname, self.feedfile) logging.info( @@ -311,13 +395,7 @@ class Category(NoDupeContainer): ) logging.info(r.text) - def write_html(self, path, content): - with open(path, 'wt') as out: - logging.debug('writing file %s', path) - out.write(content) - os.utime(path, (self.mtime, self.mtime)) - - async def render(self): + def render_paginated(self): pagination = shared.config.getint('display', 'pagination') pages = ceil(len(self.data) / pagination) page = 1 @@ -367,11 +445,6 @@ class Category(NoDupeContainer): tmplfile = "%s.html" % (self.__class__.__name__) r = shared.j2.get_template(tmplfile).render(tmplvars) self.write_html(o, r) - - # render feed - if page == 1: - self.write_feed(posttmpls) - # inc. page counter page = page + 1 @@ -633,10 +706,6 @@ class Singular(object): def html(self): html = "%s" % (self.body) - ## add photo - #if self.photo: - #html = "%s\n%s" % (str(self.photo), html) - return shared.Pandoc().convert(html) @property @@ -1455,6 +1524,7 @@ def build(): for name, c in collector_categories: if not c.is_uptodate or shared.config.getboolean('params', 'force'): worker.append(c.render()) + # TODO move ping to separate function and add it as a task # TODO separate an aiohttpworker? @@ -1471,8 +1541,13 @@ def build(): src = shared.config.get('dirs', 'static') for item in os.listdir(src): s = os.path.join(src, item) + stime = os.path.getmtime(s) d = os.path.join(shared.config.get('common', 'build'), item) - if not os.path.exists(d) or shared.config.getboolean('params', 'force'): + dtime = 0 + if os.path.exists(d): + dtime = os.path.getmtime(d) + + if not os.path.exists(d) or shared.config.getboolean('params', 'force') or dtime < stime: logging.debug("copying static file %s to %s", s, d) shutil.copy2(s, d) if '.html' in item: diff --git a/shared.py b/shared.py index d1a6dbc..7accf6c 100644 --- a/shared.py +++ b/shared.py @@ -671,48 +671,6 @@ def __setup_sitevars(): SiteVars.update({'tips': tips}) return SiteVars - -#def notify(msg): - - ### telegram notification, if set - ##if not config.has_section('api_telegram'): - ##return - - ##url = "https://api.telegram.org/bot%s/sendMessage" % ( - ##config.get('api_telegram', 'api_token') - ##) - ##data = { - ##'chat_id': config.get('api_telegram', 'chat_id'), - ##'text': msg - ##} - ### fire and forget - ##try: - ##requests.post(url, data=data) - ##except BaseException: - ##pass - - #headers = { - #'Subject': 'notification from NASG', - #'Content-Type': 'text/plain; charset=utf-8', - #'Content-Disposition': 'inline', - #'Content-Transfer-Encoding': '8bit', - #'From': 'nasg@%s' % (socket.getfqdn()), - #'To': config.get('author', 'email'), - #'Date': arrow.now().strftime('%a, %d %b %Y %H:%M:%S %Z'), - #} - - ## create the message - #mail = '' - #for key, value in headers.items(): - #mail += "%s: %s\n" % ( key, value ) - - ## add contents - #mail += "\n%s\n" % ( msg ) - - #s = smtplib.SMTP( '127.0.0.1', 25 ) - #s.sendmail( headers['From'], headers['To'], msg.encode("utf8") ) - #s.quit() - ARROWFORMAT = { 'iso': 'YYYY-MM-DDTHH:mm:ssZ', 'display': 'YYYY-MM-DD HH:mm', diff --git a/templates/Category.html b/templates/Category.html index db25eab..d3dead6 100644 --- a/templates/Category.html +++ b/templates/Category.html @@ -8,14 +8,16 @@

{{ taxonomy.name }}

{% for post in posts %} -
+

{% include 'Singular_title.html' %}

@@ -25,7 +27,7 @@
{{ post.summary }} - + […]
diff --git a/templates/Category_article.html b/templates/Category_article.html new file mode 100644 index 0000000..5e1d62b --- /dev/null +++ b/templates/Category_article.html @@ -0,0 +1,49 @@ +{% include 'block_header_open.html' %} + {{ taxonomy.title }} + + + +{% include 'block_header_close.html' %} + +
+ + +

{{ taxonomy.name }}

+ +{% for year in by_year.keys()|sort(reverse=True) %} +

{{ year }}

+ {% for post in by_year[year]|sort(attribute='pubtime',reverse=True) %} +
+
+

{% include 'Singular_title.html' %}

+
+ + {% if post.summary %} +
+ {{ post.summary }} + + […] + +
+
+ {% else %} +
+ {% if post.photo %} + {{ post.photo }} + {% endif %} + {{ post.html }} +
+ {% endif %} +
+ {% endfor %} +{% endfor %} +
+ +{% include 'block_footer.html' %} diff --git a/templates/Category_journal.html b/templates/Category_journal.html new file mode 120000 index 0000000..75fb47a --- /dev/null +++ b/templates/Category_journal.html @@ -0,0 +1 @@ +Category_article.html \ No newline at end of file diff --git a/templates/Category_photo.html b/templates/Category_photo.html deleted file mode 100644 index 15f9731..0000000 --- a/templates/Category_photo.html +++ /dev/null @@ -1,86 +0,0 @@ -{% include 'block_header_open.html' %} - {{ taxonomy.title }} - - - -{% include 'block_header_close.html' %} - -
- - - {% for post in posts %} - {{ post.photo }} - {% endfor %} -
- -{% if taxonomy.total > 1 %} - - {# based on: http://dev.dbl-a.com/symfony-2-0/symfony2-and-twig-pagination/ #} - - -{% endif %} - -{% include 'block_footer.html' %} diff --git a/templates/Comment.html b/templates/Comment.html index 5c55965..cd2e9a7 100644 --- a/templates/Comment.html +++ b/templates/Comment.html @@ -1,26 +1,28 @@
  • - - - - - {% if comment.author.url %} - - {{ comment.author.name }} - - {% else %} - {{ comment.author.name }} - {% endif %} - + + + + + {% if comment.author.url %} + + {{ comment.author.name }} + + {% else %} + {{ comment.author.name }} + {% endif %} + {% if 'webmention' == comment.type %} - - - {{ comment.source }} - + + + + + {{ comment.source }} + {% else %} - - {{ comment.type }} - + + {{ comment.type }} + {% endif %}
  • diff --git a/templates/Singular.html b/templates/Singular.html index 9da2aea..8bfc78d 100644 --- a/templates/Singular.html +++ b/templates/Singular.html @@ -15,12 +15,6 @@

    {% include 'Singular_title.html' %}

    - {% if 'article' == post.category and post.age >= 2 %} -

    WARNING: this entry was published at {{ post.pubdate }}.
    It might be outdated.

    - {% endif %} - {% for url in post.syndicate %} - - {% endfor %}
    {% if post.summary %} @@ -52,15 +46,21 @@

    {% if post.licence.text == 'CC BY 4.0' %} CC BY 4.0 - + + + Licensed under Creative Commons Attribution 4.0 International. You are free to share or republish, even if modified, if you link back here and indicate the modifications, even for commercial use. {% elif post.licence.text == 'CC BY-NC 4.0' %} CC BY-NC 4.0 - + + + Licensed under Creative Commons Attribution-NonCommercial 4.0 International. You are free to share or republish, even if modified, if you link back here and indicate the modifications, for non commercial use. For commercial use please contact the author. {% else %} CC BY-NC-ND 4.0 - + + + Licensed under Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International. You are free to share if you link back here for non commercial use, but you can't publish any altered versions of it. For commercial use please contact the author. {% endif %}

    @@ -84,7 +84,9 @@ {{ data.value }} - + + + with {{ data.label }} @@ -93,10 +95,26 @@ +{% if post.syndicate|length %} +