sitemap.xml emits relative <loc> values, so search engines reject it
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 68/100
- issue の種類
- バグ
- 明瞭さ
- おおむね明確
- 活発さ
- 静か
- 技術スタック
- hugo, javascript
- 領域
- build-system, devops, web-dev
調査の方向性
site/config/_default/hugo.toml と netlify.toml にある既存のコマンドラインから始め、次に、ローカルおよびプレビュー時の挙動を維持するため、一覧にあるテーマ partial 内の absURL の使用箇所を確認します。Netlify のコンテキストごとにベース URL を設定し、sitemap.xml がすべてのエントリについて完全修飾された loc 値を出力することを検証するとともに、issue に記載された /404/ と robots.txt の関連する挙動を確認します。
索引モデルが issue の本文から書いたものです。
説明
https://www.shift2bikes.org/sitemap.xml builds and serves fine (200), but every entry is a relative path:
<url>
<loc>/pages/bike-summer/</loc>
</url>
<url>
<loc>/archive/get-lit/</loc>
<lastmod>2017-11-13T08:19:34+00:00</lastmod>
</url>
The sitemap protocol requires <loc> to be a fully qualified URL, so the 72 entries currently in the file are almost certainly being discarded.
Cause
site/config/_default/hugo.toml sets:
baseURL = "/"
Hugo builds <loc> from each page's .Permalink, which is derived from baseURL, so the permalinks come out relative.
This is not a one-line fix
baseURL = "/" is load-bearing rather than an oversight. The theme uses absURL for essentially every asset, and for the calendar's own API calls:
site/themes/s2b_hugo_theme/layouts/partials/cal/scripts.html:140: url: '{{ absURL "api/events.php" }}',
site/themes/s2b_hugo_theme/layouts/partials/head-content.html:29: <link rel="icon" href="{{ absURL "favicon.ico" }}">
site/themes/s2b_hugo_theme/layouts/partials/cal/up-next.html:1: <script src="{{ absURL "lib/fullcalendar/core/main.min.js" }}"></script>
With baseURL = "/" these resolve same-origin, which is what lets the site work unchanged on localhost, on netlify deploy previews, and in production. Hardcoding the production URL into hugo.toml would make deploy previews and local dev load their scripts from, and fetch their event data from, www.shift2bikes.org.
Suggested approach
Set HUGO_BASEURL per netlify context rather than in hugo.toml, so each deploy gets the origin it is actually served from:
- production: the canonical
https://www.shift2bikes.org/ - deploy previews and branch deploys:
$DEPLOY_PRIME_URL - local dev (
npm run dev,-e development): leave as/
Netlify exposes both URL and DEPLOY_PRIME_URL to the build, and hugo reads HUGO_BASEURL from the environment, so this can live in the command lines already present in netlify.toml.
Related
- The sitemap also lists
/404/. Worth excluding, most simply withsitemap: disablein the page's front matter. - #1068 adds a
robots.txtwith aSitemap:line pointing here. That line becomes correct once this is fixed. See the discussion on the PR for #1068.
- 主要言語
- JavaScript
- スター
- 30
- フォーク
- 25
- 平均マージ
- 9分
- マージ済み PR(30日)
- 1
環境構築
- Dockerfile または Docker Compose ファイルあり
- プルリクエストのテンプレートなし
- コントリビューションガイドなし
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
shift-org/shift-docs のほかの issue
-
Unknown --db values report a TypeError instead of the intended error対応中かも @gangster が 63 日前に担当しました。 オープン
難易度 1/5 1時間未満 初心者へのやさしさ 88/100
shift-org/shift-docs#1091 ·
-
validateRideLength accepts any Object.prototype key as a ride length対応中かも @gangster が 63 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
shift-org/shift-docs#1089 ·
-
Favorites page fetches every favorite because getDaily's guard is inverted対応中かも @gangster が 63 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
shift-org/shift-docs#1087 ·
-
難易度 3/5 1〜2日 初心者へのやさしさ 58/100
shift-org/shift-docs#1072 ·
-
難易度 3/5 1〜2日 初心者へのやさしさ 58/100
shift-org/shift-docs#1054 ·
shift-org/shift-docs の issue をすべて見る
似ている issue
-
難易度 1/5 1〜3時間 初心者へのやさしさ 67/100
Morni-Team/pkmessenger#44 · コメント 4 件 ·
メンテナーはふだん 1 日以内に返信
-
status/needs-triage type/bug
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
PKU-YuanGroup/OpenAI4S#218 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
debpalash/VoiceStudio#2678 ·
メンテナーはふだん 1 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 66/100
メンテナーはふだん 3 日以内に返信