PageSourceSearch

https://sharkbytez.com/assets/js/rss-widget.js

js sharkbytez.com collected 2026-10-07 17:43:16 UTC 2,758 bytes, 63 lines download raw bytes

1/* ============================================================================
2   SHARKBYTEZ — RSS SIDEBAR WIDGET
3   ============================================================================
4   Runs only on index.html (only page with #rss-latest-list — see
5   RSS_WIDGET_HTML in admin.js). Fetches data/posts.json at page load, same
6   file every other page already reads, and lists posts as plain text links
7   under the "RSS Feed" sidebar widget. Because it reads posts.json fresh on
8   every load, it always reflects whatever you've most recently published —
9   no separate step needed beyond the normal publish flow (downloadIndex
10   already re-uploads posts.json alongside index.html).
11
12   SKIP_COUNT below is intentional, not a bug: the 5 newest posts (indices
13   0-4) are already baked into index.html above the fold as the featured
14   article + 2 midcards + 2 excerpt cards (see buildIndexPageHtml in
15   admin.js), so linking them again here would just duplicate links already
16   on the page. This widget instead shows the NEXT posts after those —
17   older content that isn't linked anywhere else on the homepage — so it
18   adds real new internal links instead of repeating existing ones.
19
20   This widget is just a "here's what's new" preview — it doesn't read
21   feed.xml itself. feed.xml is the real RSS file a feed reader subscribes
22   to; that's built by buildFeedXml in admin.js and re-downloaded by the
23   downloadIndex button every time you publish.
24   ============================================================================ */
25
26(function () {
27  "use strict";
28
29  var SKIP_COUNT = 5; // posts already shown above the fold on index.html
30  var COUNT = 2;
31
32  function escapeHtml(str) {
33    return String(str == null ? "" : str)
34      .replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
35  }
36
37  var list = document.getElementById("rss-latest-list");
38  if (!list) return; // not on index.html
39
40  function itemHtml(post) {
41    var url = post.url || "#";
42    return '<li><a href="' + url + '">' + escapeHtml(post.title) + '</a></li>';
43  }
44
45  fetch("data/posts.json", { cache: "no-store" })
46    .then(function (res) { return res.json(); })
47    .then(function (data) {
48      var posts = Array.isArray(data) ? data : [];
49
50      var sorted = posts.slice().sort(function (a, b) {
51        return new Date(b.publishedAt || b.date) - new Date(a.publishedAt || a.date);
52      });
53
54      var older = sorted.slice(SKIP_COUNT, SKIP_COUNT + COUNT);
55
56      list.innerHTML = older.length
57        ? older.map(itemHtml).join("")
58        : '<li class="rss-latest-empty">No older posts yet.</li>';
59    })
60    .catch(function () {
61      list.innerHTML = '<li class="rss-latest-empty">Couldn\'t load latest posts.</li>';
62    });
63})();

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.