Skip to content

feat(seo): add sitemap, robots.txt, canonical and hreflang links - #10

Merged
Kepler2024 merged 1 commit into
mainfrom
feature/search-indexing
Nov 25, 2026
Merged

Kepler2024 merged 1 commit into
mainfrom
feature/search-indexing

Conversation

@Kepler2024

Copy link
Copy Markdown
Owner

Why

codesheet.io doesn't show up on Google yet. The site went live on 2026-11-25, so mostly it's too new. But the site also made crawling harder than it needed to be:

  • /sitemap.xml and /robots.txt returned 404, so Google could find pages only by following links.
  • The 11 Chinese pages were reachable only through the JavaScript <select>. No <a> in the HTML pointed to them.
  • Pages had no canonical or hreflang links, so the English and Chinese versions weren't marked as translations of each other.

What changed

  • src/pages/sitemap.xml.js generates sitemap.xml with all 22 pages (en + zh). Each entry lists en, zh-CN and x-default hreflang alternates.
  • src/pages/robots.txt.js allows all crawlers and points to the sitemap's absolute URL.
  • Layout.astro gives every page a canonical (same URL as og:url), plus en / zh-CN / x-default hreflang links.
  • Footer gets a plain <a> to the same page in the other language ("简体中文" / "English"). Links now wrap on narrow screens.
  • langPaths() in src/lib/paths.js maps /cpp/ ↔ /zh/cpp/. URLs are still built with site + base, so github.io forks keep working.
  • scripts/check-frontend.js Check 9 fails the build when any of the following is wrong:
    • a page's canonical isn't its own URL or doesn't match og:url
    • an hreflang link points to a page that doesn't exist
    • the sitemap doesn't list exactly the generated pages, each once
    • robots.txt doesn't point to the sitemap
  • docs/frontend.md documents the above.

Verification

  • npm run build && npm run check passes: 22 pages have canonical and hreflang links, and the sitemap lists all 22.
  • A subpath build (SITE_URL=https://kepler2024.github.io BASE_PATH=/Codesheet) passes too. The canonical, sitemap and robots URLs all sit under /Codesheet/.
  • Negative test: after deleting one <loc> from the built sitemap, the check fails with dist/sitemap.xml does not list dist/zh/rust/index.html.
  • Checked a desktop screenshot of the footer.

After merge

Verify codesheet.io in Google Search Console, submit https://codesheet.io/sitemap.xml, and request indexing of the homepage.

🤖 Generated with Claude Code

Google had no sitemap to read and could reach the Chinese pages only
through the JavaScript language selector.

- Generate sitemap.xml listing every English and Chinese page with
  hreflang alternates, and robots.txt pointing to it
- Give every page a canonical link and en / zh-CN / x-default
  hreflang links
- Add a plain footer link to the page in the other language so
  crawlers can follow it
- Check all of the above in check-frontend.js, and document it in
  docs/frontend.md

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Kepler2024
Kepler2024 merged commit ed90e2c into main Nov 25, 2026
13 checks passed
@Kepler2024
Kepler2024 deleted the feature/search-indexing branch November 25, 2026 23:32
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.

1 participant