- CSS fixes and simplifications

- prism.js inlined (only for entries with code blocks)
- pandoc is a subclass is str now
- added 'nasg' logger
- minor bugfixes
This commit is contained in:
Peter Molnar 2018-08-04 09:30:26 +01:00
parent d3fbf2e51f
commit 5ec437de8f
9 changed files with 1933 additions and 142 deletions

32
nasg.py
View file

@ -13,7 +13,6 @@ import time
from functools import partial from functools import partial
import re import re
import imghdr import imghdr
import logging
import asyncio import asyncio
import sqlite3 import sqlite3
import json import json
@ -86,7 +85,7 @@ class MarkdownDoc(object):
@cached_property @cached_property
def _parsed(self): def _parsed(self):
with open(self.fpath, mode='rt') as f: with open(self.fpath, mode='rt') as f:
logging.debug('parsing YAML+MD file %s', self.fpath) settings.logger.debug('parsing YAML+MD file %s', self.fpath)
meta, txt = frontmatter.parse(f.read()) meta, txt = frontmatter.parse(f.read())
return(meta, txt) return(meta, txt)
@ -505,16 +504,16 @@ class Singular(MarkdownDoc):
'labels': settings.labels 'labels': settings.labels
}) })
if not os.path.isdir(self.renderdir): if not os.path.isdir(self.renderdir):
logging.info("creating directory: %s", self.renderdir) settings.logger.info("creating directory: %s", self.renderdir)
os.makedirs(self.renderdir) os.makedirs(self.renderdir)
with open(self.renderfile, 'wt') as f: with open(self.renderfile, 'wt') as f:
logging.info("rendering to %s", self.renderfile) settings.logger.info("rendering to %s", self.renderfile)
f.write(r) f.write(r)
class WebImage(object): class WebImage(object):
def __init__(self, fpath, mdimg, parent): def __init__(self, fpath, mdimg, parent):
logging.debug("loading image: %s", fpath) settings.logger.debug("loading image: %s", fpath)
self.mdimg = mdimg self.mdimg = mdimg
self.fpath = fpath self.fpath = fpath
self.parent = parent self.parent = parent
@ -715,7 +714,7 @@ class WebImage(object):
img = self._maybe_watermark(img) img = self._maybe_watermark(img)
for size, resized in self.resized_images: for size, resized in self.resized_images:
if not resized.exists or settings.args.get('regenerate'): if not resized.exists or settings.args.get('regenerate'):
logging.info( settings.logger.info(
"resizing image: %s to size %d", "resizing image: %s to size %d",
os.path.basename(self.fpath), os.path.basename(self.fpath),
size size
@ -832,7 +831,7 @@ class WebImage(object):
# this is to make sure pjpeg happens # this is to make sure pjpeg happens
with open(self.fpath, 'wb') as f: with open(self.fpath, 'wb') as f:
logging.info("writing %s", self.fpath) settings.logger.info("writing %s", self.fpath)
thumb.save(file=f) thumb.save(file=f)
@ -846,8 +845,7 @@ class AsyncWorker(object):
self._tasks.append(task) self._tasks.append(task)
def run(self): def run(self):
w = asyncio.wait(self._tasks, return_when=asyncio.FIRST_EXCEPTION) self._loop.run_until_complete(asyncio.wait(self._tasks))
self._loop.run_until_complete(w)
class IndexPHP(object): class IndexPHP(object):
@ -888,7 +886,7 @@ class IndexPHP(object):
'redirects': self.redirect 'redirects': self.redirect
}) })
with open(self.renderfile, 'wt') as f: with open(self.renderfile, 'wt') as f:
logging.info("rendering to %s", self.renderfile) settings.logger.info("rendering to %s", self.renderfile)
f.write(r) f.write(r)
@ -989,7 +987,7 @@ class Category(dict):
return True return True
def render_feed(self): def render_feed(self):
logging.info('rendering category "%s" ATOM feed', self.name) settings.logger.info('rendering category "%s" ATOM feed', self.name)
start = 0 start = 0
end = int(settings.site.get('pagination')) end = int(settings.site.get('pagination'))
@ -1040,7 +1038,7 @@ class Category(dict):
atom = os.path.join(dirname, 'index.xml') atom = os.path.join(dirname, 'index.xml')
with open(atom, 'wb') as f: with open(atom, 'wb') as f:
logging.info('writing file: %s', atom) settings.logger.info('writing file: %s', atom)
f.write(fg.atom_str(pretty=True)) f.write(fg.atom_str(pretty=True))
def render_page(self, pagenum=1, pages=1): def render_page(self, pagenum=1, pages=1):
@ -1188,7 +1186,7 @@ class Search(object):
'labels': settings.labels 'labels': settings.labels
}) })
with open(target, 'wt') as f: with open(target, 'wt') as f:
logging.info("rendering to %s", target) settings.logger.info("rendering to %s", target)
f.write(r) f.write(r)
class Sitemap(dict): class Sitemap(dict):
@ -1238,7 +1236,7 @@ def mkcomment(webmention):
} }
fm.content = webmention.get('data').get('content') fm.content = webmention.get('data').get('content')
with open(fpath, 'wt') as f: with open(fpath, 'wt') as f:
logging.info("saving webmention to %s", fpath) settings.logger.info("saving webmention to %s", fpath)
f.write(frontmatter.dumps(fm)) f.write(frontmatter.dumps(fm))
@ -1324,14 +1322,14 @@ def make():
) )
search.__exit__() search.__exit__()
search.render() worker.add(search.render())
for category in categories.values(): for category in categories.values():
worker.add(category.render()) worker.add(category.render())
worker.add(sitemap.render()) worker.add(sitemap.render())
worker.run() worker.run()
logging.info('worker finished') settings.logger.info('worker finished')
# copy static # copy static
staticfiles = [] staticfiles = []
@ -1351,7 +1349,7 @@ def make():
cp(e, t) cp(e, t)
end = int(round(time.time() * 1000)) end = int(round(time.time() * 1000))
logging.info('process took %d ms' % (end - start)) settings.logger.info('process took %d ms' % (end - start))
if __name__ == '__main__': if __name__ == '__main__':

View file

@ -1,44 +1,46 @@
import subprocess import subprocess
import logging import logging
def pandoc(text): class pandoc(str):
# TODO: cache? def __new__(cls, text):
# import hashlib # TODO: cache?
# print(hashlib.md5("whatever your string is".encode('utf-8')).hexdigest()) # import hashlib
# print(hashlib.md5("whatever your string is".encode('utf-8')).hexdigest())
""" Pandoc command line call with piped in- and output """ """ Pandoc command line call with piped in- and output """
cmd = ( cmd = (
'pandoc', 'pandoc',
'-o-', '-o-',
'--from=markdown+%s' % ( '--from=markdown+%s' % (
'+'.join([ '+'.join([
'footnotes', 'footnotes',
'pipe_tables', 'pipe_tables',
'raw_html', 'raw_html',
'definition_lists', 'definition_lists',
'backtick_code_blocks', 'backtick_code_blocks',
'fenced_code_attributes', 'fenced_code_attributes',
'shortcut_reference_links', 'shortcut_reference_links',
'lists_without_preceding_blankline', 'lists_without_preceding_blankline',
'autolink_bare_uris', 'autolink_bare_uris',
]) ])
), ),
'--to=html5', '--to=html5',
'--quiet', '--quiet',
'--no-highlight' '--no-highlight'
)
p = subprocess.Popen(
cmd,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
stdout, stderr = p.communicate(input=text.encode())
if stderr:
logging.warning(
"Error during pandoc covert:\n\t%s\n\t%s",
cmd,
stderr
) )
return stdout.decode('utf-8').strip() p = subprocess.Popen(
cmd,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
stdout, stderr = p.communicate(input=text.encode())
if stderr:
logging.warning(
"Error during pandoc covert:\n\t%s\n\t%s",
cmd,
stderr
)
r = stdout.decode('utf-8').strip()
return str.__new__(cls, r)

View file

@ -135,11 +135,24 @@ _parser.add_argument(
args = vars(_parser.parse_args()) args = vars(_parser.parse_args())
# remove the rest of the potential loggers loglevel = loglevels.get(args.get('loglevel'))
while len(logging.root.handlers) > 0:
logging.root.removeHandler(logging.root.handlers[-1])
logging.basicConfig( logger = logging.getLogger("nasg")
level=loglevels[args.get('loglevel')], logger.setLevel(loglevel)
format='%(asctime)s - %(levelname)s - %(message)s' console_handler = logging.StreamHandler()
) logger.addHandler(console_handler)
logging.getLogger('asyncio').setLevel(loglevel)
# remove the rest of the potential loggers
#while len(logging.root.handlers) > 0:
# logging.root.removeHandler(logging.root.handlers[-1])
# #fh = logging.FileHandler("live1.log")
# #formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
# #fh.setFormatter(formatter)
# #logger.addHandler(fh)
# logging.basicConfig(
# level=loglevels[],
# format='%(asctime)s - %(levelname)s - %(message)s'
# )

View file

@ -4,12 +4,16 @@
<meta name="description" content="{{ post.summary|e }}" /> <meta name="description" content="{{ post.summary|e }}" />
<link rel="canonical" href="{{ post.url }}" /> <link rel="canonical" href="{{ post.url }}" />
<link rel="license" href="https://creativecommons.org/licenses/4.0/{{ post.licence }}" /> <link rel="license" href="https://creativecommons.org/licenses/4.0/{{ post.licence }}" />
{% endblock %}
{% block prism %}
{% if post.has_code %} {% if post.has_code %}
<style media="all"> <style media="all">
{% include 'prism.css' %} {% include 'prism.css' %}
</style> </style>
<script src="{{ site.url }}/prism.js"></script> {% endif %}
{% endblock %}
{% block prism %}
{% if post.has_code %}
<script>
{% include 'prism.js' %}
</script>
{% endif %} {% endif %}
{% endblock %} {% endblock %}

View file

@ -36,8 +36,6 @@
return false; return false;
} }
</script> </script>
{% block prism %}
{% endblock %}
</head> </head>
<body> <body>
@ -425,5 +423,8 @@
{% include 'symbols.svg' %} {% include 'symbols.svg' %}
{% block prism %}
{% endblock %}
</body> </body>
</html> </html>

View file

@ -1,73 +1,74 @@
.token.comment, .comment,
.token.block-comment, .block-comment,
.token.prolog, .prolog,
.token.doctype, .doctype,
.token.cdata { .cdata {
color: darkgray; color: darkgray;
} }
.token.punctuation { .punctuation {
color:darkcyan; color:darkcyan;
} }
.token.tag, .tag,
.token.attr-name, .attr-name,
.token.namespace, .namespace,
.token.deleted { .deleted {
color: #e2777a; color: #e2777a;
} }
.token.function-name { .function-name {
color: red; color: red;
} }
.token.boolean, .boolean,
.token.number, .number,
.token.function { .function {
color: #f08d49; color: darkorchid;
} }
.token.property, .property,
.token.class-name, .class-name,
.token.constant, .constant,
.token.symbol { .symbol {
color: #f8c555; color:cadetblue;
} }
.token.selector, .selector,
.token.important, .important,
.token.atrule, .atrule,
.token.keyword, .keyword,
.token.builtin { .builtin {
color: darkorange; color: darkorange;
} }
.token.string, .string,
.token.char, .char,
.token.attr-value, .attr-value,
.token.regex, .regex,
.token.variable { .variable {
color:darkred; color:brown;
} }
.token.operator, .operator,
.token.entity, .entity,
.token.url { .url {
color: darkmagenta; color: darkmagenta;
} }
.token.important, .important,
.token.bold { .bold {
font-weight: bold; font-weight: bold;
} }
.token.italic {
.italic {
font-style: italic; font-style: italic;
} }
.token.entity { .entity {
cursor: help; cursor: help;
} }
.token.inserted { .inserted {
color: green; color: green;
} }

File diff suppressed because one or more lines are too long

View file

@ -1,3 +1,5 @@
body { body {
color: #222; color: #222;
background-color: #eee; background-color: #eee;
@ -27,3 +29,13 @@ blockquote {
td, th { td, th {
border: 1px solid #111; border: 1px solid #111;
} }
th, tr:nth-child(even) {
background-color: rgba(0, 0, 0, .1);
}
pre> code::before {
color: #444;
}

View file

@ -142,7 +142,7 @@ nav li {
code, pre, q, figcaption { code, pre, q, figcaption {
font-family: "Courier New", "Courier", monospace; font-family: "Courier New", "Courier", monospace;
font-size: 0.8em; font-size: 0.94em;
} }
code, pre { code, pre {
@ -171,6 +171,7 @@ pre > code {
pre> code::before { pre> code::before {
content: attr(lang); content: attr(lang);
float: right; float: right;
color: #999;
} }
table { table {
@ -188,15 +189,10 @@ th {
th { th {
font-weight: bold; font-weight: bold;
background-color: rgba(0, 0, 0, .1);
} }
tr:nth-child(odd) { th, tr:nth-child(even) {
background-color: rgba(255, 255, 255, .1);
}
tr:nth-child(even) {
background-color: rgba(0, 0, 0, .1);
} }
body > header, body > header,
@ -345,4 +341,4 @@ body > footer dd {
display: flex; display: flex;
justify-content: space-between; justify-content: space-between;
} }
} }