fixing page and Open Graph titles for Home view (#1666)

* fixes the redundant 'Web Awesome | Web Awesome' titles
* moves logic to `.eleventy.js`
* gracefully handles no titles/og titles with `Web Awesome`
This commit is contained in:
Brian Talbot
2025-10-27 20:08:14 -04:00
committed by GitHub
parent a465f0348f
commit e4a4d2eb18
2 changed files with 12 additions and 4 deletions

View File

@@ -182,8 +182,16 @@ export default async function (eleventyConfig) {
// Attach lastUpdatedISO to page data so templates can use {{ lastUpdatedISO }} directly
eleventyConfig.addGlobalData('eleventyComputed', {
lastUpdatedISO: data => getLastModifiedISO(data.page?.inputPath, data.lastUpdated),
// Open Graph metadata with smart defaults
ogTitle: data => data.ogTitle || data.title,
// Page title with smart + default site name formatting
pageTitle: data => {
const title = data.title || siteMetadata.name;
return title !== siteMetadata.name ? `${title} | ${siteMetadata.name}` : title;
},
// Open Graph title with smart + default site name formatting
ogTitle: data => {
const ogTitle = data.ogTitle || data.title || siteMetadata.name;
return ogTitle !== siteMetadata.name ? `${ogTitle} | ${siteMetadata.name}` : ogTitle;
},
ogDescription: data => data.ogDescription || data.description,
ogImage: data => data.ogImage || siteMetadata.image,
ogUrl: data => {

View File

@@ -3,13 +3,13 @@
<meta name="description" content="{{ description }}">
{% if noindex or unlisted %}<meta name="robots" content="noindex">{% endif %}
<title>{{ title }} | {{ siteMetadata.name }}</title>
<title>{{ pageTitle }}</title>
{# Skip OG tags for unlisted/noindex pages to prevent social sharing #}
{% if not (noindex or unlisted) %}
<meta property="og:type" content="{{ ogType }}" />
<meta property="og:url" content="{{ ogUrl }}" />
<meta property="og:title" content="{{ ogTitle }} | {{ siteMetadata.name }}" />
<meta property="og:title" content="{{ ogTitle }}" />
<meta property="og:description" content="{{ ogDescription }}" />
<meta property="og:image" content="{{ ogImage }}" />
<meta property="og:site_name" content="{{ siteMetadata.name }}" />