Dedup inline attachments (when already inlined)
This commit is contained in:
parent
08cdcd6b50
commit
be0f5c04b2
2 changed files with 25 additions and 1 deletions
|
@ -245,7 +245,7 @@
|
||||||
<h3 class="l">Attachments</h3>
|
<h3 class="l">Attachments</h3>
|
||||||
<ul style="padding:0;list-style-type: none;">
|
<ul style="padding:0;list-style-type: none;">
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% for a in obj.attachment %}
|
{% for a in (obj | iter_note_attachments) %}
|
||||||
{% if (a.mediaType and a.mediaType.startswith("image/")) or (a.type and a.type == 'Image') %}
|
{% if (a.mediaType and a.mediaType.startswith("image/")) or (a.type and a.type == 'Image') %}
|
||||||
<a href="{{ a.url | get_attachment_url(None) }}">
|
<a href="{{ a.url | get_attachment_url(None) }}">
|
||||||
<img src="{{a.url | get_attachment_url(720) }}" title="{{ a.name }}" alt="{{ a.name }}" class="img-attachment"></a>
|
<img src="{{a.url | get_attachment_url(720) }}" title="{{ a.name }}" alt="{{ a.name }}" class="img-attachment"></a>
|
||||||
|
|
|
@ -2,6 +2,7 @@ import logging
|
||||||
import urllib
|
import urllib
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from datetime import timezone
|
from datetime import timezone
|
||||||
|
from functools import lru_cache
|
||||||
from urllib.parse import urlparse
|
from urllib.parse import urlparse
|
||||||
|
|
||||||
import bleach
|
import bleach
|
||||||
|
@ -345,6 +346,7 @@ def get_attachment_url(url, size):
|
||||||
|
|
||||||
|
|
||||||
@filters.app_template_filter()
|
@filters.app_template_filter()
|
||||||
|
@lru_cache(maxsize=256)
|
||||||
def update_inline_imgs(content):
|
def update_inline_imgs(content):
|
||||||
soup = BeautifulSoup(content, "html5lib")
|
soup = BeautifulSoup(content, "html5lib")
|
||||||
imgs = soup.find_all("img")
|
imgs = soup.find_all("img")
|
||||||
|
@ -418,6 +420,28 @@ def has_actor_type(doc):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
@lru_cache(maxsize=256)
|
||||||
|
def _get_inlined_imgs(content):
|
||||||
|
imgs = []
|
||||||
|
if not content:
|
||||||
|
return imgs
|
||||||
|
|
||||||
|
soup = BeautifulSoup(content, "html5lib")
|
||||||
|
for img in soup.find_all("img"):
|
||||||
|
src = img.attrs.get("src")
|
||||||
|
if src:
|
||||||
|
imgs.append(src)
|
||||||
|
|
||||||
|
return imgs
|
||||||
|
|
||||||
|
|
||||||
|
@filters.app_template_filter()
|
||||||
|
def iter_note_attachments(note):
|
||||||
|
attachments = note.get("attachment", [])
|
||||||
|
imgs = _get_inlined_imgs(note.get("content"))
|
||||||
|
return [a for a in attachments if a.get("url") not in imgs]
|
||||||
|
|
||||||
|
|
||||||
@filters.app_template_filter()
|
@filters.app_template_filter()
|
||||||
def not_only_imgs(attachment):
|
def not_only_imgs(attachment):
|
||||||
for a in attachment:
|
for a in attachment:
|
||||||
|
|
Loading…
Reference in a new issue