Skip to content

Commit

Permalink
feat(parsing.utils): add JSON Feed support
Browse files Browse the repository at this point in the history
feedparser@develop has added support for JSON Feed before. However,
entry.content maybe a bare dict this time, unlike Atom that use an array
(list) of dicts.

Add JSON Feed support by adding a case that deals with such behavior.
With this patch and feedparser from its develop branch, we can finally
gain the support for JSON Feed.

See also #273.

Signed-off-by: Rongrong <[email protected]>
  • Loading branch information
Rongronggg9 committed Dec 23, 2024
1 parent b463cad commit f37672b
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/parsing/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,8 @@ class EntryParsed:
enclosures: list[Enclosure] = None

content = (
entry.get('content') # Atom
or entry.get('summary', '') # Atom summary or RSS description
entry.get('content') # Atom: <content>; JSON Feed: .content_html, .content_text
or entry.get('summary', '') # Atom: <summary>; RSS: <description>
)

if isinstance(content, list) and len(content) > 0: # Atom
Expand All @@ -271,6 +271,9 @@ class EntryParsed:
else:
content = content[0]
content = content.get('value', '')
elif isinstance(content, dict): # JSON Feed
# TODO: currently feedparser always prefer content_text rather than content_html, we'd like to change that
content = content.get('value', '')

EntryParsed.content = await html_validator(content)
EntryParsed.link = entry.get('link') or entry.get('guid')
Expand Down

0 comments on commit f37672b

Please sign in to comment.