adds nav to the header

This commit is contained in:
Effie 2023-06-07 20:02:10 +10:00
parent df46e34049
commit 12d51dd7d2
15 changed files with 113 additions and 100 deletions

29
app.py
View File

@ -10,17 +10,20 @@ app = flask.Flask('songbook')
# db = sqlite3.connect("file:songbook.sqlite?mode=ro", uri=True) # db = sqlite3.connect("file:songbook.sqlite?mode=ro", uri=True)
# return flask.render_template('.jinja', # return flask.render_template('.html',
# ) # )
# HOMEPAGE # HOMEPAGE
def openbook():
return sqlite3.connect("file:songbook.sqlite?mode=ro", uri=True)
@app.route('/') @app.route('/')
def homepage(): def homepage():
return flask.render_template('home.jinja') return flask.render_template('home.html')
# SONG INDEX # SONG INDEX
@ -31,7 +34,7 @@ def song_redirect():
@app.route('/index') @app.route('/index')
def songindex(): def songindex():
db = sqlite3.connect("file:songbook.sqlite?mode=ro", uri=True) db = openbook()
album_info = db.execute(''' album_info = db.execute('''
select select
@ -56,7 +59,7 @@ def songindex():
track track
''').fetchall() ''').fetchall()
return flask.render_template('songindex.jinja', return flask.render_template('songindex.html',
album_info=album_info, album_info=album_info,
song_info=song_info song_info=song_info
) )
@ -66,7 +69,7 @@ def songindex():
@app.route('/motif') @app.route('/motif')
def motifindex(): def motifindex():
db = sqlite3.connect("file:songbook.sqlite?mode=ro", uri=True) db = openbook()
category_info = db.execute(''' category_info = db.execute('''
select select
@ -86,7 +89,7 @@ def motifindex():
id id
''').fetchall() ''').fetchall()
return flask.render_template('motifindex.jinja', return flask.render_template('motifindex.html',
category_info = category_info, category_info = category_info,
motif_info = motif_info motif_info = motif_info
) )
@ -96,7 +99,7 @@ def motifindex():
@app.route('/album/<int:id>') @app.route('/album/<int:id>')
def albumpage(id): def albumpage(id):
db = sqlite3.connect("file:songbook.sqlite?mode=ro", uri=True) db = openbook()
album_info = db.execute(''' album_info = db.execute('''
select select
@ -124,7 +127,7 @@ def albumpage(id):
(id,) (id,)
).fetchall() ).fetchall()
return flask.render_template('album.jinja', return flask.render_template('album.html',
album_info=album_info, album_info=album_info,
song_info=song_info song_info=song_info
) )
@ -134,7 +137,7 @@ def albumpage(id):
@app.route('/motif/<int:id>') @app.route('/motif/<int:id>')
def motifpage(id): def motifpage(id):
db = sqlite3.connect("file:songbook.sqlite?mode=ro", uri=True) db = openbook()
# query motif # query motif
@ -163,12 +166,13 @@ def motifpage(id):
where where
motif_id = ? motif_id = ?
order by order by
feature desc,
song_id song_id
''', ''',
(id,) (id,)
).fetchall() ).fetchall()
return flask.render_template('motif.jinja', return flask.render_template('motif.html',
name=name, name=name,
clip_info=clip_info clip_info=clip_info
) )
@ -178,7 +182,7 @@ def motifpage(id):
@app.route('/song/<int:id>') @app.route('/song/<int:id>')
def songpage(id): def songpage(id):
db = sqlite3.connect("file:songbook.sqlite?mode=ro", uri=True) db = openbook()
# query song name # query song name
@ -250,12 +254,13 @@ def songpage(id):
where where
song_id = ? song_id = ?
order by order by
feature desc,
song_id song_id
''', ''',
(id,) (id,)
).fetchall() ).fetchall()
return flask.render_template('song.jinja', return flask.render_template('song.html',
name=name, name=name,
id=id, id=id,
album_info=album_info, album_info=album_info,

Binary file not shown.

View File

@ -0,0 +1,2 @@
body{max-width:50rem;margin-left:auto;margin-right:auto;}
nav{}

16
templates/album.html Normal file
View File

@ -0,0 +1,16 @@
{% extends "nav.html" %}
{% block title %}{{ album_info[0] }}{% endblock %}
{% block content %}
<h1>{{ album_info[0] }}</h1>
<p>Released: {{ album_info[1] }}
<!-- List songs -->
<ul>
{% for song_id, track, name, name_jp in song_info %}
<li><a href="{{ url_for('songpage', id=song_id) }}">#{{ track }}: {{name}} / {{name_jp}}</li></a>
{% endfor %}
</ul>
{% endblock %}

View File

@ -1,16 +0,0 @@
{% extends "nav.jinja" %}
{% block title %}{{ album_info[0] }}{% endblock %}
{% block content %}
<h1>{{ album_info[0] }}</h1>
<p>Released: {{ album_info[1] }}
<!-- List songs -->
<ul>
{% for song_id, track, name, name_jp in song_info %}
<li><a href="{{ url_for('songpage', id=song_id) }}">#{{ track }}: {{name}} / {{name_jp}}</li></a>
{% endfor %}
</ul>
{% endblock %}

17
templates/base.html Normal file
View File

@ -0,0 +1,17 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>{% block title %}{% endblock %} - Eorzea Songbook</title>
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=1" />
<meta name="description" content="Listen to the motifs of Final Fantasy XIV's soundtrack." />
<link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}" />
<link rel="icon" sizes="16x16 32x32 48x48" type="image/png" href="" />
</head>
<body>
{% block basecontent %}{% endblock %}
</body>
</html>

View File

@ -1,17 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>{% block title %}{% endblock %} - Eorzea Songbook</title>
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=1" />
<meta name="description" content="Listen to the motifs of Final Fantasy XIV's soundtrack." />
<link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}" />
<link rel="icon" sizes="16x16 32x32 48x48" type="image/png" href="" />
</head>
<body>
{% block basecontent %}{% endblock %}
</body>
</html>

View File

@ -1,4 +1,4 @@
{% extends "base.jinja" %} {% extends "base.html" %}
{% block title %}Home{% endblock %} {% block title %}Home{% endblock %}
{% block basecontent %} {% block basecontent %}

23
templates/motif.html Normal file
View File

@ -0,0 +1,23 @@
{% extends "nav.html" %}
{% block title %}{{ name }}{% endblock %}
{% block content %}
<h1> Motif: {{ name }} </h1>
<!-- Clips -->
<p>Clips: </p>
<ul>
{% for song_id, motif_id, song in clip_info %}
<li>
<audio
controls
src = "{{ url_for('static', filename='clip/') }}{{ '%04d' % song_id }}-{{ '%03d' % motif_id }}.flac" type="audio/flac">
</audio>
<a href="/song/{{ song_id }}">{{ song }}</a>
</li>
{% endfor %}
</ul>
{% endblock %}

View File

@ -1,22 +0,0 @@
{% extends "nav.jinja" %}
{% block title %}{{ name }}{% endblock %}
{% block content %}
<h1> Motif: {{ name }} </h1>
<!-- Clips -->
<p>Clips: </p>
<ul>
{% for song_id, motif_id, song in clip_info %}
<li>
<audio
controls
src = "{{ url_for('static', filename='clip/') }}{{ '%04d' % song_id }}-{{ '%03d' % motif_id }}.flac">
</audio>
<a href="/song/{{ song_id }}">{{ song }}</a>
</li>
{% endfor %}
{% endblock %}

View File

@ -1,4 +1,4 @@
{% extends "nav.jinja" %} {% extends "nav.html" %}
{% block title %}Motif Index{% endblock %} {% block title %}Motif Index{% endblock %}
{% block content %} {% block content %}

23
templates/nav.html Normal file
View File

@ -0,0 +1,23 @@
{% extends "base.html" %}
{% block basecontent %}
<header>
<nav>
<ul>
<li><a href="{{ url_for('songindex') }}">Songs</a></li>
<li><a href="{{ url_for('homepage') }}">Home</a></li>
<li><a href="{{ url_for('motifindex') }}">Motifs</a></li>
</ul>
</nav>
</header>
{% block content %}{% endblock %}
<footer>
<p> The footer will be in here, when it's ready. </p>
</footer>
{% endblock basecontent %}

View File

@ -1,18 +0,0 @@
{% extends "base.jinja" %}
{% block basecontent %}
<header>
<p> The header will be in here. For now, click <a href="{{ url_for('homepage') }}">here</a> to go back to the home page.</p>
</header>
{% block content %}{% endblock %}
<footer>
<p> The footer will be in here, when it's ready. </p>
</footer>
{% endblock basecontent %}

View File

@ -1,4 +1,4 @@
{% extends "nav.jinja" %} {% extends "nav.html" %}
{% block title %}{{ name }}{% endblock %} {% block title %}{{ name }}{% endblock %}
{% block content %} {% block content %}
@ -31,10 +31,10 @@
<li> <li>
<audio <audio
controls controls
src = "{{ url_for('static', filename='clip/') }}{{ '%04d' % song_id }}-{{ '%03d' % motif_id }}.flac"> src = "{{ url_for('static', filename='clip/') }}{{ '%04d' % song_id }}-{{ '%03d' % motif_id }}.flac" type="audio/flac">
</audio> </audio>
<a href = "{{ url_for('motifpage', id=motif_id) }}"> {{ motif }} </a> <a href = "{{ url_for('motifpage', id=motif_id) }}"> {{ motif }} </a>
</li> </li>
{% endfor %} {% endfor %}
</ul>
{% endblock %} {% endblock %}

View File

@ -1,4 +1,4 @@
{% extends "nav.jinja" %} {% extends "nav.html" %}
{% block title %}Song Index{% endblock %} {% block title %}Song Index{% endblock %}
{% block content %} {% block content %}