Skip to content

Commit

Permalink
Merge pull request #2391 from digitalfabrik/feature/socialmedia-headers
Browse files Browse the repository at this point in the history
Add API for social media tags
  • Loading branch information
timobrembeck authored Jun 5, 2024
2 parents 5c6602a + 5158344 commit 0e61a90
Show file tree
Hide file tree
Showing 40 changed files with 1,016 additions and 3 deletions.
37 changes: 37 additions & 0 deletions docs/src/api-docs.rst
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,43 @@ RESPONSE
A single object following the layout of :ref:`api_regions`


Social Media
============

Get social media headers for a frontend url

REQUEST
~~~~~~~

Get the social media headers for a frontend url.
The absolute url is the `path to resource <https://developer.mozilla.org/en-US/docs/Learn/Common_questions/Web_mechanics/What_is_a_URL#path_to_resource>`_ of the frontent url

.. code:: http
GET /api/v3/social/{absolute_url}/ HTTP/2
.. code:: http
GET /api/v3/social/ HTTP/2
RESPONSE
~~~~~~~~

Rendered HTML that contains social media headers describing the object of the given url.
Please keep in mind that the response contains partial ``<html>`` and ``<head>`` tags to allow the response to contain a language attribute in the root tag.
This needs to be equalized in the server-side include e.g. as follows:

.. code:: html

<!-- Nginx Server Side Include template for dynamic social media previews -->
<!--# if expr="$render_title = yes" -->
<!--# include virtual="/proxy/socialmeta/$request_uri" -->
<!--# else -->
<html>
<head>
<!--# endif -->


Languages
=========

Expand Down
85 changes: 85 additions & 0 deletions integreat_cms/api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

from django.urls import include, path, re_path

from ..core import settings
from .v3.events import events
from .v3.feedback import (
event_feedback,
Expand Down Expand Up @@ -37,6 +38,14 @@
from .v3.pdf_export import pdf_export
from .v3.push_notifications import sent_push_notifications
from .v3.regions import region_by_slug, regions
from .v3.social_media_headers import (
event_social_media_headers,
location_social_media_headers,
news_social_media_headers,
page_social_media_headers,
region_social_media_headers,
root_social_media_headers,
)

if TYPE_CHECKING:
from typing import Final
Expand Down Expand Up @@ -129,10 +138,86 @@
path("<slug:region_slug>/", region_by_slug, name="region_by_slug"),
]

social_media_api_urlpatterns = [
path("", root_social_media_headers, name="social_root"),
*(
path(
f"{reserved}/",
include(
[
path(
"",
root_social_media_headers,
name=f"social_root_reserved_{reserved}",
),
path(
"<slug:language_slug>/",
root_social_media_headers,
name=f"social_root_reserved_default_language_{reserved}",
),
]
),
)
for reserved in settings.RESERVED_REGION_SLUGS
),
path(
"<slug:region_slug>/",
region_social_media_headers,
name="social_region_default_language",
),
path(
"<slug:region_slug>/<slug:language_slug>/",
include(
[
path("", region_social_media_headers, name="social_region"),
path(
"news/local/",
region_social_media_headers,
name="social_region_reserved_local_news",
),
re_path(
r"^news/tunews/[\w-]+/$",
region_social_media_headers,
name="social_region_reserved_tunews",
),
*(
path(
f"{reserved}/",
region_social_media_headers,
name=f"social_region_reserved_{reserved}",
)
for reserved in settings.RESERVED_REGION_PAGE_PATTERNS
),
path(
"events/<slug:slug>/",
event_social_media_headers,
name="social_region_event_page",
),
path(
"news/local/<slug:slug>/",
news_social_media_headers,
name="social_region_local_news_page",
),
path(
"locations/<slug:slug>/",
location_social_media_headers,
name="social_region_location_page",
),
path(
"<path:path>/",
page_social_media_headers,
name="social_region_content",
),
]
),
),
]

#: The url patterns of this module (see :doc:`django:topics/http/urls`)
urlpatterns: list[URLPattern] = [
path("api/v3/regions/", include(region_api_urlpatterns)),
path("wp-json/extensions/v3/sites/", include(region_api_urlpatterns)),
path("api/v3/social/", include(social_media_api_urlpatterns)),
path(
"api/v3/<slug:region_slug>/",
include(
Expand Down
Loading

0 comments on commit 0e61a90

Please sign in to comment.