Merge pull request #203 from tuna/remove-help

隐藏不存在的镜像的帮助
This commit is contained in:
Yuxiang Zhang 2020-06-24 08:24:20 +08:00 committed by GitHub
commit e97a910cd9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 2 deletions

View File

@ -12,6 +12,10 @@
</script>
{% endif %}
<script>
window.mirrorId = "{{page.mirrorid}}";
</script>
{% assign help_pages = site.categories["help"] | sort: 'mirrorid' %}
<div id="help-page">
<div class="container">
@ -19,7 +23,7 @@
<div class="col-sm-2 hidden-xs">
<ul class="nav nav-pills nav-stacked" id="help-nav">
{% for h in help_pages %}
<li{% if h.mirrorid == page.mirrorid or h.redirect_help_id == page.mirrorid %} class="active"{%endif%}><a href="{{h.url}}">{{h.mirrorid}}</a></li>
<li{% if h.mirrorid == page.mirrorid or h.redirect_help_id == page.mirrorid %} class="active"{%endif%} id="toc-{{h.mirrorid}}"><a href="{{h.url}}">{{h.mirrorid}}</a></li>
{% endfor %}
</ul>
</div><!-- sidenave -->
@ -30,7 +34,7 @@
<label>选择帮助条目: </label>
<select class="form-control" id="help-select">
{% for h in help_pages %}
<option data-help-url="{{h.url}}"{% if h.mirrorid == page.mirrorid%} selected{%endif%}>{{h.mirrorid}}</option>
<option data-help-url="{{h.url}}"{% if h.mirrorid == page.mirrorid%} selected{%endif%} id="toc-{{h.mirrorid}}">{{h.mirrorid}}</option>
{% endfor %}
</select>
</div>

View File

@ -35,6 +35,18 @@ $(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));
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();
});
});
// vim: ts=2 sts=2 sw=2 noexpandtab