JSON-LD and JSONFeed, you know what? Nope.

This commit is contained in:
Peter Molnar 2018-07-27 14:55:21 +01:00
parent 2da2618a35
commit 9b38f3f0e4
5 changed files with 27 additions and 63 deletions

View file

@ -37,7 +37,7 @@ deactivate () {
# unset irrelevant variables # unset irrelevant variables
deactivate nondestructive deactivate nondestructive
VIRTUAL_ENV="/home/cadeyrn/Projects/petermolnar.net/nasg/.venv" VIRTUAL_ENV="~/Projects/petermolnar.net/nasg/.venv"
export VIRTUAL_ENV export VIRTUAL_ENV
_OLD_VIRTUAL_PATH="$PATH" _OLD_VIRTUAL_PATH="$PATH"

View file

@ -1,11 +0,0 @@
#!/home/cadeyrn/Projects/petermolnar.net/nasg/.venv/bin/python3
# -*- coding: utf-8 -*-
import re
import sys
from pip import main
if __name__ == '__main__':
sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])
sys.exit(main())

1
.venv/bin/pip3 Symbolic link
View file

@ -0,0 +1 @@
pip

View file

@ -1,11 +0,0 @@
#!/home/cadeyrn/Projects/petermolnar.net/nasg/.venv/bin/python3
# -*- coding: utf-8 -*-
import re
import sys
from pip import main
if __name__ == '__main__':
sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])
sys.exit(main())

1
.venv/bin/pip3.6 Symbolic link
View file

@ -0,0 +1 @@
pip

60
nasg.py
View file

@ -287,16 +287,22 @@ class Singular(MarkdownDoc):
return True return True
return False return False
@property
def photo(self):
if not self.is_photo:
return None
return next(iter(self.images.values()))
@property @property
def enclosure(self): def enclosure(self):
if not self.is_photo: if not self.is_photo:
return False return None
photo = next(iter(self.images.values())) else:
return { return {
'mime': photo.mime_type, 'mime': self.photo.mime_type,
'size': photo.mime_size, 'size': self.photo.mime_size,
'url': photo.href 'url': self.photo.href
} }
@property @property
def summary(self): def summary(self):
@ -942,6 +948,7 @@ class Category(dict):
'display': self.display, 'display': self.display,
'url': self.url, 'url': self.url,
'feed': "%s%s/" % (self.url, 'feed'), 'feed': "%s%s/" % (self.url, 'feed'),
'jsonfeed': "%s%s/index.json" % (self.url, 'feed'),
'title': self.title 'title': self.title
} }
@ -953,10 +960,15 @@ class Category(dict):
def exists(self): def exists(self):
if settings.args.get('force'): if settings.args.get('force'):
return False return False
renderfile = os.path.join(self.renderdir, 'feed', 'index.xml') ismissing = False
if not os.path.exists(renderfile): for f in [
return False os.path.join(self.renderdir, 'feed', 'index.xml'),
elif self.mtime > os.path.getmtime(renderfile): ]:
if not os.path.exists(f):
ismissing = True
elif self.mtime > os.path.getmtime(f):
ismissing = True
if ismissing:
return False return False
else: else:
return True return True
@ -981,30 +993,8 @@ class Category(dict):
fg.logo('%s/favicon.png' % settings.site.get('url')) fg.logo('%s/favicon.png' % settings.site.get('url'))
fg.updated(arrow.get(self.mtime).to('utc').datetime) fg.updated(arrow.get(self.mtime).to('utc').datetime)
jselements = []
jsfeed = {
'items': jselements,
'version': 'https://jsonfeed.org/version/1',
'title': self.title,
'home_page_url': settings.site.get('url'),
'feed_url': self.feed,
'author': {
'name': settings.author.get('name'),
'url': settings.author.get('url'),
'email': settings.author.get('email'),
}
}
for post in self.get_posts(start, end): for post in self.get_posts(start, end):
dt = arrow.get(post.get('pubtime')) dt = arrow.get(post.get('pubtime'))
jselements.append({
"title": post.get('title'),
"date_published": post.get('pubtime'),
"id": post.get('url'),
"url": post.get('url'),
"content_html": post.get('html_content')
})
fe = fg.add_entry() fe = fg.add_entry()
fe.id(post.get('url')) fe.id(post.get('url'))
fe.link(href=post.get('url')) fe.link(href=post.get('url'))
@ -1015,7 +1005,6 @@ class Category(dict):
post.get('html_content'), post.get('html_content'),
type='CDATA' type='CDATA'
) )
fe.rights('%s %s %s' % ( fe.rights('%s %s %s' % (
post.get('licence').upper(), post.get('licence').upper(),
settings.author.get('name'), settings.author.get('name'),
@ -1033,9 +1022,6 @@ class Category(dict):
logging.info('writing file: %s', atom) logging.info('writing file: %s', atom)
f.write(fg.atom_str(pretty=True)) f.write(fg.atom_str(pretty=True))
jsfile = os.path.join(dirname, 'index.json') jsfile = os.path.join(dirname, 'index.json')
with open(jsfile, 'wt') as f:
logging.info('writing file: %s', jsfile)
f.write(json.dumps(jsfeed, indent=4, sort_keys=True))
def render_page(self, pagenum=1, pages=1): def render_page(self, pagenum=1, pages=1):
if self.display == 'flat': if self.display == 'flat':

View file

@ -101,10 +101,8 @@ tips = [
] ]
dateformat = { dateformat = {
'iso': 'YYYY-MM-DDTHH:mm:ssZ', 'iso': 'YYYY-MM-DDTHH:mm:ssZZ',
'display': 'YYYY-MM-DD HH:mm', 'display': 'YYYY-MM-DD HH:mm',
'rcf': 'ddd, DD MMM YYYY HH:mm:ss Z',
'twitter': 'ddd MMM DD HH:mm:ss Z YYYY'
} }
loglevels = { loglevels = {