takahe/activities/templatetags/opengraph.py
Corry Haines b53504fe64
Basic OpenGraph support (#267)
Creates an OpenGraph template include in base.html including the basic tags expected on all pages.

Then allows any page to add additional expected tags via `context`.

Currently, profiles and posts are enriched to show complete opengraph metadata, and render correctly in Discord.

Note: This does not show posts in Slack like Twitter/Mastodon do. I believe this is due to Slack preferring oembed when present, which is a mastodon API endpoint we may need to create at some point.
2022-12-26 10:39:33 -07:00

24 lines
527 B
Python

from django import template
register = template.Library()
@register.filter
def dict_merge(base: dict, defaults: dict):
"""
Merges two input dictionaries, returning the merged result.
`input|dict_merge:defaults`
The defaults are overridden by any key present in the `input` dict.
"""
if not (isinstance(base, dict) or isinstance(defaults, dict)):
raise ValueError("Filter inputs must be dictionaries")
result = {}
result.update(defaults)
result.update(base)
return result