Skip to content

Commit

Permalink
microformats2: add u-featured to ActivityStreams image field
Browse files Browse the repository at this point in the history
  • Loading branch information
snarfed committed Apr 11, 2017
1 parent cbea8bd commit 1d06686
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -296,6 +296,7 @@ Changelog
* Instagram:
* Update scraping to handle new home page (ie news feed) JSON schema, which changed sometime around 2017-02-27. (Profile pages and individual photo/video permalinks still haven't changed yet.)
* microformats2:
* Add [`u-featured`](https://indieweb.org/featured) to ActivityStreams `image`.
* Minor whitespace change (added <p>) when rendering locations as HTML.
* Atom:
* Include author name when rendering attached articles and notes (e.g. quote tweets).
Expand Down
7 changes: 4 additions & 3 deletions granary/microformats2.py
Expand Up @@ -273,7 +273,7 @@ def json_to_object(mf2, actor=None):
as_type, as_verb = mf2_type_to_as_type.get(mf2_type, (None, None))

def absolute_urls(prop):
return [{'url': url} for url in get_string_urls(props.get(prop, []))
return [url for url in get_string_urls(props.get(prop, []))
# filter out relative and invalid URLs (mf2py gives absolute urls)
if urlparse.urlparse(url).netloc]

Expand Down Expand Up @@ -301,8 +301,9 @@ def absolute_urls(prop):
'content': get_html(prop.get('content')),
'url': urls[0] if urls else None,
'urls': [{'value': u} for u in urls] if urls and len(urls) > 1 else None,
'image': absolute_urls('photo'),
'stream': absolute_urls('video'),
'image': [{'url': url} for url in
util.dedupe_urls(absolute_urls('photo') + absolute_urls('featured'))],
'stream': [{'url': url} for url in absolute_urls('video')],
'location': json_to_object(prop.get('location')),
'replies': {'items': [json_to_object(c) for c in props.get('comment', [])]},
'tags': [{'objectType': 'hashtag', 'displayName': cat}
Expand Down
6 changes: 6 additions & 0 deletions granary/test/testdata/article_with_featured.as-from-mf2.json
@@ -0,0 +1,6 @@
{
"objectType": "article",
"displayName": "article abc",
"content": "foo bar",
"image": [{"url": "http://feat/ured.jpg"}]
}
8 changes: 8 additions & 0 deletions granary/test/testdata/article_with_featured.mf2.json
@@ -0,0 +1,8 @@
{
"type": ["h-entry"],
"properties": {
"name": ["article abc"],
"content": ["foo bar"],
"featured": ["http://feat/ured.jpg"]
}
}
@@ -0,0 +1,6 @@
{
"objectType": "article",
"displayName": "article abc",
"content": "foo bar",
"image": [{"url": "http://a/png"}, {"url": "http://b/jpg"}, {"url": "http://c/gif"}]
}
@@ -0,0 +1,9 @@
{
"type": ["h-entry"],
"properties": {
"name": ["article abc"],
"content": ["foo bar"],
"photo": ["http://a/png", "http://b/jpg"],
"featured": ["http://b/jpg", "http://c/gif"]
}
}

0 comments on commit 1d06686

Please sign in to comment.