From 030554281d5abae981e1c4864bbd4b8f4ba8ff91 Mon Sep 17 00:00:00 2001 From: Peiran Yao Date: Tue, 23 Jun 2020 14:59:25 -0600 Subject: [PATCH 1/2] remove unavailable help items --- _layouts/help.html | 4 ++-- static/js/help.es6 | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/_layouts/help.html b/_layouts/help.html index 80b12fc..2069134 100644 --- a/_layouts/help.html +++ b/_layouts/help.html @@ -19,7 +19,7 @@ @@ -30,7 +30,7 @@ diff --git a/static/js/help.es6 b/static/js/help.es6 index 1a9e036..69f2834 100644 --- a/static/js/help.es6 +++ b/static/js/help.es6 @@ -35,6 +35,13 @@ $(document).ready(() => { let help_url = $(ev.target).find("option:selected").data('help-url'); window.location = `${window.location.protocol}//${window.location.host}${help_url}`; }); + + $.getJSON("/static/tunasync.json", (statusData) => { + // remove help items for disabled/removed mirrors + let availableMirrorIds = new Set(statusData.map(x => x.name)); + $('li').filter((_, node) => node.id && node.id.startsWith("toc-") && !availableMirrorIds.has(node.id.slice(4))).remove(); + $('option').filter((_, node) => node.id && node.id.startsWith("toc-") && !availableMirrorIds.has(node.id.slice(4))).remove(); + }); }); // vim: ts=2 sts=2 sw=2 noexpandtab From fa858ac5fa6355594189346d781754d5bc86b5f5 Mon Sep 17 00:00:00 2001 From: Peiran Yao Date: Tue, 23 Jun 2020 15:12:47 -0600 Subject: [PATCH 2/2] redirect unavailable help pages to 404 --- _layouts/help.html | 4 ++++ static/js/help.es6 | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/_layouts/help.html b/_layouts/help.html index 2069134..2c2e475 100644 --- a/_layouts/help.html +++ b/_layouts/help.html @@ -12,6 +12,10 @@ {% endif %} + + {% assign help_pages = site.categories["help"] | sort: 'mirrorid' %}
diff --git a/static/js/help.es6 b/static/js/help.es6 index 69f2834..957d559 100644 --- a/static/js/help.es6 +++ b/static/js/help.es6 @@ -39,6 +39,11 @@ $(document).ready(() => { $.getJSON("/static/tunasync.json", (statusData) => { // remove help items for disabled/removed mirrors let availableMirrorIds = new Set(statusData.map(x => x.name)); + console.log(window.mirrorId); + if (!availableMirrorIds.has(window.mirrorId)) { + location.href = "/404.html"; // this will break 404 issue submission + } + $('li').filter((_, node) => node.id && node.id.startsWith("toc-") && !availableMirrorIds.has(node.id.slice(4))).remove(); $('option').filter((_, node) => node.id && node.id.startsWith("toc-") && !availableMirrorIds.has(node.id.slice(4))).remove(); });