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: 2 additions & 1 deletion cfgov/v1/jinja2/v1/layouts/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@
{%- endblock -%}
">
<meta name="searchgov_custom1" content="{{ language }}">
<meta name="searchgov_custom2" content="{{ self.desc() }}">
{# Base32 encoding used to avoid an issue with Search.gov custom fields losing capitalization. -#}
<meta name="searchgov_custom2" content="{{ encode_b32_string(self.desc()) }}">
Comment thread
wpears marked this conversation as resolved.

{# Always open preview panel links in a new tab. #}
{% if request.in_preview_panel %}
Expand Down
7 changes: 7 additions & 0 deletions cfgov/v1/jinja2tags/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from base64 import b32encode

from jinja2 import pass_context
from jinja2.ext import Extension

Expand Down Expand Up @@ -51,6 +53,10 @@ def unique_id_in_context(context):
return get_unique_id()


def encode_b32_string(s):
return b32encode(s.encode("utf-8")).decode("utf-8")


class V1Extension(Extension):
def __init__(self, environment):
super().__init__(environment)
Expand All @@ -63,6 +69,7 @@ def __init__(self, environment):
"get_unique_id": get_unique_id,
"is_filter_selected": pass_context(is_filter_selected),
"unique_id_in_context": pass_context(unique_id_in_context),
"encode_b32_string": encode_b32_string,
"app_url": app_url,
"app_page_url": app_page_url,
}
Expand Down
2 changes: 1 addition & 1 deletion cfgov/v1/sitemap.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Sitemap(WagtailSitemap):
# Used to set a minimum modified date for all pages in the sitemap.
# This can be updated to trigger sitemap updates that are not reflected
# in Wagtail page publish events.
MIN_SITEMAP_DATE = datetime(2025, 6, 4, tzinfo=timezone.utc)
MIN_SITEMAP_DATE = datetime(2025, 7, 9, tzinfo=timezone.utc)
latest_lastmod = MIN_SITEMAP_DATE

def get_urls(self, page=1, site=None, protocol=None):
Expand Down
13 changes: 13 additions & 0 deletions cfgov/v1/tests/jinja2tags/test_jinja2tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,16 @@ def test_nonexistent_category_name_returns_none(self):
self.checkRender(
"{{ get_category_icon('Invalid category name') }}", "None"
)


class TestEncodeB32String(SimpleTestCase):
def setUp(self):
self.jinja_engine = engines["wagtail-env"]

def test_encode_b32_string(self):
s = (
"{%- block desc -%}cfpb{%- endblock -%}"
"{{encode_b32_string(self.desc())}}"
)
template = self.jinja_engine.from_string(s)
self.assertEqual(template.render(), "cfpbMNTHAYQ=")
6 changes: 3 additions & 3 deletions cfgov/v1/tests/test_sitemap.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ def test_sitemap(self):
(
b'<?xml version="1.0" encoding="UTF-8"?>\n'
b'<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml">\n'
b"<url><loc>http://localhost/</loc><lastmod>2025-06-03</lastmod></url>"
b"<url><loc>http://localhost/old/</loc><lastmod>2025-06-03</lastmod></url>\n"
b"<url><loc>http://localhost/</loc><lastmod>2025-07-08</lastmod></url>"
b"<url><loc>http://localhost/old/</loc><lastmod>2025-07-08</lastmod></url>\n"
b"</urlset>\n"
),
)

# The Last-Modified header should also be set appropriately.
self.assertEqual(
response["Last-Modified"], "Wed, 04 Jun 2025 00:00:00 GMT"
response["Last-Modified"], "Wed, 09 Jul 2025 00:00:00 GMT"
)
Loading