diff --git a/roles/web-app-littlejs/config/main.yml b/roles/web-app-littlejs/config/main.yml index bc481686..9d6f2019 100644 --- a/roles/web-app-littlejs/config/main.yml +++ b/roles/web-app-littlejs/config/main.yml @@ -1,8 +1,8 @@ features: - matomo: true - css: true - desktop: true - logout: false + css: true + matomo: true + desktop: true + logout: false server: csp: diff --git a/roles/web-app-littlejs/filter_plugins/littlejs.py b/roles/web-app-littlejs/filter_plugins/littlejs.py new file mode 100644 index 00000000..36c9304e --- /dev/null +++ b/roles/web-app-littlejs/filter_plugins/littlejs.py @@ -0,0 +1,30 @@ +def littlejs_href(example, protocol, domain): + """ + Build correct LittleJS example URL based on whether it is a full project + or a single-file example. + + :param example: dict with keys 'is_project' and 'file' + :param protocol: http or https + :param domain: the domain to use (e.g. littlejs.example.com) + :return: string URL + """ + + file = example.get("file") + is_project = example.get("is_project", False) + + if not file: + return "#" + + # Full examples: always absolute URL + if is_project: + return f"{protocol}://{domain}/examples/{file}/" + + # Short examples: internal wrapper + return f"{protocol}://{domain}/examples/shorts/base.html?file={file}" + + +class FilterModule(object): + def filters(self): + return { + "littlejs_href": littlejs_href + } diff --git a/roles/web-app-littlejs/templates/html/main.html.j2 b/roles/web-app-littlejs/templates/html/main.html.j2 index b7a5da57..cfb37901 100644 --- a/roles/web-app-littlejs/templates/html/main.html.j2 +++ b/roles/web-app-littlejs/templates/html/main.html.j2 @@ -11,12 +11,7 @@ {% for key, cat in littlejs_examples|dictsort %} {% for ex in cat['items'] %} - {% if ex.is_project %} - {% set href = "/examples/" ~ ex.file ~ "/" %} - {% else %} - {% set href = "/examples/shorts/base.html?file=" ~ ex.file %} - {% endif %} - + {% set href = ex | littlejs_href(WEB_PROTOCOL, domain) %}
diff --git a/roles/web-app-littlejs/templates/html/nav_top.html.j2 b/roles/web-app-littlejs/templates/html/nav_top.html.j2 index fe9d07f5..a2a91d93 100644 --- a/roles/web-app-littlejs/templates/html/nav_top.html.j2 +++ b/roles/web-app-littlejs/templates/html/nav_top.html.j2 @@ -30,15 +30,9 @@