Skip to content

KAFKA-20265: Add canonical URL tags to Kafka Javadoc pages to point search engines to suggest latest stable version - #823

Open
MartijnVisser wants to merge 2 commits into
apache:markdownfrom
MartijnVisser:KAFKA-20265-canonical-tags
Open

MartijnVisser wants to merge 2 commits into
apache:markdownfrom
MartijnVisser:KAFKA-20265-canonical-tags

Conversation

@MartijnVisser

@MartijnVisser MartijnVisser commented Mar 9, 2026 •

Copy link
Copy Markdown

Some examples of Javadocs that are currently ranked for older versions:

RetriableCommitFailedException is shown for 2.5.0 instead of 4.2.0
image

ConsumerRebalanceListener is shown for both 2.5.0 and 2.3.0 instead of 4.2.0
image

AdminClient is shown for 2.6.0 instead of 4.2.0
image

Add a bash script that inserts/updates <link rel="canonical"> tags in
all Javadoc HTML files across all versions, pointing to the latest
stable version. This points search engines to use the latest stable
versions of the API docs and consolidates SEO ranking signals.

When a Javadoc page doesn't exist in the latest version (e.g., a
removed API), the script points the canonical URL to the newest
version that still contains the page, instead of pointing to a 404.

Also update README.md to document the new step in the release process.
Run add-javadoc-canonical-urls.sh to add <link rel="canonical"> tags
across all existing Javadoc HTML files in static/*/javadoc/. Pages that exist in the latest version (42) get a canonical pointing there. Pages for removed APIs point to the newest version that still contains them.
for (i = 1; i <= n; i++) order[v[i]] = i
}
!seen[$0]++ { print $0 }
' > /dev/null

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the purpose of this block from L75 to here? (Thank you Claude for this pointer 😄)

!seen[$0]++ { print $0 }
' > /dev/null

# Simpler approach: for each version (newest first), record paths not yet seen

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we delete the above block, we can update this comment?

CANONICAL_URL="https://kafka.apache.org/${CANON_VERSION}/javadoc/${REL_PATH}"
CANONICAL_TAG="<link rel=\"canonical\" href=\"${CANONICAL_URL}\">"

if grep -qi 'rel="canonical"' "$HTML_FILE" 2>/dev/null; then

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

grep -qiE 'rel=["'\'']canonical["'\'']' to find both 'canonical' and "canonical".

#
# If no version argument is provided, reads latest_version from hugo.yaml.

set -e

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude suggest to use set -euo pipefail

CANONICAL_TAG="<link rel=\"canonical\" href=\"${CANONICAL_URL}\">"

if grep -qi 'rel="canonical"' "$HTML_FILE" 2>/dev/null; then
"${SED_INPLACE[@]}" "s|<[Ll][Ii][Nn][Kk] [Rr][Ee][Ll] *=[\"'] *canonical[\"'][^>]*>|${CANONICAL_TAG}|g" "$HTML_FILE"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<[Ll][Ii][Nn][Kk] [Rr][Ee][Ll] -> <[Ll][Ii][Nn][Kk][[:space:]]+[Rr][Ee][Ll]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants