pogo/assets/index.html

68 lines
2.1 KiB
HTML
Raw Normal View History

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>CMS Loading</title>
<link rel="stylesheet" href="/assets/styles.css">
2017-09-07 04:02:59 +01:00
<!-- Custom CSS stylings from admin -->
<link rel="stylesheet" href="/assets/custom.css">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<div class="container">
<h1 id="title" class="title">Loading</h1>
<h3><a href="/admin">Admin</a></h3>
<div id="podcasts">
</div>
<footer>
<p>White Rabbit licensed under the GPLv3 | <a href="/rss">RSS</a> <a href="/json">JSON</a></p>
</footer>
</div>
<script>
get("/json", function(data){
json = JSON.parse(data);
document.title = json.title;
document.getElementById("title").innerHTML = json.title;
// Iterate through JSON
for (i=0;i<=json.items.length; i++){
var div = document.createElement('div');
div.className = 'podcast';
2017-09-07 04:02:59 +01:00
// Hacky date workaround - convert our Go date output to unix timestamp,
// then convert that into a string
date = new Date(Date.parse(json.items[i].date_published))
month = date.getMonth()+1;
datestring = date.getDate() + "/" + month + "/" + date.getFullYear();
// Build div for podcast entry
div.innerHTML = '<h3>'+json.items[i].title+' <small>'+datestring+'</small></h3><p>'+json.items[i].summary+'</p>'+
'<audio controls><source src="'+json.items[i].url+'">';
// We can safely do this because of how the Go code actually
// generates the .json file - it's consistent
// Preappend so newest is at the top
var element = document.getElementById("podcasts");
element.insertBefore(div, element.firstChild);
}
});
// Wrap xmlHttp into smaller function, I like
// to include this function whenever I need to
// do such a thing
function get(url, callback) {
var xmlHttp = new XMLHttpRequest();
xmlHttp.onreadystatechange = function() {
if (xmlHttp.readyState == 4 && xmlHttp.status == 200)
callback(xmlHttp.responseText);
}
xmlHttp.open("GET", url, true);
xmlHttp.send(null);
}
</script>
</body>
</html>