summaryrefslogtreecommitdiff
path: root/publications.js
blob: 22a0b59680b9dc13d2ccb73a9e48cfc7e3952eab (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/*
 * sophies.rocks
 *
 * Copyright (C) 2026 Zofia Szweda
 *
 * This file is part of sophies.rocks.
 *
 * sophies.rocks is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of
 * the License, or (at your option) any later version.
 *
 * sophies.rocks is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with sophies.rocks. If not, see <https://www.gnu.org/licenses/>.
 */
function escapeXml(str) {
  return String(str)
    .replace(/&/g, "&amp;")
    .replace(/</g, "&lt;")
    .replace(/>/g, "&gt;")
    .replace(/"/g, "&quot;")
    .replace(/'/g, "&apos;");
}

async function renderPublications() {
  const list = document.querySelector("#recent-publications ul");
  try {
    const res = await fetch("/publications.json");
    const posts = await res.json();
    if (posts.length === 0) {
      list.innerHTML = "<li>No publications yet.</li>";
      return;
    }
    list.innerHTML = posts
      .map(
        (p) => `
      <li>
        <a href="${escapeXml(p.url)}">${escapeXml(p.title.trim())}</a>
        ${p.date ? `<div>${escapeXml(new Date(p.date).toLocaleDateString("en-US", { month: "long", day: "numeric", year: "numeric" }))}</div>` : ""}
      </li>
    `,
      )
      .join("");
  } catch (err) {
    console.error("Failed to load publications:", err);
    list.innerHTML = "<li>Couldn't load publications right now.</li>";
  }
}
renderPublications();