Add hit/view/update stats to Neocities front page

This commit is contained in:
Kyle Drake 2017-06-23 10:25:20 -07:00
parent ffb67cd3a8
commit 4a33f3f9d3
3 changed files with 54 additions and 2 deletions

View file

@ -31,11 +31,29 @@ get '/?' do
end
if SimpleCache.expired?(:sites_count)
@sites_count = SimpleCache.store :sites_count, Site.count.roundup(100), 10.minutes
@sites_count = SimpleCache.store :sites_count, Site.count.roundup(100), 4.hours
else
@sites_count = SimpleCache.get :sites_count
end
if SimpleCache.expired?(:total_hits_count)
@total_hits_count = SimpleCache.store :total_hits_count, DB['SELECT SUM(hits) AS hits FROM SITES'].first[:hits], 4.hours
else
@total_hits_count = SimpleCache.get :total_hits_count
end
if SimpleCache.expired?(:total_views_count)
@total_views_count = SimpleCache.store :total_views_count, DB['SELECT SUM(views) AS views FROM SITES'].first[:views], 4.hours
else
@total_views_count = SimpleCache.get :total_views_count
end
if SimpleCache.expired?(:changed_count)
@changed_count = SimpleCache.store :changed_count, DB['SELECT SUM(changed_count) AS changed_count FROM SITES'].first[:changed_count], 4.hours
else
@changed_count = SimpleCache.get :changed_count
end
if SimpleCache.expired?(:blog_feed_html)
@blog_feed_html = ''

View file

@ -1469,6 +1469,7 @@ a.tag:hover {
margin-bottom: 0;
}
}
.section.support {
padding-bottom: 100px;
p {
@ -1506,6 +1507,25 @@ a.tag:hover {
.section.features p, .section.features h3 {
text-align: left;
}
.section .stats {
padding-top: 10px;
padding-bottom: 30px;
}
.section .stats h2 {
font-weight: bold;
font-size: 3em;
padding-bottom: 0px;
letter-spacing: 2px;
font-family: sans-serif;
margin-bottom: 0px;
@media (max-device-width:480px), screen and (max-width:1200px){
margin-top: 20px;
font-size: 1.8em;
}
}
.section .stats h3 {
margin: 0;
}
.section .press {
display: inline-block;
clear: both;

View file

@ -242,8 +242,22 @@
<h3><i class="fa fa-university"></i>Open Source</h3>
<p>We <a href="https://github.com/neocities" target="_blank">publish</a> the code that powers the site for inspection. We want to win your trust—not lock you in.</p>
</div>
</div>
<div class="col col-100">
<div class="row stats">
<div class="col col-33">
<h2><%= @total_hits_count.to_comma_separated %></h2>
<h3 style="text-align: center">Site Hits</h3>
</div>
<div class="col col-33">
<h2><%= @total_views_count.to_comma_separated %></h2>
<h3 style="text-align: center">Site Visitors</h3>
</div>
<div class="col col-33">
<h2><%= @changed_count.to_comma_separated %></h2>
<h3 style="text-align: center">Site Updates</h3>
</div>
</div>
<div class="col col-100">