From 495e955378d62dc439c4c210785e5d401bc77f64 Mon Sep 17 00:00:00 2001 From: Andrew Godwin Date: Wed, 16 Nov 2022 06:53:39 -0700 Subject: Tag and visibility handling --- core/ld.py | 12 ++++++++++++ core/views.py | 37 ++++++++++++++++++++++++++++++++++++- 2 files changed, 48 insertions(+), 1 deletion(-) (limited to 'core') diff --git a/core/ld.py b/core/ld.py index 346708c..6692dab 100644 --- a/core/ld.py +++ b/core/ld.py @@ -414,6 +414,18 @@ def canonicalise(json_data: Dict, include_security: bool = False) -> Dict: return jsonld.compact(jsonld.expand(json_data), context) +def get_list(container, key) -> List: + """ + Given a JSON-LD value (that can be either a list, or a dict if it's just + one item), always returns a list""" + if key not in container: + return [] + value = container[key] + if not isinstance(value, list): + return [value] + return value + + def format_ld_date(value: datetime.datetime) -> str: return value.strftime(DATETIME_FORMAT) diff --git a/core/views.py b/core/views.py index 30eaf90..2ef83cc 100644 --- a/core/views.py +++ b/core/views.py @@ -1,4 +1,6 @@ -from django.views.generic import TemplateView +from django.http import JsonResponse +from django.templatetags.static import static +from django.views.generic import TemplateView, View from activities.views.timelines import Home from users.models import Identity @@ -19,3 +21,36 @@ class LoggedOutHomepage(TemplateView): return { "identities": Identity.objects.filter(local=True), } + + +class AppManifest(View): + """ + Serves a PWA manifest file. This is a view as we want to drive some + items from settings. + """ + + def get(self, request): + return JsonResponse( + { + "$schema": "https://json.schemastore.org/web-manifest-combined.json", + "name": "Takahē", + "short_name": "Takahē", + "start_url": "/", + "display": "standalone", + "background_color": "#26323c", + "theme_color": "#26323c", + "description": "An ActivityPub server", + "icons": [ + { + "src": static("img/icon-128.png"), + "sizes": "128x128", + "type": "image/png", + }, + { + "src": static("img/icon-1024.png"), + "sizes": "1024x1024", + "type": "image/png", + }, + ], + } + ) -- cgit v1.2.3