Skip to content

Commit

Permalink
[SKIP] Add a link for visiting random articles
Browse files Browse the repository at this point in the history
  • Loading branch information
themkat committed Feb 5, 2024
1 parent db49c7c commit b8e0b44
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

<h3>{{ site.posts | size }} articles on many different topics!</h3>

<a id="random-article-link" href="javascript:void(0)">Take me to a random article!</a>

<!-- collecting all tags to make links to tag pages.
Wish I could make it in a more functional style :( I miss you map, filter and friends :( -->
{% assign tags = "" | split: "," %}
Expand Down Expand Up @@ -40,3 +42,18 @@ <h3>Tags:
</div>

<script src="https://cdn.commento.io/js/count.js"></script>

<script>
// Little snippet I originally made for AITales to get a random article
document.getElementById("random-article-link").onclick = function() {
{% for post in site.posts %}
{% if page.url != post.url %}
{% assign urls = urls | append: "'" | append: post.url | append: "', " %}
{% endif %}
{% endfor %}

const posts = [{{urls}}].slice(0, -1);
const randomPost = posts[Math.floor(Math.random() * posts.length)];
window.open(randomPost, '_self');
}
</script>

0 comments on commit b8e0b44

Please sign in to comment.