Skip to content

Revert "fix: resolve incorrect URLs for pre-quiz tests missing /academy prefix"#195

Merged
CodexRaunak merged 1 commit into
masterfrom
revert-191-fix/pre-quiz-url-prefix
May 20, 2026
Merged

Revert "fix: resolve incorrect URLs for pre-quiz tests missing /academy prefix"#195
CodexRaunak merged 1 commit into
masterfrom
revert-191-fix/pre-quiz-url-prefix

Conversation

@CodexRaunak
Copy link
Copy Markdown
Contributor

Reverts #191

@CodexRaunak CodexRaunak merged commit ca3e7cf into master May 20, 2026
1 of 3 checks passed
@CodexRaunak CodexRaunak deleted the revert-191-fix/pre-quiz-url-prefix branch May 20, 2026 20:50
@github-actions
Copy link
Copy Markdown

PR Preview Action v1.6.3
Preview removed because the pull request was closed.
2026-05-20 20:51 UTC

Copy link
Copy Markdown
Contributor

@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 the Hugo template in layouts/test/single.html by removing the jsonify filter from variables passed to JavaScript and replacing the curriculaRoot calculation with a client-side path-splitting approach. Feedback indicates that removing jsonify will cause JavaScript syntax and reference errors because the values will be rendered without quotes. Furthermore, the new path-splitting logic is flagged as brittle and less reliable than Hugo's native .RelPermalink for determining the root path.

Comment thread layouts/test/single.html

<script>
const testId = {{ $test.id | jsonify }};
const testId = {{$test.id}};
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

Removing the jsonify filter will cause a JavaScript syntax error because the value (which is a string) will be rendered without surrounding quotes (e.g., const testId = some-id;). Using jsonify is the idiomatic way to safely pass Hugo variables to JavaScript as it handles both quoting and escaping.

Suggested change
const testId = {{$test.id}};
const testId = {{ $test.id | jsonify }};

Comment thread layouts/test/single.html
const testId = {{$test.id}};
const testAbsPath = "{{$tesAbsPath}}";
const build = {{ $build | jsonify }};
const build = {{$build}};
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

The build variable is a string (e.g., "development" or "production"). Removing jsonify without adding quotes will result in invalid JavaScript (e.g., const build = development;), which will throw a ReferenceError in the browser.

Suggested change
const build = {{$build}};
const build = {{ $build | jsonify }};

Comment thread layouts/test/single.html
if (isProdBuild && window.academyContext?.RegistrationData?.id) {
// redirect to test page
const curriculaRoot = {{ .RelPermalink | strings.TrimSuffix "/" | jsonify }};
const curriculaRoot = window.location.pathname.split("/").slice(0, 5).join("/");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Using window.location.pathname.split("/").slice(0, 5).join("/") is brittle as it relies on a fixed URL depth. This logic will break if the URL structure changes or if the site is hosted under a different base path. It is safer to use Hugo's .RelPermalink which is determined at build time based on the content structure.

Suggested change
const curriculaRoot = window.location.pathname.split("/").slice(0, 5).join("/");
const curriculaRoot = {{ .RelPermalink | strings.TrimSuffix "/" | jsonify }};

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.

1 participant