Skip to content

Fix/video sidebar hash links#1054

Closed
Sbragul26 wants to merge 12 commits into
layer5io:masterfrom
Sbragul26:fix/video-sidebar-hash-links
Closed

Fix/video sidebar hash links#1054
Sbragul26 wants to merge 12 commits into
layer5io:masterfrom
Sbragul26:fix/video-sidebar-hash-links

Conversation

@Sbragul26
Copy link
Copy Markdown
Member

@Sbragul26 Sbragul26 commented May 18, 2026

Notes for Reviewers

This PR fixes #1051 where direct navigation to video category pages always showed the default "Getting Started" tab instead of the correct category.

Signed commits

  • Yes, I signed my commits.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 18, 2026

PR Preview Action v1.6.3
Preview removed because the pull request was closed.
2026-05-18 18:25 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 introduces a new partial, video-scripts.html, which generates a mapping of video category URLs to hash fragments and uses JavaScript to append these hashes to matching links. Feedback suggests that the current implementation should also handle direct navigation by checking the current window location on load and applying the appropriate hash if it is missing.

Comment on lines +15 to +33
document.addEventListener('DOMContentLoaded', function () {
const mapEl = document.getElementById('video-hash-map');
const videoHashMap = mapEl ? JSON.parse(mapEl.dataset.map || '{}') : {};

const normalize = (href) => {
try {
const u = new URL(href, location.origin);
let p = u.pathname;
if (!p.endsWith('/')) p += '/';
return p;
} catch (_) { return href || ''; }
};

document.querySelectorAll("a[href^='/videos/'], a[href*='/videos/']").forEach(link => {
const key = normalize(link.getAttribute('href') || '');
const hash = videoHashMap[key];
if (hash) link.setAttribute('href', key + '#' + hash);
});
});
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 current implementation rewrites links on the page, but it does not address the core issue of direct navigation (e.g., when a user enters a category URL directly into the browser). To fully fix the issue, the script should check the current window.location.pathname on load and update the browser's hash if it matches a known category path. The implementation has been updated to use logical short-circuiting for string validation and defaults to ensure conciseness.

document.addEventListener('DOMContentLoaded', function () {
  const mapEl = document.getElementById('video-hash-map');
  const videoHashMap = mapEl ? JSON.parse(mapEl.dataset.map || '{}') : {};

  const normalize = (href) => {
    try {
      const u = new URL(href, location.origin);
      const p = u.pathname;
      return p.endsWith('/') ? p : p + '/';
    } catch (_) { return href || ''; }
  };

  const currentPath = normalize(window.location.pathname);
  if (!window.location.hash && videoHashMap[currentPath]) {
    window.location.hash = videoHashMap[currentPath];
  }

  document.querySelectorAll("a[href^='/videos/'], a[href*='/videos/']").forEach(link => {
    const key = normalize(link.getAttribute('href') || '');
    const hash = videoHashMap[key];
    if (hash) link.setAttribute('href', key + '#' + hash);
  });
});
References
  1. Use logical short-circuiting to simplify return statements for string validation and trimming to make code more concise and avoid redundant method calls.

Sbragul26 and others added 12 commits May 18, 2026 23:49
Signed-off-by: Sbragul26 <sbragul26@gmail.com>
Signed-off-by: l5io <ci@layer5.io>
Signed-off-by: l5io <ci@layer5.io>
Signed-off-by: l5io <ci@layer5.io>
Signed-off-by: l5io <ci@layer5.io>
Signed-off-by: Discuss bot <discussions@meshery.io>
Signed-off-by: l5io <ci@layer5.io>
Signed-off-by: Sangram Rath <sangram.rath@gmail.com>
Signed-off-by: Sbragul26 <sbragul26@gmail.com>
Signed-off-by: Sbragul26 <sbragul26@gmail.com>
@Sbragul26 Sbragul26 force-pushed the fix/video-sidebar-hash-links branch from ef22099 to a1477bd Compare May 18, 2026 18:21
@Sbragul26
Copy link
Copy Markdown
Member Author

Closing this PR for now because unrelated commits were included after rebasing. I’ll clean the branch and open a fresh PR with only the required video sidebar hash link fix.

@Sbragul26 Sbragul26 closed this May 18, 2026
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.

[Docs] Videos page loads wrong category tab

5 participants