From acaf94d3805470f39a94427ab3c2a376686799e6 Mon Sep 17 00:00:00 2001 From: "Jonathan S. Katz" Date: Sun, 1 Aug 2021 16:04:56 -0400 Subject: [PATCH] Add canonical page references to documentation This sets the documentation pages to use the "/docs/current/" prefix to be the canonical docs. This follows SEO guidance to help improve which doc pages show up higher in search, per: https://developers.google.com/search/docs/advanced/crawling/consolidate-duplicate-urls Reviewed-by: Andres Freund --- pgweb/docs/views.py | 19 +++++++++++++++++++ templates/docs/docspage.html | 3 +++ templates/docs/index.html | 3 +++ 3 files changed, 25 insertions(+) diff --git a/pgweb/docs/views.py b/pgweb/docs/views.py index 9def765..436e235 100644 --- a/pgweb/docs/views.py +++ b/pgweb/docs/views.py @@ -128,11 +128,30 @@ def docpage(request, version, filename): else: contentpreview = '' + # determine the canonical version of the page + # if the doc page is in the current version, then we set it to current + # otherwise, check the supported and unsupported versions and find the + # last version that the page appeared + # we exclude "devel" as development docs are disallowed in robots.txt + canonical_version = "" + if len(list(filter(lambda v: v.version.current, versions))): + canonical_version = "current" + else: + version_max = None + for v in versions: + if version_max is None: + version_max = v + elif v.version.tree > version_max.version.tree: + version_max = v + if version_max.version.tree > Decimal(0): + canonical_version = version_max.display_version() + r = render(request, 'docs/docspage.html', { 'page': page, 'supported_versions': [v for v in versions if v.version.supported], 'devel_versions': [v for v in versions if not v.version.supported and v.version.testing], 'unsupported_versions': [v for v in versions if not v.version.supported and not v.version.testing], + 'canonical_version': canonical_version, 'title': page.title, 'doc_index_filename': indexname, 'loaddate': loaddate, diff --git a/templates/docs/docspage.html b/templates/docs/docspage.html index b23fafb..d2c9341 100644 --- a/templates/docs/docspage.html +++ b/templates/docs/docspage.html @@ -15,6 +15,9 @@ {%if og.description%} {%endif%} {%endif%} {%if not page.version.supported%} {%endif%} +{% if canonical_version %} + +{% endif %} diff --git a/templates/docs/index.html b/templates/docs/index.html index cfcc2f8..b259967 100644 --- a/templates/docs/index.html +++ b/templates/docs/index.html @@ -27,6 +27,9 @@ {{v.treestring}} + {% if v.current %} + / Current + {% endif %} {%if v.a4pdf or v.uspdf%} -- 2.32.0 (Apple Git-132)