override link label for home page to be "Web site"

for #331
pull/389/head
Ryan Barrett 2023-01-25 12:31:13 -08:00
rodzic f296d0f017
commit 05c8dc83c4
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 6BE31FDF4776E9D4
2 zmienionych plików z 18 dodań i 1 usunięć

Wyświetl plik

@ -464,7 +464,11 @@ def postprocess_as2_actor(actor, user=None):
Returns:
actor dict
"""
urls = util.get_list(actor, 'url') or [f'https://{user.key.id()}/']
url = f'https://{user.key.id()}/' if user else None
urls = util.get_list(actor, 'url')
if not urls and url:
urls = [url]
domain = util.domain_from_link(urls[0], minimize=False)
urls[0] = redirect_wrap(urls[0])
@ -476,6 +480,14 @@ def postprocess_as2_actor(actor, user=None):
'preferredUsername': domain,
})
# Override the label for their home page to be "Web site"
for att in util.get_list(actor, 'attachment'):
if att.get('type') == 'PropertyValue':
val = att.get('value', '')
link = util.parse_html(val).find('a')
if url and (val == url or link.get('href') == url):
att['name'] = 'Web site'
# required by pixelfed. https://github.com/snarfed/bridgy-fed/issues/39
actor.setdefault('summary', '')
return actor

Wyświetl plik

@ -201,6 +201,7 @@ class ActivityPubTest(testutil.TestCase):
<body>
<div class="h-card">
<a class="u-url" rel="me" href="/about-me">Mrs. Foo</a>
<a class="u-url" rel="me" href="/">should be ignored</a>
<a class="u-url" rel="me" href="http://one" title="one title">
one text
</a>
@ -215,6 +216,10 @@ class ActivityPubTest(testutil.TestCase):
'type': 'PropertyValue',
'name': 'Mrs. ☕ Foo',
'value': '<a rel="me" href="https://foo.com/about-me">foo.com/about-me</a>',
}, {
'type': 'PropertyValue',
'name': 'Web site',
'value': '<a rel="me" href="https://foo.com/">foo.com</a>',
}, {
'type': 'PropertyValue',
'name': 'one text',