Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,6 @@ coverage.xml

# Sphinx documentation
docs/_build/

# Deployment-specific extra head HTML (e.g. analytics scripts)
extra_head.html
26 changes: 26 additions & 0 deletions ckanext/digitizationknowledge/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
import ckan.authz as authz
from sqlalchemy import and_, not_, exists
from typing import Any
import os
import logging
from functools import lru_cache
from markupsafe import Markup

log = logging.getLogger(__name__)


def is_group_private(group):
Expand Down Expand Up @@ -156,10 +162,30 @@ def get_custom_featured_organizations(count: int = 1):
return []


@lru_cache(maxsize=1)
def get_extra_head_html():
"""
Read extra HTML to inject in <head> from assets/extra_head.html.
Content is cached after first read to avoid repeated file I/O.
Returns empty string if the file doesn't exist.
"""
file_path = os.path.join(
os.path.dirname(__file__), 'assets', 'extra_head.html'
)
try:
with open(file_path, 'r', encoding='utf-8') as f:
content = f.read()
log.info('Loaded extra head HTML from %s', file_path)
return Markup(content)
except FileNotFoundError:
log.debug('No extra head HTML file at %s', file_path)
return Markup('')

def get_helpers():
return {
"get_custom_featured_groups": get_custom_featured_groups,
"get_custom_featured_organizations": get_custom_featured_organizations,
"is_group_private": is_group_private,
"user_can_view_group": user_can_view_group,
"get_extra_head_html": get_extra_head_html,
}
11 changes: 8 additions & 3 deletions ckanext/digitizationknowledge/templates/base.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
{% ckan_extends %}

{% block styles %}
{{ super() }}
{% asset 'digitizationknowledge_theme/main-css' %}
<script src="//unpkg.com/alpinejs" defer></script>
{{ super() }}
{% asset 'digitizationknowledge_theme/main-css' %}
<script src="//unpkg.com/alpinejs" defer></script>
{% endblock %}

{% block head_extras %}
{{ super() }}
{{ h.get_extra_head_html() }}
{% endblock %}