formatting and semantics

This commit is contained in:
sakrecoer 2020-12-15 21:15:33 +01:00
parent e4443eca9f
commit 6e8a81051e
5 changed files with 98 additions and 54 deletions

View file

@ -11,48 +11,36 @@ layout: default
{% endfor %}
<script type="text/javascript">
function generateRandomPosts()
{
$.getJSON("/posts.json", function(data) {
console.log("[posts.json loaded for random posts]");
function generateRandomPosts() {
$.getJSON("/posts.json", function (data) {
console.log("[posts.json loaded for random posts]");
var postsCount = data.length;
var posts = data;
var randomIndexUsed = [];
var counter = 0;
var numberOfPosts = 1;
var divRandomPosts = $("#random_posts");
while (counter < numberOfPosts) {
var randomIndex = Math.floor(Math.random() * postsCount);
if (randomIndexUsed.indexOf(randomIndex) == "-1") {
var postHREF = posts[randomIndex].href;
var postTitle = posts[randomIndex].title;
var postsCount = data.length;
var posts = data;
var randomIndexUsed = [];
var counter = 0;
var numberOfPosts = 1;
var divRandomPosts = $("#random_posts");
while (counter < numberOfPosts)
{
var randomIndex = Math.floor(Math.random() * postsCount);
if (randomIndexUsed.indexOf(randomIndex) == "-1")
{
var postHREF = posts[randomIndex].href;
var postTitle = posts[randomIndex].title;
if (counter == (numberOfPosts - 1))
{
divRandomPosts.append('<a class="button" href="' + postHREF + '">🔥</a>');
}
else
{
divRandomPosts.append('<a class="button" href="' + postHREF + '">🔥</a>');
}
randomIndexUsed.push(randomIndex);
counter++;
}
if (counter == (numberOfPosts - 1)) {
divRandomPosts.append('<a class="button" href="' + postHREF + '">🔥</a>');
}
});
else {
divRandomPosts.append('<a class="button" href="' + postHREF + '">🔥</a>');
}
randomIndexUsed.push(randomIndex);
counter++;
}
}
});
}
$(document).ready(function() {
generateRandomPosts();
$(document).ready(function () {
generateRandomPosts();
});
</script>