[PR #1622] [MERGED] fix(dev): rewrite shared navbar URLs by page depth in dev preview #9228

Closed
opened 2026-05-03 01:29:31 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/harvard-edge/cs249r_book/pull/1622
Author: @farhan523
Created: 5/1/2026
Status: Merged
Merged: 5/1/2026
Merged by: @profvjreddi

Base: devHead: fix/dev-navbar-rewrite-nested-paths


📝 Commits (1)

  • b251b6a fix(dev): rewrite navbar URLs by page depth

📊 Changes

1 file changed (+42 additions, -17 deletions)

View changed files

📝 .github/scripts/rewrite-dev-urls.sh (+42 -17)

📄 Description

Summary

  • fix dev-preview navbar/footer link rewriting for nested HTML pages
  • compute relative prefixes per rendered file instead of once per subsite
  • keep self-links and cross-site links resolving correctly from deep pages

Issue

The shared navbar uses absolute production URLs like https://mlsysbook.ai/labs/ and https://mlsysbook.ai/kits/. In dev preview, .github/scripts/rewrite-dev-urls.sh rewrites those URLs for https://harvard-edge.github.io/cs249r_book_dev/.

The bug was that the rewrite script used one static ../ prefix per subsite. That worked for top-level pages like kits/index.html, but it broke on nested pages like:

  • kits/contents/arduino/nicla_vision/image_classification/image_classification.html

From a deep page, navbar links like Labs were rewritten too shallowly and resolved under the current chapter path, producing broken URLs like:

  • https://harvard-edge.github.io/cs249r_book_dev/kits/contents/arduino/nicla_vision/labs/

Why Local Worked

Local Quarto preview serves the site in project context, so this post-build dev rewrite mismatch does not show up there.

The published dev site is different: it rewrites production URLs after render so each subsite lives under cs249r_book_dev/. That rewrite logic was where the bug lived.

Fix

Update .github/scripts/rewrite-dev-urls.sh to compute prefixes per rendered HTML file:

  • detect each file's depth relative to the build directory
  • compute a root prefix back to the dev-site root
  • compute a self prefix back to the current subsite root
  • rewrite cross-site links with the root prefix
  • rewrite self-links with the self prefix

Test Plan

Script verification

  • create a top-level HTML file with links to https://mlsysbook.ai/labs/, https://mlsysbook.ai/kits/, and https://mlsysbook.ai/
  • create a nested HTML file under contents/arduino/nicla_vision/image_classification/ with the same links
  • run:
    • bash .github/scripts/rewrite-dev-urls.sh kits tmp/rewrite-verify
  • verify:
    • top-level page rewrites to ../labs/, ./, and ../
    • nested page rewrites to ../../../../../labs/, ../../../../, and ../../../../../

Manual dev-preview verification

  • open:
    • https://harvard-edge.github.io/cs249r_book_dev/kits/contents/arduino/nicla_vision/image_classification/image_classification.html
  • click from the shared navbar:
    • Build -> Labs
    • Build -> Hardware Kits
    • navbar brand/home
    • another shared-nav destination like About or Community
  • confirm each lands at the correct cs249r_book_dev/<subsite>/... path rather than under the current chapter directory

Regression checks

  • verify top-level Kits pages still navigate correctly
  • verify self-links still resolve to the Kits root
  • optionally spot-check another subsite using the same rewrite script

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/harvard-edge/cs249r_book/pull/1622 **Author:** [@farhan523](https://github.com/farhan523) **Created:** 5/1/2026 **Status:** ✅ Merged **Merged:** 5/1/2026 **Merged by:** [@profvjreddi](https://github.com/profvjreddi) **Base:** `dev` ← **Head:** `fix/dev-navbar-rewrite-nested-paths` --- ### 📝 Commits (1) - [`b251b6a`](https://github.com/harvard-edge/cs249r_book/commit/b251b6a95f00dddc3bbcb085ebf02ea9cc705b6b) fix(dev): rewrite navbar URLs by page depth ### 📊 Changes **1 file changed** (+42 additions, -17 deletions) <details> <summary>View changed files</summary> 📝 `.github/scripts/rewrite-dev-urls.sh` (+42 -17) </details> ### 📄 Description ## Summary - fix dev-preview navbar/footer link rewriting for nested HTML pages - compute relative prefixes per rendered file instead of once per subsite - keep self-links and cross-site links resolving correctly from deep pages ## Issue The shared navbar uses absolute production URLs like `https://mlsysbook.ai/labs/` and `https://mlsysbook.ai/kits/`. In dev preview, `.github/scripts/rewrite-dev-urls.sh` rewrites those URLs for `https://harvard-edge.github.io/cs249r_book_dev/`. The bug was that the rewrite script used one static `../` prefix per subsite. That worked for top-level pages like `kits/index.html`, but it broke on nested pages like: - `kits/contents/arduino/nicla_vision/image_classification/image_classification.html` From a deep page, navbar links like `Labs` were rewritten too shallowly and resolved under the current chapter path, producing broken URLs like: - `https://harvard-edge.github.io/cs249r_book_dev/kits/contents/arduino/nicla_vision/labs/` ## Why Local Worked Local Quarto preview serves the site in project context, so this post-build dev rewrite mismatch does not show up there. The published dev site is different: it rewrites production URLs after render so each subsite lives under `cs249r_book_dev/`. That rewrite logic was where the bug lived. ## Fix Update `.github/scripts/rewrite-dev-urls.sh` to compute prefixes per rendered HTML file: - detect each file's depth relative to the build directory - compute a root prefix back to the dev-site root - compute a self prefix back to the current subsite root - rewrite cross-site links with the root prefix - rewrite self-links with the self prefix ## Test Plan ### Script verification - create a top-level HTML file with links to `https://mlsysbook.ai/labs/`, `https://mlsysbook.ai/kits/`, and `https://mlsysbook.ai/` - create a nested HTML file under `contents/arduino/nicla_vision/image_classification/` with the same links - run: - `bash .github/scripts/rewrite-dev-urls.sh kits tmp/rewrite-verify` - verify: - top-level page rewrites to `../labs/`, `./`, and `../` - nested page rewrites to `../../../../../labs/`, `../../../../`, and `../../../../../` ### Manual dev-preview verification - open: - `https://harvard-edge.github.io/cs249r_book_dev/kits/contents/arduino/nicla_vision/image_classification/image_classification.html` - click from the shared navbar: - `Build -> Labs` - `Build -> Hardware Kits` - navbar brand/home - another shared-nav destination like `About` or `Community` - confirm each lands at the correct `cs249r_book_dev/<subsite>/...` path rather than under the current chapter directory ### Regression checks - verify top-level Kits pages still navigate correctly - verify self-links still resolve to the Kits root - optionally spot-check another subsite using the same rewrite script --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-05-03 01:29:31 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/cs249r_book#9228