Skip to content

Commit f37bca6

Browse files
authored
Merge pull request #1333 from makeabilitylab/1324-meta-description-fallbacks
feat(seo): smarter meta-description fallbacks; trim over-long defaults (2.12.1, #1142/#1324)
2 parents 5faf178 + 01d5d97 commit f37bca6

5 files changed

Lines changed: 55 additions & 8 deletions

File tree

makeabilitylab/settings.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@
7272
ALLOWED_HOSTS = ['*']
7373

7474
# Makeability Lab Global Variables, including Makeability Lab version
75-
ML_WEBSITE_VERSION = "2.12.0" # Keep this updated with each release and also change the short description below
76-
ML_WEBSITE_VERSION_DESCRIPTION = "Minor: site-wide SEO / social-sharing metadata overhaul (#1236, #1142, #1324). Centralized per-page Open Graph + Twitter Card tags with https URLs behind the TLS proxy (fixes #1236 via a site_scheme context processor), self-referential canonical links, distinct per-page meta descriptions, and schema.org JSON-LD (Organization on home, Person w/ sameAs on member pages, NewsArticle on news). Adds ORCID + Google Scholar fields to Person. IT follow-up #1329 (SECURE_PROXY_SSL_HEADER) would supersede the site_scheme workaround."
75+
ML_WEBSITE_VERSION = "2.12.1" # Keep this updated with each release and also change the short description below
76+
ML_WEBSITE_VERSION_DESCRIPTION = "Patch: tighten meta descriptions (#1142/#1324). Home now uses a concise description mirroring the hero blurb; projects without a one-line summary fall back to a truncated About instead of the generic lab boilerplate; the last-resort default is trimmed to ~135 chars. Reduces duplicate/over-long descriptions flagged by social/OG inspectors. Template/view-only — no schema change."
7777
DATE_MAKEABILITYLAB_FORMED = datetime.date(2012, 1, 1) # Date Makeability Lab was formed
7878
MAX_BANNERS = 7 # Maximum number of banners on a page
7979

website/templates/website/base.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
============================================================================
8080
{% endcomment %}
8181
{% with meta_title=page_meta.title|default:"Makeability Lab" og_type=page_meta.og_type|default:"website" canonical_path=page_meta.canonical_path|default:request.path %}
82-
{% firstof page_meta.description "The Makeability Lab is an advanced research lab in Human-Computer Interaction and AI directed by Professor Jon E. Froehlich at University of Washington's Allen School of Computer Science." as meta_description %}
82+
{% firstof page_meta.description "The Makeability Lab is an advanced research lab in Human-AI directed by Prof. Jon E. Froehlich at UW's Allen School of Computer Science." as meta_description %}
8383
<meta name="description" content="{{ meta_description }}">
8484
<link rel="canonical" href="{{ site_scheme }}://{{ request.get_host }}{{ canonical_path }}">
8585

website/tests/test_page_metadata.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,45 @@ def test_jsonld_escapes_script_breakout(self):
205205
self.assertEqual(data["headline"], "Pwn </script><b>x</b>") # round-trips
206206

207207

208+
class DescriptionFallbackTests(DatabaseTestCase):
209+
"""Distinct, length-bounded descriptions instead of the generic boilerplate
210+
(#1142/#1324): home mirrors the hero blurb; summary-less projects use About."""
211+
212+
def _meta_description(self, resp):
213+
m = re.search(r'name="description" content="([^"]*)"', resp.content.decode())
214+
return m.group(1) if m else None
215+
216+
def test_home_uses_distinct_hero_description(self):
217+
resp = self.client.get(reverse("website:index"))
218+
desc = self._meta_description(resp)
219+
self.assertIn("advanced research lab in Human-AI, directed by", desc)
220+
self.assertLessEqual(len(desc), 160)
221+
# not the old generic boilerplate
222+
self.assertNotIn("Human-Computer Interaction and AI directed by Professor", desc)
223+
224+
def test_project_without_summary_falls_back_to_about(self):
225+
p = self.make_project(
226+
name="GlassEar", short_name="glassear", is_visible=True,
227+
start_date=date(2021, 1, 1), summary="",
228+
about="<p>GlassEar is a wearable sound-awareness display for d/Deaf users.</p>",
229+
)
230+
resp = self.client.get(reverse("website:project", args=[p.short_name]))
231+
desc = self._meta_description(resp)
232+
self.assertIn("GlassEar is a wearable sound-awareness display", desc)
233+
self.assertLessEqual(len(desc), 160)
234+
235+
def test_project_without_summary_or_about_uses_trimmed_default(self):
236+
p = self.make_project(
237+
name="Empty Proj", short_name="emptyproj", is_visible=True,
238+
start_date=date(2021, 1, 1), summary="", about="",
239+
)
240+
resp = self.client.get(reverse("website:project", args=[p.short_name]))
241+
desc = self._meta_description(resp)
242+
# last-resort generic default — present but trimmed
243+
self.assertIn("Makeability Lab", desc)
244+
self.assertLessEqual(len(desc), 160)
245+
246+
208247
class PageMetadataSchemeTests(DatabaseTestCase):
209248
"""site_scheme keys off DJANGO_ENV, not DEBUG. The test server runs DEBUG=True
210249
behind the same TLS proxy as prod, so a DEBUG-based check would emit http://

website/views/index.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,14 @@ def index(request):
7979
'sponsors': sponsors,
8080
'debug': settings.DEBUG}
8181

82+
# Distinct home-page description, mirroring the hero "About Us" blurb next to
83+
# the animated logo (index.html). Concise (~155 chars) so it isn't truncated
84+
# in search/social previews, and not the generic fallback (#1142/#1324).
85+
home_description = ("The Makeability Lab is an advanced research lab in Human-AI, "
86+
"directed by Prof. Jon E. Froehlich in UW's Allen School of "
87+
"Computer Science.")
88+
context['page_meta'] = {'description': home_description}
89+
8290
# schema.org Organization JSON-LD (home page) — helps Google build a
8391
# knowledge panel for "Makeability Lab" (#1142/#1324). Rendered by the
8492
# jsonld block in base.html.
@@ -89,10 +97,7 @@ def index(request):
8997
"url": absolute_url(request, "/"),
9098
"logo": absolute_url(request, static(
9199
"website/img/logos/makelab_logo_v3_white_with_colors_and_text_og_image_ratio_1200w.png")),
92-
"description": ("The Makeability Lab is an advanced research lab in "
93-
"Human-Computer Interaction and AI directed by Professor "
94-
"Jon E. Froehlich at the University of Washington's Allen "
95-
"School of Computer Science."),
100+
"description": home_description,
96101
"parentOrganization": {
97102
"@type": "CollegeOrUniversity",
98103
"name": ("Paul G. Allen School of Computer Science & Engineering, "

website/views/project.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,10 @@ def project(request, project_name):
121121
# /projects/ alias to one indexable URL.
122122
context['page_meta'] = {
123123
'title': project.name,
124-
'description': meta_description(project.summary),
124+
# Prefer the one-line summary; fall back to the (HTML) About text,
125+
# stripped + truncated. Gives summary-less projects a distinct
126+
# description instead of the generic lab boilerplate (#1142/#1324).
127+
'description': meta_description(project.summary or project.about),
125128
'canonical_path': reverse('website:project', args=[project.short_name]),
126129
}
127130

0 commit comments

Comments
 (0)