Add custom_head config to inject HTML in to page <head> (#350)

This commit is contained in:
Michael Manfre 2023-01-04 18:42:03 -05:00 committed by GitHub
parent 4547ed1c71
commit 69b0430819
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 0 deletions

View file

@ -235,6 +235,8 @@ class Config(models.Model):
restricted_usernames: str = "admin\nadmins\nadministrator\nadministrators\nsystem\nroot\nannounce\nannouncement\nannouncements" restricted_usernames: str = "admin\nadmins\nadministrator\nadministrators\nsystem\nroot\nannounce\nannouncement\nannouncements"
custom_head: str | None
class UserOptions(pydantic.BaseModel): class UserOptions(pydantic.BaseModel):
pass pass

View file

@ -30,6 +30,7 @@
{% include "_opengraph.html" with opengraph_local=opengraph_defaults %} {% include "_opengraph.html" with opengraph_local=opengraph_defaults %}
{% endblock %} {% endblock %}
{% block extra_head %}{% endblock %} {% block extra_head %}{% endblock %}
{% block custom_head %}{% if config.custom_head %}{{ config.custom_head|safe }}{% endif %}{% endblock %}
</head> </head>
<body class="{% block body_class %}{% endblock %}" hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'> <body class="{% block body_class %}{% endblock %}" hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'>
<a id='skip-to-main' class='screenreader-text' href='#main-content'>Skip to Content</a> <a id='skip-to-main' class='screenreader-text' href='#main-content'>Skip to Content</a>

View file

@ -101,6 +101,11 @@ class BasicSettings(AdminSettingsPage):
"title": "Show Public Timeline On Front Page", "title": "Show Public Timeline On Front Page",
"help_text": "Whether to show some recent posts on the logged-out homepage", "help_text": "Whether to show some recent posts on the logged-out homepage",
}, },
"custom_head": {
"title": "HTML <head> Extra",
"help_text": "Add custom HTML to the &lt;head&gt; of all pages (except /djadmin/).\nNote: This can break page rendering/layout.",
"display": "textarea",
},
} }
layout = { layout = {
@ -110,6 +115,7 @@ class BasicSettings(AdminSettingsPage):
"site_icon", "site_icon",
"site_banner", "site_banner",
"highlight_color", "highlight_color",
"custom_head",
], ],
"Signups": [ "Signups": [
"signup_allowed", "signup_allowed",