Skip to content

Commit

Permalink
Update post.html
Browse files Browse the repository at this point in the history
  • Loading branch information
mrinalcs committed Jan 14, 2024
1 parent 8806ebb commit 2f6d4b8
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions _layouts/post.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<header>
<h1>{{ page.title }}</h1>
<time datetime="{{ page.date | date: "%Y-%m-%d" }}">{{ page.date | date: "%B %-d, %Y" }}</time>
<span id="view">views: counting..</span>
</header>

<aside>
Expand All @@ -20,3 +21,21 @@ <h1>{{ page.title }}</h1>
{{ content }}

</article>




<script>
function getSlugFromUrl() {
var pathArray = window.location.pathname.split('/');
var slug = pathArray[pathArray.length - 1];
return slug || 'home';
}
var slug = getSlugFromUrl();
fetch('https://api.mrinal.tk/1/view_counter.php?slug=' + slug)
.then(response => response.text())
.then(viewCount => {
document.getElementById('view').textContent = ' views: ' + viewCount;
})
.catch(error => console.error('Error fetching view count:', error));
</script>

0 comments on commit 2f6d4b8

Please sign in to comment.