mirror of
				https://git.sr.ht/~tsileo/microblog.pub
				synced 2025-06-05 21:59:23 +02:00 
			
		
		
		
	Add support for displaying Page object
This commit is contained in:
		| @@ -76,6 +76,20 @@ class Object: | |||||||
|     def attachments(self) -> list["Attachment"]: |     def attachments(self) -> list["Attachment"]: | ||||||
|         attachments = [] |         attachments = [] | ||||||
|         for obj in ap.as_list(self.ap_object.get("attachment", [])): |         for obj in ap.as_list(self.ap_object.get("attachment", [])): | ||||||
|  |             if obj.get("type") == "Link": | ||||||
|  |                 attachments.append( | ||||||
|  |                     Attachment.parse_obj( | ||||||
|  |                         { | ||||||
|  |                             "proxiedUrl": None, | ||||||
|  |                             "resizedUrl": None, | ||||||
|  |                             "mediaType": None, | ||||||
|  |                             "type": "Link", | ||||||
|  |                             "url": obj["href"], | ||||||
|  |                         } | ||||||
|  |                     ) | ||||||
|  |                 ) | ||||||
|  |                 continue | ||||||
|  |  | ||||||
|             proxied_url = proxied_media_url(obj["url"]) |             proxied_url = proxied_media_url(obj["url"]) | ||||||
|             attachments.append( |             attachments.append( | ||||||
|                 Attachment.parse_obj( |                 Attachment.parse_obj( | ||||||
| @@ -189,12 +203,12 @@ class BaseModel(pydantic.BaseModel): | |||||||
|  |  | ||||||
| class Attachment(BaseModel): | class Attachment(BaseModel): | ||||||
|     type: str |     type: str | ||||||
|     media_type: str |     media_type: str | None | ||||||
|     name: str | None |     name: str | None | ||||||
|     url: str |     url: str | ||||||
|  |  | ||||||
|     # Extra fields for the templates |     # Extra fields for the templates (and only for media) | ||||||
|     proxied_url: str |     proxied_url: str | None = None | ||||||
|     resized_url: str | None = None |     resized_url: str | None = None | ||||||
|  |  | ||||||
|  |  | ||||||
|   | |||||||
| @@ -78,7 +78,6 @@ _RESIZED_CACHE: MutableMapping[tuple[str, int], tuple[bytes, str, Any]] = LFUCac | |||||||
| # Next: | # Next: | ||||||
| # - UI support for updating posts | # - UI support for updating posts | ||||||
| # - Support for processing update | # - Support for processing update | ||||||
| # - Page support |  | ||||||
| # - Article support | # - Article support | ||||||
| # - Fix tests | # - Fix tests | ||||||
| # - Fix SQL tx in the codebase | # - Fix SQL tx in the codebase | ||||||
| @@ -1087,8 +1086,8 @@ async def _gen_rss_feed( | |||||||
|  |  | ||||||
|         if outbox_object.attachments: |         if outbox_object.attachments: | ||||||
|             for attachment in outbox_object.attachments: |             for attachment in outbox_object.attachments: | ||||||
|                 if attachment.type == "Image" or attachment.media_type.startswith( |                 if attachment.type == "Image" or ( | ||||||
|                     "image" |                     attachment.media_type and attachment.media_type.startswith("image") | ||||||
|                 ): |                 ): | ||||||
|                     content += f'<img src="{attachment.url}">' |                     content += f'<img src="{attachment.url}">' | ||||||
|                 # TODO(ts): other attachment types |                 # TODO(ts): other attachment types | ||||||
|   | |||||||
| @@ -315,7 +315,9 @@ def _timeago(original_dt: datetime) -> str: | |||||||
|  |  | ||||||
|  |  | ||||||
| def _has_media_type(attachment: Attachment, media_type_prefix: str) -> bool: | def _has_media_type(attachment: Attachment, media_type_prefix: str) -> bool: | ||||||
|     return attachment.media_type.startswith(media_type_prefix) |     if attachment.media_type: | ||||||
|  |         return attachment.media_type.startswith(media_type_prefix) | ||||||
|  |     return False | ||||||
|  |  | ||||||
|  |  | ||||||
| def _format_date(dt: datetime) -> str: | def _format_date(dt: datetime) -> str: | ||||||
|   | |||||||
| @@ -254,6 +254,8 @@ | |||||||
|     <video controls preload="metadata"  src="{{ attachment.url | media_proxy_url }}"{% if attachment.name %} title="{{ attachment.name }}"{% endif %} class="attachment"></video> |     <video controls preload="metadata"  src="{{ attachment.url | media_proxy_url }}"{% if attachment.name %} title="{{ attachment.name }}"{% endif %} class="attachment"></video> | ||||||
|     {% elif attachment.type == "Audio" or (attachment | has_media_type("audio")) %} |     {% elif attachment.type == "Audio" or (attachment | has_media_type("audio")) %} | ||||||
|     <audio controls preload="metadata"  src="{{ attachment.url | media_proxy_url }}"{% if attachment.name%} title="{{ attachment.name }}"{% endif %} style="width:480px;" class="attachment"></audio> |     <audio controls preload="metadata"  src="{{ attachment.url | media_proxy_url }}"{% if attachment.name%} title="{{ attachment.name }}"{% endif %} style="width:480px;" class="attachment"></audio> | ||||||
|  |     {% elif attachment.type == "Link" %} | ||||||
|  |         <a href="{{ attachment.url }}" class="attachment" style="display:inline-block;margin-bottom: 15px;">{{ attachment.url }}</a> | ||||||
|     {% else %} |     {% else %} | ||||||
|     <a href="{{ attachment.url | media_proxy_url }}"{% if attachment.name %} title="{{ attachment.name }}"{% endif %} class="attachment">{{ attachment.url }}</a> |     <a href="{{ attachment.url | media_proxy_url }}"{% if attachment.name %} title="{{ attachment.name }}"{% endif %} class="attachment">{{ attachment.url }}</a> | ||||||
|     {% endif %} |     {% endif %} | ||||||
| @@ -262,7 +264,7 @@ | |||||||
| {% endmacro %} | {% endmacro %} | ||||||
|  |  | ||||||
| {% macro display_object(object, likes=[], shares=[], webmentions=[], expanded=False, actors_metadata={}) %} | {% macro display_object(object, likes=[], shares=[], webmentions=[], expanded=False, actors_metadata={}) %} | ||||||
| {% if object.ap_type in ["Note", "Article", "Video"] %} | {% if object.ap_type in ["Note", "Article", "Video", "Page"] %} | ||||||
| <div class="ap-object {% if expanded %}ap-object-expanded {% endif %}h-entry" id="{{ object.permalink_id }}"> | <div class="ap-object {% if expanded %}ap-object-expanded {% endif %}h-entry" id="{{ object.permalink_id }}"> | ||||||
|     {{ display_actor(object.actor, actors_metadata, embedded=True) }} |     {{ display_actor(object.actor, actors_metadata, embedded=True) }} | ||||||
|  |  | ||||||
| @@ -272,7 +274,6 @@ | |||||||
|         </a> |         </a> | ||||||
|     {% endif %} |     {% endif %} | ||||||
|  |  | ||||||
|  |  | ||||||
|     {% if object.summary %} |     {% if object.summary %} | ||||||
|         <p class="p-summary">{{ object.summary | clean_html(object) | safe }}</p> |         <p class="p-summary">{{ object.summary | clean_html(object) | safe }}</p> | ||||||
|     {% endif %} |     {% endif %} | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user