This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch fix/seo-meta in repository https://gitbox.apache.org/repos/asf/camel-website.git
commit 86b04f14f686fe6845f78c307756cec1df08acb4 Author: Claus Ibsen <[email protected]> AuthorDate: Sun Nov 29 13:38:18 2026 +0100 Fix #1878: meta descriptions, Open Graph/Twitter cards and JSON-LD Hugo pages: - meta description and og:description from one partial: description, preview, the advisory summary, a sentence for release notes and blog categories, then the page summary; descriptions on the section pages - blog posts get og:type article, article:published_time/author/tag and a BlogPosting JSON-LD block - og:image crops the featured image to 1200x630, skips SVG and falls back to a new raster social card; twitter:card summary_large_image - Organization JSON-LD uses a raster logo and is built with jsonify; BreadcrumbList names come from page titles and only list real pages - robots.txt lists only the sitemap index Antora docs: - og:url is the page's canonical URL instead of the site root - meta description and og:description fall back to the first paragraph (new page_description helper, with tests) - og:image is the raster social card, twitter:card added - Organization JSON-LD uses the absolute raster logo and the current description instead of the old "Scala DSL" text Checks: html-validate rules camel/meta-description and camel/og-image, and test/seo-parity-test.js keeps the Antora copies in sync with config.toml. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y4dDj46SB6GniXf8mX2U6 --- .htmlvalidate.json | 2 + .../public/_/helpers/page_description.js | 47 +++++++++++++ antora-ui-camel/public/_/partials/head-info.hbs | 2 +- antora-ui-camel/public/_/partials/head-meta.hbs | 11 +++- .../public/_/partials/organization-microdata.hbs | 6 +- antora-ui-camel/src/helpers/page_description.js | 47 +++++++++++++ antora-ui-camel/src/partials/head-info.hbs | 2 +- antora-ui-camel/src/partials/head-meta.hbs | 11 +++- .../src/partials/organization-microdata.hbs | 6 +- antora-ui-camel/test/page-description-test.js | 48 ++++++++++++++ config.toml | 2 +- content/blog/_index.md | 1 + content/download/_index.md | 1 + content/releases/_index.md | 1 + content/security/_index.md | 1 + content/sitemap/_index.md | 1 + content/tooling/_index.md | 1 + layouts/partials/header.html | 35 +++++----- layouts/partials/seo/description.html | 34 ++++++++++ layouts/partials/seo/image.html | 18 +++++ layouts/partials/seo/schema.html | 1 + layouts/partials/seo/structured/blogposting.html | 23 +++++++ .../seo/structured/breadcrumbs-microdata.html | 42 +++++------- .../seo/structured/organization-microdata.html | 16 ++--- layouts/robots.txt | 4 -- rules.js | 73 ++++++++++++++++++++- static/img/logo-camel-512.png | Bin 0 -> 41647 bytes static/img/social-card.png | Bin 0 -> 86769 bytes test/seo-parity-test.js | 45 +++++++++++++ 29 files changed, 412 insertions(+), 69 deletions(-) diff --git a/.htmlvalidate.json b/.htmlvalidate.json index 5710ad27..65197070 100644 --- a/.htmlvalidate.json +++ b/.htmlvalidate.json @@ -7,6 +7,8 @@ ], "rules": { "attr-quotes": "off", + "camel/meta-description": "error", + "camel/og-image": "error", "camel/relative-links": "error", "camel/structured-data": "error", "camel/title": "error", diff --git a/antora-ui-camel/public/_/helpers/page_description.js b/antora-ui-camel/public/_/helpers/page_description.js new file mode 100644 index 00000000..201b34ad --- /dev/null +++ b/antora-ui-camel/public/_/helpers/page_description.js @@ -0,0 +1,47 @@ +'use strict' + +// The description for <meta name="description"> and og:description: the page's own +// `:description:` attribute when it has one, otherwise the first paragraph of the page that +// reads as a sentence. Paragraphs shorter than MIN_LENGTH ("Since Camel 4.0") and paragraphs +// that only introduce a list or a code block (ending in a colon) are skipped. + +const MAX_LENGTH = 160 +const MIN_LENGTH = 50 + +const PARAGRAPH_RX = /<div class="paragraph">\s*<p>([\s\S]*?)<\/p>/g +const TAG_RX = /<[^>]+>/g +const ENTITY_RX = /&(#x[0-9a-f]+|#[0-9]+|amp|lt|gt|quot|apos|nbsp);/gi +const NAMED_ENTITIES = { amp: '&', lt: '<', gt: '>', quot: '"', apos: "'", nbsp: ' ' } + +function decode (text) { + return text.replace(ENTITY_RX, (match, entity) => { + const lower = entity.toLowerCase() + if (lower.startsWith('#x')) return String.fromCodePoint(parseInt(lower.slice(2), 16)) + if (lower.startsWith('#')) return String.fromCodePoint(parseInt(lower.slice(1), 10)) + return NAMED_ENTITIES[lower] + }) +} + +function truncate (text) { + if (text.length <= MAX_LENGTH) return text + const cut = text.slice(0, MAX_LENGTH - 1) + const lastSpace = cut.lastIndexOf(' ') + return (lastSpace > MIN_LENGTH ? cut.slice(0, lastSpace) : cut).replace(/[\s,;:.]+$/, '') + '…' +} + +function excerpt (contents) { + if (!contents) return undefined + const html = contents.toString() + for (const [, paragraph] of html.matchAll(PARAGRAPH_RX)) { + const text = decode(paragraph.replace(TAG_RX, '')).replace(/\s+/g, ' ').trim() + if (text.length >= MIN_LENGTH && !text.endsWith(':')) return truncate(text) + } + return undefined +} + +module.exports = (page) => { + if (!page) return undefined + return page.description || excerpt(page.contents) +} + +module.exports.excerpt = excerpt diff --git a/antora-ui-camel/public/_/partials/head-info.hbs b/antora-ui-camel/public/_/partials/head-info.hbs index 32c8bee9..dc89f5f9 100644 --- a/antora-ui-camel/public/_/partials/head-info.hbs +++ b/antora-ui-camel/public/_/partials/head-info.hbs @@ -9,7 +9,7 @@ <link rel="next" href="{{{relativize ./url}}}"> {{/with}} {{/unless}} - {{#with page.description}} + {{#with (page_description page)}} <meta name="description" content="{{this}}"> {{/with}} {{#with page.keywords}} diff --git a/antora-ui-camel/public/_/partials/head-meta.hbs b/antora-ui-camel/public/_/partials/head-meta.hbs index 2da68055..35e207ae 100644 --- a/antora-ui-camel/public/_/partials/head-meta.hbs +++ b/antora-ui-camel/public/_/partials/head-meta.hbs @@ -1,10 +1,15 @@ <meta name="application-name" content="Apache Camel"> <meta property="og:title" content="{{page.title}}"> <meta property="og:site_name" content="Apache Camel"> -<meta property="og:url" content="https://camel.apache.org"> -<meta property="og:description" content="Apache Camel is an open source integration framework with 350+ connectors for databases, APIs, message brokers, and cloud services. Write routes in Java, YAML, or XML. Run on Spring Boot, Quarkus, or standalone with the Camel CLI. In production since 2007. Apache License 2.0."> +<meta property="og:url" content="{{#if page.canonicalUrl}}{{{page.canonicalUrl}}}{{else}}{{{site.url}}}{{{page.url}}}{{/if}}"> +{{! NOTE keep the fallback in sync with organizationDescription in config.toml, test/seo-parity-test.js checks it }} +<meta property="og:description" content="{{#with (page_description page)}}{{this}}{{else}}Apache Camel is an open source integration framework with 350+ connectors for databases, APIs, message brokers, and cloud services. Write routes in Java, YAML, or XML. Run on Spring Boot, Quarkus, or standalone with the Camel CLI. In production since 2007. Apache License 2.0.{{/with}}"> <meta property="og:type" content="website"> -<meta property="og:image" content="{{site.url}}/_/img/logo-d-a567cee6fa.svg"> +{{! NOTE a raster card served from the Hugo static/ directory: social platforms do not render SVG }} +<meta property="og:image" content="{{{site.url}}}/img/social-card.png"> +<meta property="og:image:width" content="1200"> +<meta property="og:image:height" content="630"> +<meta name="twitter:card" content="summary_large_image"> <link rel="manifest" href="{{siteRootPath}}/site.webmanifest"> <link rel="alternate" type="text/plain" title="llms.txt: documentation index for AI tools" href="{{siteRootPath}}/llms.txt"> {{! Add additional meta tags here}} diff --git a/antora-ui-camel/public/_/partials/organization-microdata.hbs b/antora-ui-camel/public/_/partials/organization-microdata.hbs index b24fee84..9b0e3d37 100644 --- a/antora-ui-camel/public/_/partials/organization-microdata.hbs +++ b/antora-ui-camel/public/_/partials/organization-microdata.hbs @@ -1,13 +1,13 @@ <script type='application/ld+json'> { - "@context": "http://schema.org", + "@context": "https://schema.org", "@type": "Organization", "name": "{{{site.title}}}", "url": "{{{site.url}}}", "sameAs": [ "https://twitter.com/ApacheCamel" ], - "logo": "{{uiRootPath}}/img/logo-d-a567cee6fa.svg", - "description": "Apache Camel ™ is a versatile open-source integration framework based on known Enterprise Integration Patterns. Camel empowers you to define routing and mediation rules in a variety of domain-specific languages, including a Java-based Fluent API, Spring or Blueprint XML Configuration files, and a Scala DSL." + "logo": "{{{site.url}}}/img/logo-camel-512.png", + "description": "Apache Camel is an open source integration framework with 350+ connectors for databases, APIs, message brokers, and cloud services. Write routes in Java, YAML, or XML. Run on Spring Boot, Quarkus, or standalone with the Camel CLI. In production since 2007. Apache License 2.0." } </script> diff --git a/antora-ui-camel/src/helpers/page_description.js b/antora-ui-camel/src/helpers/page_description.js new file mode 100644 index 00000000..201b34ad --- /dev/null +++ b/antora-ui-camel/src/helpers/page_description.js @@ -0,0 +1,47 @@ +'use strict' + +// The description for <meta name="description"> and og:description: the page's own +// `:description:` attribute when it has one, otherwise the first paragraph of the page that +// reads as a sentence. Paragraphs shorter than MIN_LENGTH ("Since Camel 4.0") and paragraphs +// that only introduce a list or a code block (ending in a colon) are skipped. + +const MAX_LENGTH = 160 +const MIN_LENGTH = 50 + +const PARAGRAPH_RX = /<div class="paragraph">\s*<p>([\s\S]*?)<\/p>/g +const TAG_RX = /<[^>]+>/g +const ENTITY_RX = /&(#x[0-9a-f]+|#[0-9]+|amp|lt|gt|quot|apos|nbsp);/gi +const NAMED_ENTITIES = { amp: '&', lt: '<', gt: '>', quot: '"', apos: "'", nbsp: ' ' } + +function decode (text) { + return text.replace(ENTITY_RX, (match, entity) => { + const lower = entity.toLowerCase() + if (lower.startsWith('#x')) return String.fromCodePoint(parseInt(lower.slice(2), 16)) + if (lower.startsWith('#')) return String.fromCodePoint(parseInt(lower.slice(1), 10)) + return NAMED_ENTITIES[lower] + }) +} + +function truncate (text) { + if (text.length <= MAX_LENGTH) return text + const cut = text.slice(0, MAX_LENGTH - 1) + const lastSpace = cut.lastIndexOf(' ') + return (lastSpace > MIN_LENGTH ? cut.slice(0, lastSpace) : cut).replace(/[\s,;:.]+$/, '') + '…' +} + +function excerpt (contents) { + if (!contents) return undefined + const html = contents.toString() + for (const [, paragraph] of html.matchAll(PARAGRAPH_RX)) { + const text = decode(paragraph.replace(TAG_RX, '')).replace(/\s+/g, ' ').trim() + if (text.length >= MIN_LENGTH && !text.endsWith(':')) return truncate(text) + } + return undefined +} + +module.exports = (page) => { + if (!page) return undefined + return page.description || excerpt(page.contents) +} + +module.exports.excerpt = excerpt diff --git a/antora-ui-camel/src/partials/head-info.hbs b/antora-ui-camel/src/partials/head-info.hbs index 32c8bee9..dc89f5f9 100644 --- a/antora-ui-camel/src/partials/head-info.hbs +++ b/antora-ui-camel/src/partials/head-info.hbs @@ -9,7 +9,7 @@ <link rel="next" href="{{{relativize ./url}}}"> {{/with}} {{/unless}} - {{#with page.description}} + {{#with (page_description page)}} <meta name="description" content="{{this}}"> {{/with}} {{#with page.keywords}} diff --git a/antora-ui-camel/src/partials/head-meta.hbs b/antora-ui-camel/src/partials/head-meta.hbs index 8417d0bd..35e207ae 100644 --- a/antora-ui-camel/src/partials/head-meta.hbs +++ b/antora-ui-camel/src/partials/head-meta.hbs @@ -1,10 +1,15 @@ <meta name="application-name" content="Apache Camel"> <meta property="og:title" content="{{page.title}}"> <meta property="og:site_name" content="Apache Camel"> -<meta property="og:url" content="https://camel.apache.org"> -<meta property="og:description" content="Apache Camel is an open source integration framework with 350+ connectors for databases, APIs, message brokers, and cloud services. Write routes in Java, YAML, or XML. Run on Spring Boot, Quarkus, or standalone with the Camel CLI. In production since 2007. Apache License 2.0."> +<meta property="og:url" content="{{#if page.canonicalUrl}}{{{page.canonicalUrl}}}{{else}}{{{site.url}}}{{{page.url}}}{{/if}}"> +{{! NOTE keep the fallback in sync with organizationDescription in config.toml, test/seo-parity-test.js checks it }} +<meta property="og:description" content="{{#with (page_description page)}}{{this}}{{else}}Apache Camel is an open source integration framework with 350+ connectors for databases, APIs, message brokers, and cloud services. Write routes in Java, YAML, or XML. Run on Spring Boot, Quarkus, or standalone with the Camel CLI. In production since 2007. Apache License 2.0.{{/with}}"> <meta property="og:type" content="website"> -<meta property="og:image" content="{{site.url}}/_/img/logo-d.svg"> +{{! NOTE a raster card served from the Hugo static/ directory: social platforms do not render SVG }} +<meta property="og:image" content="{{{site.url}}}/img/social-card.png"> +<meta property="og:image:width" content="1200"> +<meta property="og:image:height" content="630"> +<meta name="twitter:card" content="summary_large_image"> <link rel="manifest" href="{{siteRootPath}}/site.webmanifest"> <link rel="alternate" type="text/plain" title="llms.txt: documentation index for AI tools" href="{{siteRootPath}}/llms.txt"> {{! Add additional meta tags here}} diff --git a/antora-ui-camel/src/partials/organization-microdata.hbs b/antora-ui-camel/src/partials/organization-microdata.hbs index 71a80ab4..9b0e3d37 100644 --- a/antora-ui-camel/src/partials/organization-microdata.hbs +++ b/antora-ui-camel/src/partials/organization-microdata.hbs @@ -1,13 +1,13 @@ <script type='application/ld+json'> { - "@context": "http://schema.org", + "@context": "https://schema.org", "@type": "Organization", "name": "{{{site.title}}}", "url": "{{{site.url}}}", "sameAs": [ "https://twitter.com/ApacheCamel" ], - "logo": "{{uiRootPath}}/img/logo-d.svg", - "description": "Apache Camel ™ is a versatile open-source integration framework based on known Enterprise Integration Patterns. Camel empowers you to define routing and mediation rules in a variety of domain-specific languages, including a Java-based Fluent API, Spring or Blueprint XML Configuration files, and a Scala DSL." + "logo": "{{{site.url}}}/img/logo-camel-512.png", + "description": "Apache Camel is an open source integration framework with 350+ connectors for databases, APIs, message brokers, and cloud services. Write routes in Java, YAML, or XML. Run on Spring Boot, Quarkus, or standalone with the Camel CLI. In production since 2007. Apache License 2.0." } </script> diff --git a/antora-ui-camel/test/page-description-test.js b/antora-ui-camel/test/page-description-test.js new file mode 100644 index 00000000..340cb6f7 --- /dev/null +++ b/antora-ui-camel/test/page-description-test.js @@ -0,0 +1,48 @@ +'use strict' + +const assert = require('node:assert/strict') +const test = require('node:test') + +const pageDescription = require('../src/helpers/page_description') + +const paragraph = (html) => `<div class="paragraph">\n<p>${html}</p>\n</div>` + +test('the description attribute wins over the page content', () => { + const page = { description: 'Send and receive messages to/from an Apache Kafka broker.', contents: paragraph('x'.repeat(80)) } + assert.equal(pageDescription(page), 'Send and receive messages to/from an Apache Kafka broker.') +}) + +test('falls back to the first paragraph, without markup and with entities decoded', () => { + const contents = Buffer.from( + '<div id="preamble">' + + paragraph('Apache Camel™ is a versatile open-source integration framework based on known <a href="eips.html">Enterprise Integration Patterns</a>.') + + paragraph('Second paragraph that should not be used for the description at all.') + + '</div>' + ) + assert.equal( + pageDescription({ contents }), + 'Apache Camel™ is a versatile open-source integration framework based on known Enterprise Integration Patterns.' + ) +}) + +test('skips short paragraphs and paragraphs introducing a list', () => { + const contents = + paragraph('<strong>Since Camel 4.0</strong>') + + paragraph('This version of Camel Quarkus depends on the following projects:') + + paragraph('This project brings the integration capabilities of Apache Camel to Quarkus applications.') + assert.equal(pageDescription({ contents }), 'This project brings the integration capabilities of Apache Camel to Quarkus applications.') +}) + +test('truncates long paragraphs on a word boundary', () => { + const text = 'The Camel CLI is the command-line interface for Apache Camel. '.repeat(5).trim() + const description = pageDescription({ contents: paragraph(text) }) + assert.ok(description.length <= 160, `expected at most 160 characters, got ${description.length}`) + assert.ok(description.endsWith('…')) + assert.ok(text.startsWith(description.slice(0, -1))) +}) + +test('returns nothing for pages without a usable paragraph', () => { + assert.equal(pageDescription({ contents: '<div class="ulist"><ul><li><p>item</p></li></ul></div>' }), undefined) + assert.equal(pageDescription({}), undefined) + assert.equal(pageDescription(undefined), undefined) +}) diff --git a/config.toml b/config.toml index d2c3f0bd..b64489b9 100644 --- a/config.toml +++ b/config.toml @@ -19,7 +19,7 @@ defaultMarkdownHandler = "goldmark" [params] socialProfiles = ["https://twitter.com/ApacheCamel"] - organizationLogo = "https://camel.apache.org/_/img/logo-d.svg" + organizationLogo = "https://camel.apache.org/img/logo-camel-512.png" organizationDescription = "Apache Camel is an open source integration framework with 350+ connectors for databases, APIs, message brokers, and cloud services. Write routes in Java, YAML, or XML. Run on Spring Boot, Quarkus, or standalone with the Camel CLI. In production since 2007. Apache License 2.0." GitHubUsername = "" GitHubToken = "" diff --git a/content/blog/_index.md b/content/blog/_index.md index 59db2268..337da27a 100644 --- a/content/blog/_index.md +++ b/content/blog/_index.md @@ -1,3 +1,4 @@ --- title: "Blog" +description: "News, release announcements, how-to guides and feature deep dives from the Apache Camel community." --- diff --git a/content/download/_index.md b/content/download/_index.md index 51af4a8f..edcb084a 100644 --- a/content/download/_index.md +++ b/content/download/_index.md @@ -1,5 +1,6 @@ --- title: "Downloads" +description: "Download Apache Camel and its sub-projects: latest and LTS releases, the Camel CLI, source archives, SBOMs and verification instructions." cli_command: "curl -fsSL https://camel.apache.org/install.sh | sh" sbom_card_body: "Every release since 4.0.3 includes PGP-signed CycloneDX SBOMs (JSON and XML) listed alongside the source download above. Feed them into tools like [OWASP Dependency-Track](https://dependencytrack.org/) for automated vulnerability scanning, or see [Generating SBOMs](/manual/sbom.html) for your own application." verify_card_body: "You can verify your download by following these [procedures](http://www.apache.org/info/verification.html) and using these [KEYS](https://www.apache.org/dist/camel/KEYS)." diff --git a/content/releases/_index.md b/content/releases/_index.md index 3666bd35..42fcbf72 100644 --- a/content/releases/_index.md +++ b/content/releases/_index.md @@ -1,3 +1,4 @@ --- title: "Releases archive" +description: "Archive of all Apache Camel releases and their release notes: Camel, Camel Quarkus, Camel K, Camel Kafka Connector, Kamelets and more." --- diff --git a/content/security/_index.md b/content/security/_index.md index ba5d88fd..03ad5043 100644 --- a/content/security/_index.md +++ b/content/security/_index.md @@ -1,5 +1,6 @@ --- title: "Security" +description: "Apache Camel security advisories (CVEs), the security model, and how to report a vulnerability to the Apache Camel PMC." lead: "Apache Camel security information." read_first: eyebrow: "Read first" diff --git a/content/sitemap/_index.md b/content/sitemap/_index.md index 79a415f0..148815fc 100644 --- a/content/sitemap/_index.md +++ b/content/sitemap/_index.md @@ -1,3 +1,4 @@ --- title: "Sitemap" +description: "An index of the pages on the Apache Camel website." --- \ No newline at end of file diff --git a/content/tooling/_index.md b/content/tooling/_index.md index c9bb3e4b..b1271b37 100644 --- a/content/tooling/_index.md +++ b/content/tooling/_index.md @@ -1,5 +1,6 @@ --- title: "Tooling" +description: "Tools for building Apache Camel integrations: the Camel CLI, IDE plugins, visual editors and more." editPath: data/tooling.yaml layout: list --- diff --git a/layouts/partials/header.html b/layouts/partials/header.html index b0ca1d67..ec3c3d38 100644 --- a/layouts/partials/header.html +++ b/layouts/partials/header.html @@ -18,34 +18,39 @@ <link rel="icon" type="image/png" href="{{ "favicon-128.png" | relURL }}" sizes="128x128"> <meta name="application-name" content="Apache Camel"> + {{ $description := partial "seo/description.html" . }} + {{ $image := partial "seo/image.html" . }} + {{ $isPost := and .IsPage (eq .Section "blog") }} <meta property="og:title" content="{{ .Title }}"> <meta property="og:site_name" content="{{ .Site.Title }}"> <meta property="og:url" content="{{ .Permalink }}"> - {{ if .Description}} - <meta property="og:description" content="{{ .Description }}"> - {{ else }} - {{ if .Params.preview}} - <meta property="og:description" content="{{ .Params.preview }}"> - {{ end }} + {{ with $description }} + <meta property="og:description" content="{{ . }}"> {{ end }} - <meta property="og:type" content="website"> - {{ $featured := (.Resources.ByType "image").GetMatch "*featured*" }} - {{ if not $featured }} - {{ $featured = resources.Get "img/default-featured.jpg" }} + {{ if $isPost }} + <meta property="og:type" content="article"> + <meta property="article:published_time" content="{{ .PublishDate.Format "2006-01-02T15:04:05Z07:00" }}"> + {{ range .Params.authors }} + <meta property="article:author" content="https://github.com/{{ . }}"> + {{ end }} + {{ range .Params.categories }} + <meta property="article:tag" content="{{ . }}"> {{ end }} - {{ with $featured }} - <meta property="og:image" content="{{ $featured.Permalink }}"> {{ else }} - <meta property="og:image" content="{{ .Site.Params.organizationLogo }}"> + <meta property="og:type" content="website"> {{ end }} + <meta property="og:image" content="{{ $image.url }}"> + {{ with $image.width }}<meta property="og:image:width" content="{{ . }}">{{ end }} + {{ with $image.height }}<meta property="og:image:height" content="{{ . }}">{{ end }} + <meta name="twitter:card" content="summary_large_image"> <link rel="manifest" href="{{ "site.webmanifest" | relURL }}"> <title>{{ block "title" . }}{{ .Title }} - {{ .Site.Title }}{{ end }}</title> <link rel="canonical" href="{{ .Permalink }}"> <link rel="alternate" type="application/rss+xml" title="Apache Camel Blog" href="{{ "blog/index.xml" | relURL }}"> <link rel="alternate" type="text/plain" title="llms.txt: documentation index for AI tools" href="{{ "llms.txt" | relURL }}"> - {{ if .Description}} - <meta name="description" content="{{ .Description }}"> + {{ with $description }} + <meta name="description" content="{{ . }}"> {{ end }} {{ if .Keywords}} <meta name="keywords" content="{{ delimit .Keywords "," }}"> diff --git a/layouts/partials/seo/description.html b/layouts/partials/seo/description.html new file mode 100644 index 00000000..4f729d36 --- /dev/null +++ b/layouts/partials/seo/description.html @@ -0,0 +1,34 @@ +{{- /* + The page description used for <meta name="description">, og:description and + the BlogPosting JSON-LD, as plain text: + + - security advisories: their one-line `summary` (their `description` is the + full advisory text) + - other pages: `description`, then the `preview` that blog posts carry + - release notes without either: a sentence built from category and version + - blog category pages: a sentence built from the category name + - anything else: the start of the page content + + Front matter values are capped at 300 characters and content excerpts at 160, + so a paragraph-length field does not end up in the <head> verbatim. +*/ -}} +{{- $description := "" -}} +{{- if eq .Type "security-advisory" -}} + {{- $description = .Params.summary -}} +{{- end -}} +{{- $description = $description | default .Description | default .Params.preview -}} +{{- $limit := 300 -}} +{{- if and (not $description) (eq .Type "release-note") -}} + {{- $product := "Apache Camel" -}} + {{- with index site.Data "release-categories" (.Params.category | default "camel") }}{{ $product = .name }}{{ end -}} + {{- $description = printf "Release notes for %s %s, released %s." $product .Params.version (.Date.Format "January 2, 2006") -}} +{{- end -}} +{{- if and (not $description) (eq .Kind "term") -}} + {{- $description = printf "Apache Camel blog posts in the %s category." .Title -}} +{{- end -}} +{{- if not $description -}} + {{- $description = .Summary -}} + {{- $limit = 160 -}} +{{- end -}} +{{- $text := string $description | plainify | htmlUnescape | replaceRE `\s+` " " -}} +{{- return (trim $text " " | truncate $limit) -}} diff --git a/layouts/partials/seo/image.html b/layouts/partials/seo/image.html new file mode 100644 index 00000000..93282b7d --- /dev/null +++ b/layouts/partials/seo/image.html @@ -0,0 +1,18 @@ +{{- /* + The image for og:image (which X/Twitter cards also read) and the BlogPosting JSON-LD, as a dict + with url, width and height. A page bundle "featured" image is cropped to the + 1200x630 that social cards use when it is large enough, and used as is when + it is smaller. SVG is skipped since no social platform renders it. Everything + else gets the generic site card (static/img/social-card.png). +*/ -}} +{{- $image := dict "url" (absURL "img/social-card.png") "width" 1200 "height" 630 -}} +{{- with (.Resources.ByType "image").GetMatch "*featured*" -}} + {{- if in (slice "jpeg" "png" "webp") .MediaType.SubType -}} + {{- $img := . -}} + {{- if and (ge .Width 1200) (ge .Height 630) -}} + {{- $img = .Fill "1200x630 jpg q85" -}} + {{- end -}} + {{- $image = dict "url" $img.Permalink "width" $img.Width "height" $img.Height -}} + {{- end -}} +{{- end -}} +{{- return $image -}} diff --git a/layouts/partials/seo/schema.html b/layouts/partials/seo/schema.html index 64c1b384..7156bd0a 100644 --- a/layouts/partials/seo/schema.html +++ b/layouts/partials/seo/schema.html @@ -1,2 +1,3 @@ {{ partial "seo/structured/organization-microdata" . }} {{ partial "seo/structured/breadcrumbs-microdata" . }} +{{ if and .IsPage (eq .Section "blog") }}{{ partial "seo/structured/blogposting" . }}{{ end }} diff --git a/layouts/partials/seo/structured/blogposting.html b/layouts/partials/seo/structured/blogposting.html new file mode 100644 index 00000000..3e2d49ea --- /dev/null +++ b/layouts/partials/seo/structured/blogposting.html @@ -0,0 +1,23 @@ +{{- /* BlogPosting for blog posts, sharing the description and image with the <head> meta tags. */ -}} +{{- $image := partial "seo/image.html" . -}} +{{- $authors := slice -}} +{{- range .Params.authors -}} + {{- $authors = $authors | append (dict "@type" "Person" "name" . "url" (printf "https://github.com/%s" .)) -}} +{{- end -}} +{{- $post := dict + "@context" "https://schema.org" + "@type" "BlogPosting" + "headline" .Title + "url" .Permalink + "mainEntityOfPage" .Permalink + "datePublished" (.PublishDate.Format "2006-01-02T15:04:05Z07:00") + "dateModified" (.Lastmod.Format "2006-01-02T15:04:05Z07:00") + "image" $image.url + "publisher" (dict "@type" "Organization" "name" .Site.Title "logo" (dict "@type" "ImageObject" "url" .Site.Params.organizationLogo)) +-}} +{{- with partial "seo/description.html" . }}{{ $post = merge $post (dict "description" .) }}{{ end -}} +{{- with $authors }}{{ $post = merge $post (dict "author" .) }}{{ end -}} +{{- with .Params.categories }}{{ $post = merge $post (dict "keywords" (delimit . ", ")) }}{{ end -}} +<script type="application/ld+json"> +{{ $post | jsonify | safeJS }} +</script> diff --git a/layouts/partials/seo/structured/breadcrumbs-microdata.html b/layouts/partials/seo/structured/breadcrumbs-microdata.html index 8d6bafd4..612bbea5 100644 --- a/layouts/partials/seo/structured/breadcrumbs-microdata.html +++ b/layouts/partials/seo/structured/breadcrumbs-microdata.html @@ -1,26 +1,20 @@ -{{ $url := replace .Permalink .Site.BaseURL "" }} -{{ $local := newScratch }} -{{ $local.Add "path" .Site.BaseURL }} -{{ $local.Add "breadcrumb" (slice (dict "url" .Site.BaseURL "name" .Site.Title "position" 1 )) }} -{{ range $index, $element := split $url "/" }} - {{ $local.Add "path" $element }} - {{ $local.Add "path" "/" }} - {{ if ne $element "" }} - {{ $local.Add "breadcrumb" (slice (dict "url" ($local.Get "path") "name" . "position" (add $index 2))) }} - {{ end }} -{{ end }} - +{{- /* + Home > section > ... > page, named after the page titles. Only pages that are + rendered are listed, so URL segments without a page of their own (the year + and month of a blog permalink, the disabled /categories/ taxonomy page) are + not offered as breadcrumbs. +*/ -}} +{{- $items := slice -}} +{{- range $p := (.Ancestors.Reverse | append .) -}} + {{- /* disabled kinds, like the /categories/ taxonomy page, have no permalink */ -}} + {{- with $p.Permalink -}} + {{- $name := $p.Title | default $p.Site.Title -}} + {{- if $p.IsHome }}{{ $name = $p.Site.Title }}{{ end -}} + {{- $items = $items | append (dict "@type" "ListItem" "position" (add (len $items) 1) "name" $name "item" .) -}} + {{- end -}} +{{- end -}} +{{- if gt (len $items) 1 -}} <script type="application/ld+json"> -{ - "@context": "http://schema.org", - "@type": "BreadcrumbList", - "itemListElement": [{{ range $local.Get "breadcrumb" }}{{ if ne .position 1 }},{{ end }}{ - "@type": "ListItem", - "position": {{ .position }}, - "item": { - "@id": {{ .url }}, - "name": "{{ .name }}" - } - }{{ end }}] -} +{{ dict "@context" "https://schema.org" "@type" "BreadcrumbList" "itemListElement" $items | jsonify | safeJS }} </script> +{{- end -}} diff --git a/layouts/partials/seo/structured/organization-microdata.html b/layouts/partials/seo/structured/organization-microdata.html index b83d40f8..9d768547 100644 --- a/layouts/partials/seo/structured/organization-microdata.html +++ b/layouts/partials/seo/structured/organization-microdata.html @@ -1,11 +1,7 @@ -<script type='application/ld+json'> - { - "@context": "http://schema.org", - "@type": "Organization", - "name": "{{ .Site.Title }}", - "url": "{{ .Site.BaseURL }}" - {{ with .Site.Params.socialProfiles }}, "sameAs": {{ . }}{{ end }} - {{ with .Site.Params.organizationLogo }}, "logo": "{{ . }}"{{ end }} - {{ with .Site.Params.organizationDescription }}, "description": "{{ . }}"{{ end }} - } +{{- $org := dict "@context" "https://schema.org" "@type" "Organization" "name" .Site.Title "url" .Site.BaseURL -}} +{{- with .Site.Params.socialProfiles }}{{ $org = merge $org (dict "sameAs" .) }}{{ end -}} +{{- with .Site.Params.organizationLogo }}{{ $org = merge $org (dict "logo" .) }}{{ end -}} +{{- with .Site.Params.organizationDescription }}{{ $org = merge $org (dict "description" .) }}{{ end -}} +<script type="application/ld+json"> +{{ $org | jsonify | safeJS }} </script> diff --git a/layouts/robots.txt b/layouts/robots.txt index d031045f..8aac4ed3 100644 --- a/layouts/robots.txt +++ b/layouts/robots.txt @@ -1,7 +1,3 @@ User-agent: * Sitemap: {{.Site.BaseURL}}sitemap.xml -Sitemap: {{.Site.BaseURL}}sitemap-camel-k.xml -Sitemap: {{.Site.BaseURL}}sitemap-components.xml -Sitemap: {{.Site.BaseURL}}sitemap-manual.xml - diff --git a/rules.js b/rules.js index 2bf21ec8..bbab8e25 100644 --- a/rules.js +++ b/rules.js @@ -81,6 +81,75 @@ class StructuredData extends Rule { } } +// Pages that are not indexed on their own: alias redirects (meta refresh) and +// pages marked noindex. The static link-checker workaround pages and other +// files without a canonical link are not pages search engines should list. +function isIndexablePage (document) { + if (document.querySelector('meta[http-equiv="refresh"]') !== null) return false; + const robots = document.querySelector('meta[name="robots"]'); + if (robots !== null && robots.hasAttribute('content') && /noindex/i.test(robots.getAttribute('content').value)) return false; + return document.querySelector('link[rel="canonical"]') !== null; +} + +function isAntoraPage (document) { + const generator = document.querySelector('meta[name="generator"]'); + return generator !== null && generator.hasAttribute('content') && generator.getAttribute('content').value.startsWith('Antora'); +} + +class MetaDescription extends Rule { + documentation(context) { + return { + description: "Pages must have a non-empty <meta name=\"description\">, it is the snippet search engines show and the fallback for link previews" + }; + } + + setup() { + this.on("dom:ready", event => { + const document = event.document; + // NOTE Antora pages fall back to the first paragraph of the page, which a + // page without any paragraph does not have; they are checked once a full + // build shows none of them is left without a description. + if (!isIndexablePage(document) || isAntoraPage(document)) { + return; + } + const meta = document.querySelector('meta[name="description"]'); + if (meta === null) { + this.report(document.querySelector('html'), 'Missing <meta name="description">, add `description` (or `preview` for blog posts) to the front matter'); + } else if (!meta.hasAttribute('content') || meta.getAttribute('content').value.trim().length === 0) { + this.report(meta, "Empty <meta name=\"description\">"); + } + }); + } +} + +class OpenGraphImage extends Rule { + documentation(context) { + return { + description: "og:image must be an absolute URL to a raster image, social platforms do not render SVG" + }; + } + + setup() { + this.on("dom:ready", event => { + const document = event.document; + if (!isIndexablePage(document)) { + return; + } + const meta = document.querySelector('meta[property="og:image"]'); + if (meta === null) { + this.report(document.querySelector('html'), 'Missing <meta property="og:image">'); + return; + } + const url = meta.hasAttribute('content') ? meta.getAttribute('content').value : ''; + if (!/^https?:\/\//.test(url)) { + this.report(meta, `og:image must be an absolute URL, found: ${url}`); + } else if (/\.svg(\?|#|$)/i.test(url)) { + this.report(meta, `og:image must not be an SVG, found: ${url}`); + } + }); + } +} + let data; module.exports = { @@ -90,6 +159,8 @@ module.exports = { rules: { "camel/title": HtmlTitle, "camel/relative-links": RelativeLinks, - "camel/structured-data": StructuredData + "camel/structured-data": StructuredData, + "camel/meta-description": MetaDescription, + "camel/og-image": OpenGraphImage } }; diff --git a/static/img/logo-camel-512.png b/static/img/logo-camel-512.png new file mode 100644 index 00000000..62a8ce18 Binary files /dev/null and b/static/img/logo-camel-512.png differ diff --git a/static/img/social-card.png b/static/img/social-card.png new file mode 100644 index 00000000..cd2d3c77 Binary files /dev/null and b/static/img/social-card.png differ diff --git a/test/seo-parity-test.js b/test/seo-parity-test.js new file mode 100644 index 00000000..1a97ff98 --- /dev/null +++ b/test/seo-parity-test.js @@ -0,0 +1,45 @@ +'use strict' + +// The Hugo pages (layouts/partials/header.html, layouts/partials/seo/) and the Antora docs +// (antora-ui-camel/src/partials/head-meta.hbs, organization-microdata.hbs) each render their +// own <head> metadata and Organization JSON-LD. They had drifted apart: the docs still described +// Camel with the old "Scala DSL" text and pointed og:image at an SVG. This keeps the shared +// values in one place, config.toml, and fails when the Antora copies no longer match it. + +const assert = require('node:assert/strict') +const fs = require('node:fs') +const path = require('node:path') +const test = require('node:test') + +const root = path.join(__dirname, '..') +const read = (file) => fs.readFileSync(path.join(root, file), 'utf8') + +function param (name) { + const match = read('config.toml').match(new RegExp(`^\\s*${name}\\s*=\\s*"([^"]*)"`, 'm')) + assert.ok(match, `expected ${name} in config.toml`) + return match[1] +} + +const headMeta = read('antora-ui-camel/src/partials/head-meta.hbs') +const organization = read('antora-ui-camel/src/partials/organization-microdata.hbs') + +test('the docs use the same Organization description as the Hugo pages', () => { + const description = param('organizationDescription') + assert.ok(organization.includes(`"description": "${description}"`), 'organization-microdata.hbs description differs from config.toml') + assert.ok(headMeta.includes(`{{else}}${description}{{/with}}`), 'head-meta.hbs og:description fallback differs from config.toml') +}) + +test('the Organization logo is the same raster image on both, and it exists', () => { + const logo = param('organizationLogo') + const { pathname } = new URL(logo) + assert.match(pathname, /\.png$/, 'Google requires a raster Organization logo') + assert.ok(organization.includes(`"logo": "{{{site.url}}}${pathname}"`), 'organization-microdata.hbs logo differs from config.toml') + assert.ok(fs.existsSync(path.join(root, 'static', pathname)), `static${pathname} is missing`) +}) + +test('the docs og:image is the social card the Hugo pages fall back to', () => { + const card = read('layouts/partials/seo/image.html').match(/absURL "([^"]+)"/) + assert.ok(card, 'expected the default card in layouts/partials/seo/image.html') + assert.ok(headMeta.includes(`content="{{{site.url}}}/${card[1]}"`), 'head-meta.hbs og:image differs from the Hugo default card') + assert.ok(fs.existsSync(path.join(root, 'static', card[1])), `static/${card[1]} is missing`) +})
