Skip to content

fix: resolve incorrect URLs for pre-quiz tests missing /academy prefix#191

Open
AnkitRewar11 wants to merge 3 commits into
layer5io:masterfrom
AnkitRewar11:fix/pre-quiz-url-prefix
Open

fix: resolve incorrect URLs for pre-quiz tests missing /academy prefix#191
AnkitRewar11 wants to merge 3 commits into
layer5io:masterfrom
AnkitRewar11:fix/pre-quiz-url-prefix

Conversation

@AnkitRewar11
Copy link
Copy Markdown

Notes for Reviewers
This PR fixes #127

What was the problem?

Pre-quiz test URLs were missing the /academy prefix.
The curriculaRoot variable was built using hardcoded .slice(0, 5) on
window.location.pathname at runtime, which generated incorrect URLs
like /learning-paths/xxx instead of /academy/learning-paths/xxx.

What was changed?

File: layouts/test/single.html

Replaced the hardcoded JavaScript path-splitting logic:

const curriculaRoot = window.location.pathname.split("/").slice(0, 5).join("/");

With Hugo's RelPermalink which injects the correct full path at build time:

const curriculaRoot = "{{ .RelPermalink | strings.TrimSuffix "/" }}";

Why this fix?

Hugo's .RelPermalink correctly includes the /academy base path prefix
at build time — no runtime path manipulation needed.

Signed commits

  • Yes, I signed my commits.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request modifies layouts/test/single.html to update how Hugo variables are injected into JavaScript, specifically adding quotes to testId and build and replacing client-side path logic for curriculaRoot with Hugo's .RelPermalink. Feedback recommends using the jsonify filter for these injections to provide safer character escaping and more robust integration within the JavaScript context.

Comment thread layouts/test/single.html Outdated
Comment thread layouts/test/single.html Outdated
Comment thread layouts/test/single.html Outdated
Signed-off-by: ankitrewar11 <ankitrewar11@gmail.com>
@AnkitRewar11 AnkitRewar11 force-pushed the fix/pre-quiz-url-prefix branch from 8e58fd5 to 6208dfb Compare May 9, 2026 06:28
Copy link
Copy Markdown
Member

@KhushamBansal KhushamBansal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM !

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 9, 2026

🚀 Preview deployment: https://layer5io.github.io/academy-theme/pr-preview/pr-191/

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes incorrect pre-quiz redirect URLs that were missing the /academy prefix by removing brittle runtime path slicing and using Hugo-provided permalinks at build time.

Changes:

  • Serialize testId and build into JavaScript using jsonify to ensure valid JS values.
  • Replace window.location.pathname segment slicing with {{ .RelPermalink | strings.TrimSuffix "/" }} (via jsonify) to build correct redirect roots under /academy.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix: Incorrect URLs for Academy Pre-Quiz Tests

4 participants