Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b9a4712

Browse files
committed
Slow down Mastodon refresh rate and refactor the JavaScript.
1 parent 4579fa5 commit b9a4712

File tree

4 files changed

+70
-41
lines changed

4 files changed

+70
-41
lines changed

_config.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ collections:
2828

2929
# Head
3030
metaKeywords: "mendercon, menders, unconference, refactoring, development, programming, legacy, code, software, remodeling, technical, debt"
31-
mastodonServer: "https://toot.legacycode.rocks"
32-
mastodonAccount: "@mendercon"
3331
socialImageSrcGooglePlus: "/img/seo/sharing-google-plus.png"
3432
socialImageSrcMastodon: "/img/seo/sharing-mastodon.png"
3533
socialImageSrcFacebook: "/img/seo/sharing-facebook.png"
@@ -100,8 +98,12 @@ venueFeatures: ["3 huge cinema screens", "Doulby Digital Surround EX audio syste
10098
tootsFeedImage: "mastodon-feed.jpg"
10199
tootsFeedTitle: "What's Up?"
102100
mastodonHashTag: "MenderCon2025"
103-
mastodonFeedApiUrl: "https://toot.legacycode.rocks/api/v1/timelines/tag/MenderCon2025"
104-
mastodonFeedUrl: "https://toot.legacycode.rocks/tags/MenderCon2025"
101+
mastodonServer: "https://toot.legacycode.rocks/"
102+
mastodonAccount: "@mendercon"
103+
mastodonFeedUrl: "tags/MenderCon2025"
104+
mastodonFeedApiUrl: "api/v1/timelines/tag/MenderCon2025"
105+
mastodonRefreshIntervalMilliSeconds: 15000
106+
105107

106108
# Partners Block
107109
organizersTitle: "Organizers"

_includes/mastodon-feed.html

Lines changed: 64 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,76 @@
33
<div class="overlay solid-overlay"></div>
44
<div class="content-wrapper">
55
<div class="col-md-8 col-md-offset-2">
6-
<a href="{{site.mastodonServer}}/{{ site.mastodonAccount }}" target="_blank">
6+
<a href="{{site.mastodonServer}}{{ site.mastodonAccount }}" target="_blank">
77
<svg class="icon" viewBox="0 0 24 24">
88
<use xlink:href="{{ site.baseurl }}/img/sprites/sprites.svg#icon-mastodon"></use>
99
</svg>
1010
</a>
11-
<h3>{{ site.tootsFeedTitle }} <a href="{{ site.mastodonFeedUrl }}" target="_blank">#{{ site.mastodonHashTag }}</a>
11+
<h3>{{ site.tootsFeedTitle }} <a href="{{site.mastodonServer}}{{ site.mastodonFeedUrl }}" target="_blank">#{{ site.mastodonHashTag }}</a>
1212
</h3>
1313
<div id="toots" class="toots"></div>
1414
</div>
1515
</div>
1616
</section>
17-
<!-- End Mastodon Feed Section -->
17+
<script>
18+
document.addEventListener('DOMContentLoaded', function() {
19+
const mastodonFeedApiUrl = '{{ site.mastodonServer}}{{ site.mastodonFeedApiUrl }}';
20+
const mastodonRefreshIntervalMilliSeconds = '{{ site.mastodonRefreshIntervalMilliSeconds }}';
21+
22+
if (typeof mastodonFeedApiUrl !== 'undefined' && mastodonFeedApiUrl) {
23+
fetch(mastodonFeedApiUrl)
24+
.then(response => {
25+
if (!response.ok) {
26+
throw new Error('Network response was not ok');
27+
}
28+
return response.json();
29+
})
30+
.then(data => {
31+
const tootsContainer = document.getElementById('toots');
32+
data.forEach(gist => {
33+
const tootDate = new Date(gist.created_at);
34+
const formattedTootDate = new Intl.DateTimeFormat('en-US', {
35+
dateStyle: 'full',
36+
timeStyle: 'long',
37+
timeZone: 'America/New_York'
38+
}).format(tootDate);
39+
40+
const tootElement = document.createElement('div');
41+
tootElement.className = 'toot animated fadeInUp hidden';
42+
43+
tootElement.innerHTML =
44+
'<div class="toot-text">' +
45+
gist.content +
46+
'</div>' +
47+
'<p class="toot-meta">' +
48+
'by <a href="' + gist.account.url + '" target="_blank">@' + gist.account.display_name + '</a>' +
49+
' posted <a href="' + gist.url + '" target="_blank">' + formattedTootDate + '</a>' +
50+
'</p>';
51+
52+
tootsContainer.appendChild(tootElement);
53+
});
54+
55+
animateToots();
56+
})
57+
.catch(error => console.error('Error fetching Mastodon feed:', error));
58+
59+
function animateToots() {
60+
const toots = document.querySelectorAll('#toots .toot');
61+
let i = 0;
62+
63+
if (toots.length === 0) return;
64+
65+
toots[0].classList.remove('hidden');
66+
67+
function changeToots() {
68+
toots[i].classList.add('hidden');
69+
i = (i + 1) % toots.length;
70+
toots[i].classList.remove('hidden');
71+
}
72+
73+
setInterval(changeToots, mastodonRefreshIntervalMilliSeconds);
74+
}
75+
}
76+
});
77+
</script>
78+
<!-- End Mastodon Feed Section -->

_layouts/default.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@
4848
<script>
4949
Waves.displayEffect();
5050
{% if page.permalink == '/' %}
51-
var mastodonFeedApiUrl = '{{ site.mastodonFeedApiUrl }}';
5251
$(document).ready(function () {
5352
$(function () {
5453
if ($(window).width() > 767) {

js/scripts.js

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -227,39 +227,6 @@
227227
$('.slot').click(function() {
228228
location.hash = $(this).attr('id');
229229
});
230-
231-
if (typeof mastodonFeedApiUrl !== 'undefined') {
232-
$.getJSON(mastodonFeedApiUrl, function(data) {
233-
$.each(data, function(i, gist) {
234-
var tootDate = new Date(gist.created_at);
235-
var formattedTootDate = new Intl.DateTimeFormat('en-US', { dateStyle: 'full', timeStyle: 'long', timeZone: 'America/New_York' }).format(tootDate);
236-
var tootElement =
237-
'<div class="toot animated fadeInUp hidden">' +
238-
'<div class="toot-text">' +
239-
gist.content +
240-
'</div>' +
241-
'<p class="toot-meta">' +
242-
'by <a href="' + gist.account.url + '" target="_blank">@' + gist.account.display_name + '</a>' +
243-
' posted <a href="' + gist.url + '" target="_blank">' + formattedTootDate + '</a>'
244-
'</p>' +
245-
'</div>';
246-
$('#toots').append(tootElement);
247-
});
248-
animateToots();
249-
});
250-
251-
function animateToots() {
252-
var $toots = $('#toots').find('.toot'),
253-
i = 0;
254-
$($toots.get(0)).removeClass('hidden');
255-
function changeToots() {
256-
var next = (++i % $toots.length);
257-
$($toots.get(next - 1)).addClass('hidden');
258-
$($toots.get(next)).removeClass('hidden');
259-
}
260-
var interval = setInterval(changeToots, 5000);
261-
}
262-
}
263230
});
264231

265232
})(jQuery);

0 commit comments

Comments
 (0)