entry content
+diff --git a/README.md b/README.md
index ffe2d619..985f3323 100644
--- a/README.md
+++ b/README.md
@@ -313,6 +313,8 @@ Changelog
* GitHub:
* Escape HTML characters (`<`, `>`, and `&`) in content in `create()` and `preview_create()` ([snarfed/bridgy#810](https://github.com/snarfed/bridgy/issues/810)).
* `get_activities()` and `get_comment()` now return `ValueError` instead of `AssertionError` on malformed `activity_id` and `comment_id` args, respectively.
+* Atom:
+ * Shorten and ellipsize feed title when necessary ([#144](https://github.com/snarfed/granary/issues/144)).
### 1.12 - 2018-03-24
* Add Python 3 support! Granary now requires either Python 2.7+ or Python 3.3+.
diff --git a/app.py b/app.py
index bd2438b2..fe505138 100644
--- a/app.py
+++ b/app.py
@@ -157,7 +157,7 @@ def fetch_mf2_func(url):
return mf2py.parse(doc=doc, url=url)
actor = microformats2.find_author(mf2, fetch_mf2_func=fetch_mf2_func)
- title = mf2util.interpret_feed(mf2, url).get('name')
+ title = microformats2.get_title(mf2)
if input in ('as1', 'activitystreams'):
activities = body_items
diff --git a/granary/atom.py b/granary/atom.py
index 56fb587f..dec7ff02 100644
--- a/granary/atom.py
+++ b/granary/atom.py
@@ -332,7 +332,7 @@ def html_to_atom(html, url=None, fetch_author=False, reader=True):
return activities_to_atom(
microformats2.html_to_activities(html, url, actor),
actor,
- title=mf2util.interpret_feed(parsed, url).get('name'),
+ title=microformats2.get_title(parsed),
xml_base=util.base_url(url),
host_url=url,
reader=reader)
diff --git a/granary/microformats2.py b/granary/microformats2.py
index 02e3c5c4..004e117e 100644
--- a/granary/microformats2.py
+++ b/granary/microformats2.py
@@ -913,6 +913,21 @@ def find_author(parsed, **kwargs):
}
+def get_title(mf2):
+ """Returns the author of a page as a ActivityStreams actor dict.
+
+ Args:
+ mf2: dict, parsed mf2 object (ie return value from mf2py.parse())
+
+ Returns: string title, possibly ellipsized
+ """
+ lines = mf2util.interpret_feed(mf2, '').get('name', '').splitlines()
+ if lines:
+ return util.ellipsize(lines[0])
+
+ return ''
+
+
def first_props(props):
"""Converts a multiply-valued dict to singly valued.
diff --git a/granary/test/test_atom.py b/granary/test/test_atom.py
index 98b4a9e6..8e551af1 100644
--- a/granary/test/test_atom.py
+++ b/granary/test/test_atom.py
@@ -632,6 +632,21 @@ def test_html_to_atom_fetch_author(self):
""", got, ignore_blanks=True)
+ def test_html_to_atom_title_without_hfeed_name(self):
+ self.assert_multiline_in("""\
+
entry content
+