- 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:
parent
d3fbf2e51f
commit
5ec437de8f
9 changed files with 1933 additions and 142 deletions
32
nasg.py
32
nasg.py
|
@ -13,7 +13,6 @@ import time
|
|||
from functools import partial
|
||||
import re
|
||||
import imghdr
|
||||
import logging
|
||||
import asyncio
|
||||
import sqlite3
|
||||
import json
|
||||
|
@ -86,7 +85,7 @@ class MarkdownDoc(object):
|
|||
@cached_property
|
||||
def _parsed(self):
|
||||
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())
|
||||
return(meta, txt)
|
||||
|
||||
|
@ -505,16 +504,16 @@ class Singular(MarkdownDoc):
|
|||
'labels': settings.labels
|
||||
})
|
||||
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)
|
||||
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)
|
||||
|
||||
|
||||
class WebImage(object):
|
||||
def __init__(self, fpath, mdimg, parent):
|
||||
logging.debug("loading image: %s", fpath)
|
||||
settings.logger.debug("loading image: %s", fpath)
|
||||
self.mdimg = mdimg
|
||||
self.fpath = fpath
|
||||
self.parent = parent
|
||||
|
@ -715,7 +714,7 @@ class WebImage(object):
|
|||
img = self._maybe_watermark(img)
|
||||
for size, resized in self.resized_images:
|
||||
if not resized.exists or settings.args.get('regenerate'):
|
||||
logging.info(
|
||||
settings.logger.info(
|
||||
"resizing image: %s to size %d",
|
||||
os.path.basename(self.fpath),
|
||||
size
|
||||
|
@ -832,7 +831,7 @@ class WebImage(object):
|
|||
|
||||
# this is to make sure pjpeg happens
|
||||
with open(self.fpath, 'wb') as f:
|
||||
logging.info("writing %s", self.fpath)
|
||||
settings.logger.info("writing %s", self.fpath)
|
||||
thumb.save(file=f)
|
||||
|
||||
|
||||
|
@ -846,8 +845,7 @@ class AsyncWorker(object):
|
|||
self._tasks.append(task)
|
||||
|
||||
def run(self):
|
||||
w = asyncio.wait(self._tasks, return_when=asyncio.FIRST_EXCEPTION)
|
||||
self._loop.run_until_complete(w)
|
||||
self._loop.run_until_complete(asyncio.wait(self._tasks))
|
||||
|
||||
|
||||
class IndexPHP(object):
|
||||
|
@ -888,7 +886,7 @@ class IndexPHP(object):
|
|||
'redirects': self.redirect
|
||||
})
|
||||
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)
|
||||
|
||||
|
||||
|
@ -989,7 +987,7 @@ class Category(dict):
|
|||
return True
|
||||
|
||||
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
|
||||
end = int(settings.site.get('pagination'))
|
||||
|
||||
|
@ -1040,7 +1038,7 @@ class Category(dict):
|
|||
|
||||
atom = os.path.join(dirname, 'index.xml')
|
||||
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))
|
||||
|
||||
def render_page(self, pagenum=1, pages=1):
|
||||
|
@ -1188,7 +1186,7 @@ class Search(object):
|
|||
'labels': settings.labels
|
||||
})
|
||||
with open(target, 'wt') as f:
|
||||
logging.info("rendering to %s", target)
|
||||
settings.logger.info("rendering to %s", target)
|
||||
f.write(r)
|
||||
|
||||
class Sitemap(dict):
|
||||
|
@ -1238,7 +1236,7 @@ def mkcomment(webmention):
|
|||
}
|
||||
fm.content = webmention.get('data').get('content')
|
||||
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))
|
||||
|
||||
|
||||
|
@ -1324,14 +1322,14 @@ def make():
|
|||
)
|
||||
|
||||
search.__exit__()
|
||||
search.render()
|
||||
worker.add(search.render())
|
||||
for category in categories.values():
|
||||
worker.add(category.render())
|
||||
|
||||
worker.add(sitemap.render())
|
||||
|
||||
worker.run()
|
||||
logging.info('worker finished')
|
||||
settings.logger.info('worker finished')
|
||||
|
||||
# copy static
|
||||
staticfiles = []
|
||||
|
@ -1351,7 +1349,7 @@ def make():
|
|||
cp(e, t)
|
||||
|
||||
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__':
|
||||
|
|
80
pandoc.py
80
pandoc.py
|
@ -1,44 +1,46 @@
|
|||
import subprocess
|
||||
import logging
|
||||
|
||||
def pandoc(text):
|
||||
# TODO: cache?
|
||||
# import hashlib
|
||||
# print(hashlib.md5("whatever your string is".encode('utf-8')).hexdigest())
|
||||
class pandoc(str):
|
||||
def __new__(cls, text):
|
||||
# TODO: cache?
|
||||
# import hashlib
|
||||
# print(hashlib.md5("whatever your string is".encode('utf-8')).hexdigest())
|
||||
|
||||
""" Pandoc command line call with piped in- and output """
|
||||
cmd = (
|
||||
'pandoc',
|
||||
'-o-',
|
||||
'--from=markdown+%s' % (
|
||||
'+'.join([
|
||||
'footnotes',
|
||||
'pipe_tables',
|
||||
'raw_html',
|
||||
'definition_lists',
|
||||
'backtick_code_blocks',
|
||||
'fenced_code_attributes',
|
||||
'shortcut_reference_links',
|
||||
'lists_without_preceding_blankline',
|
||||
'autolink_bare_uris',
|
||||
])
|
||||
),
|
||||
'--to=html5',
|
||||
'--quiet',
|
||||
'--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
|
||||
""" Pandoc command line call with piped in- and output """
|
||||
cmd = (
|
||||
'pandoc',
|
||||
'-o-',
|
||||
'--from=markdown+%s' % (
|
||||
'+'.join([
|
||||
'footnotes',
|
||||
'pipe_tables',
|
||||
'raw_html',
|
||||
'definition_lists',
|
||||
'backtick_code_blocks',
|
||||
'fenced_code_attributes',
|
||||
'shortcut_reference_links',
|
||||
'lists_without_preceding_blankline',
|
||||
'autolink_bare_uris',
|
||||
])
|
||||
),
|
||||
'--to=html5',
|
||||
'--quiet',
|
||||
'--no-highlight'
|
||||
)
|
||||
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)
|
||||
|
|
27
settings.py
27
settings.py
|
@ -135,11 +135,24 @@ _parser.add_argument(
|
|||
|
||||
args = vars(_parser.parse_args())
|
||||
|
||||
# remove the rest of the potential loggers
|
||||
while len(logging.root.handlers) > 0:
|
||||
logging.root.removeHandler(logging.root.handlers[-1])
|
||||
loglevel = loglevels.get(args.get('loglevel'))
|
||||
|
||||
logging.basicConfig(
|
||||
level=loglevels[args.get('loglevel')],
|
||||
format='%(asctime)s - %(levelname)s - %(message)s'
|
||||
)
|
||||
logger = logging.getLogger("nasg")
|
||||
logger.setLevel(loglevel)
|
||||
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'
|
||||
# )
|
||||
|
|
|
@ -4,12 +4,16 @@
|
|||
<meta name="description" content="{{ post.summary|e }}" />
|
||||
<link rel="canonical" href="{{ post.url }}" />
|
||||
<link rel="license" href="https://creativecommons.org/licenses/4.0/{{ post.licence }}" />
|
||||
{% endblock %}
|
||||
{% block prism %}
|
||||
{% if post.has_code %}
|
||||
<style media="all">
|
||||
{% include 'prism.css' %}
|
||||
</style>
|
||||
<script src="{{ site.url }}/prism.js"></script>
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
{% block prism %}
|
||||
{% if post.has_code %}
|
||||
<script>
|
||||
{% include 'prism.js' %}
|
||||
</script>
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
|
|
@ -36,8 +36,6 @@
|
|||
return false;
|
||||
}
|
||||
</script>
|
||||
{% block prism %}
|
||||
{% endblock %}
|
||||
</head>
|
||||
<body>
|
||||
|
||||
|
@ -425,5 +423,8 @@
|
|||
|
||||
{% include 'symbols.svg' %}
|
||||
|
||||
{% block prism %}
|
||||
{% endblock %}
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -1,73 +1,74 @@
|
|||
.token.comment,
|
||||
.token.block-comment,
|
||||
.token.prolog,
|
||||
.token.doctype,
|
||||
.token.cdata {
|
||||
.comment,
|
||||
.block-comment,
|
||||
.prolog,
|
||||
.doctype,
|
||||
.cdata {
|
||||
color: darkgray;
|
||||
}
|
||||
|
||||
.token.punctuation {
|
||||
.punctuation {
|
||||
color:darkcyan;
|
||||
}
|
||||
|
||||
.token.tag,
|
||||
.token.attr-name,
|
||||
.token.namespace,
|
||||
.token.deleted {
|
||||
.tag,
|
||||
.attr-name,
|
||||
.namespace,
|
||||
.deleted {
|
||||
color: #e2777a;
|
||||
}
|
||||
|
||||
.token.function-name {
|
||||
.function-name {
|
||||
color: red;
|
||||
}
|
||||
|
||||
.token.boolean,
|
||||
.token.number,
|
||||
.token.function {
|
||||
color: #f08d49;
|
||||
.boolean,
|
||||
.number,
|
||||
.function {
|
||||
color: darkorchid;
|
||||
}
|
||||
|
||||
.token.property,
|
||||
.token.class-name,
|
||||
.token.constant,
|
||||
.token.symbol {
|
||||
color: #f8c555;
|
||||
.property,
|
||||
.class-name,
|
||||
.constant,
|
||||
.symbol {
|
||||
color:cadetblue;
|
||||
}
|
||||
|
||||
.token.selector,
|
||||
.token.important,
|
||||
.token.atrule,
|
||||
.token.keyword,
|
||||
.token.builtin {
|
||||
.selector,
|
||||
.important,
|
||||
.atrule,
|
||||
.keyword,
|
||||
.builtin {
|
||||
color: darkorange;
|
||||
}
|
||||
|
||||
.token.string,
|
||||
.token.char,
|
||||
.token.attr-value,
|
||||
.token.regex,
|
||||
.token.variable {
|
||||
color:darkred;
|
||||
.string,
|
||||
.char,
|
||||
.attr-value,
|
||||
.regex,
|
||||
.variable {
|
||||
color:brown;
|
||||
}
|
||||
|
||||
.token.operator,
|
||||
.token.entity,
|
||||
.token.url {
|
||||
.operator,
|
||||
.entity,
|
||||
.url {
|
||||
color: darkmagenta;
|
||||
}
|
||||
|
||||
.token.important,
|
||||
.token.bold {
|
||||
.important,
|
||||
.bold {
|
||||
font-weight: bold;
|
||||
}
|
||||
.token.italic {
|
||||
|
||||
.italic {
|
||||
font-style: italic;
|
||||
}
|
||||
|
||||
.token.entity {
|
||||
.entity {
|
||||
cursor: help;
|
||||
}
|
||||
|
||||
.token.inserted {
|
||||
.inserted {
|
||||
color: green;
|
||||
}
|
||||
}
|
1814
templates/prism.js
1814
templates/prism.js
File diff suppressed because one or more lines are too long
|
@ -1,3 +1,5 @@
|
|||
|
||||
|
||||
body {
|
||||
color: #222;
|
||||
background-color: #eee;
|
||||
|
@ -27,3 +29,13 @@ blockquote {
|
|||
td, th {
|
||||
border: 1px solid #111;
|
||||
}
|
||||
|
||||
th, tr:nth-child(even) {
|
||||
background-color: rgba(0, 0, 0, .1);
|
||||
}
|
||||
|
||||
pre> code::before {
|
||||
color: #444;
|
||||
}
|
||||
|
||||
|
|
@ -142,7 +142,7 @@ nav li {
|
|||
|
||||
code, pre, q, figcaption {
|
||||
font-family: "Courier New", "Courier", monospace;
|
||||
font-size: 0.8em;
|
||||
font-size: 0.94em;
|
||||
}
|
||||
|
||||
code, pre {
|
||||
|
@ -171,6 +171,7 @@ pre > code {
|
|||
pre> code::before {
|
||||
content: attr(lang);
|
||||
float: right;
|
||||
color: #999;
|
||||
}
|
||||
|
||||
table {
|
||||
|
@ -188,15 +189,10 @@ th {
|
|||
|
||||
th {
|
||||
font-weight: bold;
|
||||
background-color: rgba(0, 0, 0, .1);
|
||||
}
|
||||
|
||||
tr:nth-child(odd) {
|
||||
|
||||
}
|
||||
|
||||
tr:nth-child(even) {
|
||||
background-color: rgba(0, 0, 0, .1);
|
||||
th, tr:nth-child(even) {
|
||||
background-color: rgba(255, 255, 255, .1);
|
||||
}
|
||||
|
||||
body > header,
|
||||
|
@ -345,4 +341,4 @@ body > footer dd {
|
|||
display: flex;
|
||||
justify-content: space-between;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue