Skip to content
Permalink
Browse files

better metadata support

  • Loading branch information
ralsina committed May 27, 2017
1 parent 85c255e commit 8b94d644d47ee6106a35d39f6f626b40e4c93bd1
@@ -7,28 +7,25 @@ Using continuous import you can have that content presented also in your own
site, making it the authoritative source for all things you write, and giving
you a backup in case those sites ever disappear.

TODO: explain better how it works

TODO: do more templates for more services

TODO: add a generic default template that "sort of works"
TODO: explain how it works

```
# This is a list of feeds whose contents will be imported as posts into
# your blog via the "nikola continuous_import" command.
FEEDS = {
'goodreads': {
'url': 'https://www.goodreads.com/review/list_rss/1512608?key=N4VCVq54T-sxk8wx4UMRYIZKMVqQpbZN4gdYG22R4dv04LM2&shelf=read',
'url': 'https://www.goodreads.com/review/list_rss/1512608?shelf=read',
'template': 'goodreads.tmpl',
'output_folder': 'posts/goodreads',
'format': 'html',
'lang': 'en',
'tags': 'books, goodreads',
'metadata': {
'title': 'title',
'date': 'published',
'tags': 'books, goodreads',
'date': ['user_read_at', 'user_date_added', 'published'],
}
}
}
```
@@ -27,6 +27,7 @@
"""Create a new site."""

from __future__ import print_function, unicode_literals
import io
import os

import feedparser
@@ -61,19 +62,41 @@ def fetch(self, feed):
parsed = feedparser.parse(url)
return parsed

def get_data(self, item, prop):
if isinstance(prop, (list, tuple)):
# Try each prop until one works
for p in prop:
if p in item and item[p]:
return item[p]
return ''
else:
return item.get(prop, '')

def generate(self, item, feed):
compiler = self.site.compilers[feed['format']]
title = item[feed['metadata']['title']]
title = self.get_data(item, feed['metadata']['title'])
output_name = os.path.join(feed['output_folder'],
slugify(title, feed['lang'])) + compiler.extension()
post = self.site.render_template(
content = self.site.render_template(
feed['template'],
None,
dict(
item=item,
feed=feed,
lang=feed['lang'],
))
makedirs(os.path.dirname(output_name))
with open(output_name, "w+") as post_file:
post_file.write(post)

metadata = {}
for k, v in feed['metadata'].items():
metadata[k] = self.get_data(item, v)

if 'tags' not in metadata:
metadata['tags'] = feed['tags']

compiler.create_post(
path=output_name,
content=content,
onefile=True,
is_page=False,
**metadata
)
@@ -1,6 +1,16 @@
<div>
<img class='img-thumbnail pull-left' src="${item['book_medium_image_url']}">
<p>Author: ${item['author_name']}</p>
<table>
<tr>
<td>
<img class='img-thumbnail' src="${item['book_medium_image_url']}">
</td>
<td valign="top">
<p><b>Author:</b> ${item['author_name']}</p>
<p><b>Rating:</b>
%for i in range(int(item['user_rating'])):
<span class="glyphicon glyphicon-star"></span>
% endfor
</table>

<p>${item['user_review']}</p>
</div>

0 comments on commit 8b94d64

Please sign in to comment.