WebHost: Add tutorials to sitemap and hide settings link for games without settings (#1452)

* WebHost: Add tutorials to sitemap and hide settings link for games without settings

* Fixed some typing imports
This commit is contained in:
Jarno 2023-02-17 19:16:37 +01:00 committed by GitHub
parent b62be6f7f4
commit 0a1261eb84
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 6 deletions

View File

@ -12,7 +12,7 @@ import io
import collections import collections
import importlib import importlib
import logging import logging
from typing import BinaryIO, Coroutine, Optional, Set from typing import BinaryIO, Coroutine, Optional, Set, Dict, Any, Union
from yaml import load, load_all, dump, SafeLoader from yaml import load, load_all, dump, SafeLoader
@ -662,7 +662,10 @@ def messagebox(title: str, text: str, error: bool = False) -> None:
def title_sorted(data: typing.Sequence, key=None, ignore: typing.Set = frozenset(("a", "the"))): def title_sorted(data: typing.Sequence, key=None, ignore: typing.Set = frozenset(("a", "the"))):
"""Sorts a sequence of text ignoring typical articles like "a" or "the" in the beginning.""" """Sorts a sequence of text ignoring typical articles like "a" or "the" in the beginning."""
def sorter(element: str) -> str: def sorter(element: Union[str, Dict[str, Any]]) -> str:
if (not isinstance(element, str)):
element = element["title"]
parts = element.split(maxsplit=1) parts = element.split(maxsplit=1)
if parts[0].lower() in ignore: if parts[0].lower() in ignore:
return parts[1].lower() return parts[1].lower()

View File

@ -1,5 +1,6 @@
import datetime import datetime
import os import os
from typing import List, Dict, Union
import jinja2.exceptions import jinja2.exceptions
from flask import request, redirect, url_for, render_template, Response, session, abort, send_from_directory from flask import request, redirect, url_for, render_template, Response, session, abort, send_from_directory
@ -163,8 +164,9 @@ def get_datapackage():
@app.route('/index') @app.route('/index')
@app.route('/sitemap') @app.route('/sitemap')
def get_sitemap(): def get_sitemap():
available_games = [] available_games: List[Dict[str, Union[str, bool]]] = []
for game, world in AutoWorldRegister.world_types.items(): for game, world in AutoWorldRegister.world_types.items():
if not world.hidden: if not world.hidden:
available_games.append(game) has_settings: bool = isinstance(world.web.settings_page, bool) and world.web.settings_page
available_games.append({ 'title': game, 'has_settings': has_settings })
return render_template("siteMap.html", games=available_games) return render_template("siteMap.html", games=available_games)

View File

@ -29,17 +29,30 @@
<li><a href="/glossary/en">Glossary</a></li> <li><a href="/glossary/en">Glossary</a></li>
</ul> </ul>
<h2>Tutorials</h2>
<ul>
<li><a href="/tutorial/Archipelago/setup/en">Multiworld Setup Tutorial</a></li>
<li><a href="/tutorial/Archipelago/using_website/en">Website User Guide</a></li>
<li><a href="/tutorial/Archipelago/mac/en">Setup Guide for Mac</a></li>
<li><a href="/tutorial/Archipelago/commands/en">Server and Client Commands</a></li>
<li><a href="/tutorial/Archipelago/advanced_settings/en">Advanced YAML Guide</a></li>
<li><a href="/tutorial/Archipelago/triggers/en">Triggers Guide</a></li>
<li><a href="/tutorial/Archipelago/plando/en">Plando Guide</a></li>
</ul>
<h2>Game Info Pages</h2> <h2>Game Info Pages</h2>
<ul> <ul>
{% for game in games | title_sorted %} {% for game in games | title_sorted %}
<li><a href="{{ url_for('game_info', game=game, lang='en') }}">{{ game }}</a></li> <li><a href="{{ url_for('game_info', game=game['title'], lang='en') }}">{{ game['title'] }}</a></li>
{% endfor %} {% endfor %}
</ul> </ul>
<h2>Game Settings Pages</h2> <h2>Game Settings Pages</h2>
<ul> <ul>
{% for game in games | title_sorted %} {% for game in games | title_sorted %}
<li><a href="{{ url_for('player_settings', game=game) }}">{{ game }}</a></li> {% if game['has_settings'] %}
<li><a href="{{ url_for('player_settings', game=game['title']) }}">{{ game['title'] }}</a></li>
{% endif %}
{% endfor %} {% endfor %}
</ul> </ul>
</div> </div>