8000 Fix for parsing photo/avatar with mf2py>=2.0. · beatonma/django-wm@d99a3fc · GitHub
[go: up one dir, main page]

Skip to content

Commit

Permalink
Fix for parsing photo/avatar with mf2py>=2.0.
Browse files Browse the repository at this point in the history
  • Loading branch information
beatonma committed Feb 9, 2024
1 parent 41e9c5d commit d99a3fc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
8 changes: 6 additions & 2 deletions mentions/tasks/incoming/parsing/hcard.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ def parse_h 8000 card(
soup: Tag,
recursive: bool = False,
) -> Optional[HCard]:
"""Create or update HCard(s) using data from a BeautifulSoup document.
"""Create or update HCard using data from a BeautifulSoup document.
Top-down search to find an h-card on the document.
See https://github.com/microformats/mf2py"""

Expand All @@ -41,7 +43,9 @@ def parse_hcard(


def find_related_hcard(link: Tag) -> Optional[HCard]:
"""Try to find a post-specific h-card from a parent `h-entry` or `h-feed`."""
"""Try to find a post-specific h-card from a parent `h-entry` or `h-feed`.
Bottom-up search for the nearest related h-card."""
hentry = link.find_parent(class_=H_ENTRY)
if hentry:
hcard = parse_hcard(hentry, recursive=True)
Expand Down
4 changes: 2 additions & 2 deletions mentions/tasks/incoming/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,15 @@ def get_metadata_from_source(

hcard = find_related_hcard(link) or parse_hcard(soup, recursive=False)
if hcard:
hcard = coerce_hcard_absolute_urls(hcard, source_url)
hcard = _coerce_hcard_absolute_urls(hcard, source_url)

return WebmentionMetadata(
post_type=post_type.serialized_name() if post_type else None,
hcard=hcard,
)


def coerce_hcard_absolute_urls(hcard: HCard, source_url: str) -> HCard:
def _coerce_hcard_absolute_urls(hcard: HCard, source_url: str) -> HCard:
"""Convert any relative URLs to absolute URLs."""
updated_fields = []

Expand Down

0 comments on commit d99a3fc

Please sign in to comment.
0