track listing generator and its integration

This commit is contained in:
veclav talica 2023-05-23 21:38:25 +05:00
parent 9086b7e38c
commit f0fafb33bd
3 changed files with 83 additions and 0 deletions

View File

@ -13,3 +13,5 @@ for d in ./articles/*; do
done
./tools/feed_generator.py ./articles/ https://mjestecko.neocities.org/ > ./html/feed.xml
./tools/track_listing_generator.py html/tracks > html/tracks.html

View File

@ -9,6 +9,7 @@ HEAD_EMBED = """
<ul class="nav">
<li><a href="/">main page</a></li>
<li><a href="https://git.poto.cafe/veclavtalica/mjestecko">source</a></li>
<li><a href="/tracks.html">tracks</a></li>
<li><a href="/feed.xml">rss</a></li>
<li><a href="/articles/mjestečko.html">about</a></li>
</ul>

View File

@ -0,0 +1,80 @@
#!/usr/bin/python3
from sys import argv, exit
from os import walk, path
if len(argv) <= 1:
print("No directory was supplied")
exit(-1)
page = """<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<meta charset="utf-8"/>
<title>Tracks</title>
<link type="text/css" rel="stylesheet" href="/style.css"/>
<script type="text/javascript" src="/xm.js"></script>
<script type="text/javascript">
(function (window, document) {
if (!window.XMPlayer)
window.XMPlayer = {};
var XMPlayer = window.XMPlayer;
window.loadAndPlayTrack = function(url) {
var request = new XMLHttpRequest();
request.responseType = "arraybuffer";
request.open('GET', url);
request.send();
request.onload = (_) => {
if (request.readyState === 4 && request.status === 200) {
XMPlayer.stop();
XMPlayer.load(request.response);
XMPlayer.play();
}
}
}
window.onload = function() {
XMPlayer.init();
}
})(window, document)
</script>
</head>
<body>
<div style="display: flex;">
<div>
<h2 id="mjestečko">mjestečko</h2>
<ul class="nav">
<li><a href="/">main page</a></li>
<li><a href="https://git.poto.cafe/veclavtalica/mjestecko">source</a></li>
<li><a href="/tracks.html">tracks</a></li>
<li><a href="/feed.xml">rss</a></li>
<li><a href="/articles/mjestečko.html">about</a></li>
</ul>
</div>
<div class="container">
<h3 id="articles">Tracks</h3>
<p>.xm module tracks of my own. Btw, they're playable in browser :3</p>
<p>Note that some files are rendered incorrectly.</p>
<hr/>
"""
for _, _, files in walk(argv[1]):
files.sort()
for f in files:
if not f.endswith('.xm'):
continue
page += (
f""" <div><p style="display: inline;">{f}</p><button style="float: right;" onclick="window.loadAndPlayTrack('/tracks/{f}')">play</button></div>\n"""
" <hr/>\n"
)
page += """ </div>
</div>
</body>
</html>
"""
print(page)