Upgrade from bootstrap 4 to 5

This commit is contained in:
Edward Betts 2023-11-09 07:35:41 +01:00
parent fd281532e6
commit 4446cbed6e
4 changed files with 87 additions and 40 deletions

View file

@ -0,0 +1,27 @@
from .category import Category
from .mediawiki import mediawiki_query
from .type import CallParams
def process_cats(cats: list[dict[str, str]], site: str) -> list[Category]:
"""Process categories."""
return [Category(cat["title"], site) for cat in cats]
def get_categories(titles: list[str], site: str) -> list[tuple[str, list[Category]]]:
"""Get categories for pages with given titles."""
params: CallParams = {
"prop": "categories",
"clshow": "!hidden",
"cllimit": "max",
}
from_wiki = mediawiki_query(titles, params, site)
title_and_cats = []
for i in from_wiki:
if "categories" not in i:
continue
cats = process_cats(i["categories"], site)
if not cats:
continue
title_and_cats.append((i["title"], cats))
return title_and_cats

View file

@ -2,7 +2,7 @@
<html lang="en">
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="{{ url_for('static', filename='javascript/bootstrap4/css/bootstrap.min.css') }}">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN" crossorigin="anonymous">
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>
@ -27,8 +27,7 @@
{% block content %}{% endblock %}
<script src="{{ url_for('static', filename='javascript/jquery/jquery.min.js') }}"></script>
{# <script src="{{ url_for('static', filename='javascript/popper.js/popper.min.js') }}"></script> #}
<script src="{{ url_for('static', filename='javascript/bootstrap4/js/bootstrap.min.js') }}"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-C6RzsynM9kWDrMNeT87bh95OGNyZPhcTNXj1NW7RuBCsyN/o0jlpcV8Qyq46cDfL" crossorigin="anonymous"></script>
{% block script %}{% endblock %}
</body>

View file

@ -6,16 +6,40 @@
<style>
div.description { margin-left: 2em; color: rgb(96, 96, 96); }
span.description { color: rgb(96, 96, 96); }
#artwork {
position: fixed; /* This keeps the map in place when the page is scrolled */
top: 56px;
left: 0; /* Positioned on the right side */
width: 50%; /* Half the screen width */
bottom: 0px;
z-index: -1;
}
#artwork img {
object-fit: contain; /* The image will be scaled to maintain its aspect ratio */
width: 100%;
height: 100%;
}
#main {
float: right; /* Floats the main content to the right */
width: 48%; /* Adjusted width of the main content */
height: auto; /* Height is set to auto, allowing it to expand naturally */
margin-right: 1%;
}
</style>
{% endblock %}
{% block content %}
<div class="container-fluid mt-2">
<div class="row">
<div class="col-md">
<img src="{{ image.thumburl }}" class="w-100" />
<div id="artwork">
<div class="w-100 h-100">
<img src="{{ image.thumburl }}" />
</div>
</div>
<div class="col-md">
<div id="main">
<h1>{{ self.title() }}</h1>
{% if label_languages %}
<p>Label from:
@ -179,8 +203,6 @@ span.description { color: rgb(96, 96, 96); }
</form>
{% endif %}
</div>
</div>
</div>
{% endblock %}
{% block script %}

View file

@ -5,40 +5,39 @@
{% endmacro %}
{% macro navbar_inner(name) %}
<button class="navbar-toggler navbar-toggler-right" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<a class="navbar-brand" href="{{ url_for('browse_page') }}">Wikidata Art Depiction Explorer</a>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav mr-auto">
<ul class="navbar-nav mr-auto">
{{ nav_item('browse_page', 'Browse') }}
{{ nav_item('list_edits', 'Recent changes') }}
{{ nav_item('random_artwork', 'Random artwork') }}
</ul>
</ul>
<ul class="navbar-nav">
<li class="nav-item">
{% if g.user %}
<li class="nav-item">
<a class="nav-link" href="{{ url_for('user_page', username=g.user) }}">{{ g.user }}</a>
</li>
<li class="nav-item">
<a class="nav-link" href="{{ url_for('oauth_disconnect', next=request.script_root + request.full_path) }}">switch user</a>
</li>
{% else %}
<li class="nav-item">
{% set login_url = url_for('start_oauth', next=request.script_root + request.full_path) %}
<a class="nav-link" href="{{ login_url }}">connect with Wikidata</a>
</li>
{% endif %}
</ul>
<div class="container-fluid">
<a class="navbar-brand" href="{{ url_for('browse_page') }}">Wikidata Art Depiction Explorer</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav me-auto">
{{ nav_item('browse_page', 'Browse') }}
{{ nav_item('list_edits', 'Recent changes') }}
{{ nav_item('random_artwork', 'Random artwork') }}
</ul>
<ul class="navbar-nav">
<li class="nav-item">
{% if g.user %}
<li class="nav-item">
<a class="nav-link" href="{{ url_for('user_page', username=g.user) }}">{{ g.user }}</a>
</li>
<li class="nav-item">
<a class="nav-link" href="{{ url_for('oauth_disconnect', next=request.script_root + request.full_path) }}">switch user</a>
</li>
{% else %}
<li class="nav-item">
{% set login_url = url_for('start_oauth', next=request.script_root + request.full_path) %}
<a class="nav-link" href="{{ login_url }}">connect with Wikidata</a>
</li>
{% endif %}
</ul>
</div>
</div>
{% endmacro %}
{% macro navbar() %}
<nav class="navbar navbar-toggleable-md navbar-expand-lg navbar-dark bg-dark">
<nav class="navbar navbar-expand-lg bg-dark" data-bs-theme="dark">
{{ navbar_inner() }}
</nav>
{% endmacro %}