From 0773a126fb6ab907d8715b392f11b4cb1e8924c1 Mon Sep 17 00:00:00 2001 From: Martin Geisler Date: Wed, 30 Aug 2023 21:22:29 +0200 Subject: [PATCH] Insert `` elements This prevents duplicate search results in case copies of the material is being left visible on the web. See https://developers.google.com/search/docs/crawling-indexing/consolidate-duplicate-urls for details. The implementation here is very simple and should go away when https://github.com/google/mdbook-i18n-helpers/issues/70 is implemented. --- .github/workflows/publish.yml | 22 ++++++++++++++++++++++ theme/index.hbs | 4 ++++ 2 files changed, 26 insertions(+) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index e29f6a3f13ec..fb9862dc9f57 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -55,6 +55,28 @@ jobs: echo "::endgroup::" done + # This helps guard against duplicate search results in case test + # instances are left around on the public Internet. See + # https://developers.google.com/search/docs/crawling-indexing/consolidate-duplicate-urls + # for details. + # + # For simplicity, we replace a fixed string instead of + # attempting to parse the HTML in some clever way. + # https://github.com/google/mdbook-i18n-helpers/issues/70 will + # eventually make this obsolete. + - name: 'Add link rel="canonical" elements' + run: | + canonical="https://google.github.io/comprehensive-rust" + cd book/html + for page in **/*.html; do + if [[ ${page:t} -eq "index.html" ]]; then + link=${page:h} + else + link=$page + fi + sed -i 's|||' + shell: zsh {0} + - name: Setup Pages uses: actions/configure-pages@v2 diff --git a/theme/index.hbs b/theme/index.hbs index df975d7b0e46..18e24bacafad 100644 --- a/theme/index.hbs +++ b/theme/index.hbs @@ -29,6 +29,10 @@ + {{! Replaced with a element in + publish.yml. Remove when after fixing this issue: + https://github.com/google/mdbook-i18n-helpers/issues/70 }} + {{#if favicon_svg}} {{/if}}