PageSourceSearch

https://translationcore-website.netlify.app/scripts/resource-links.js

js translationcore-website.netlify.app collected 2026-10-03 11:31:58 UTC 1,917 bytes, 52 lines download raw bytes

1/**
2 * Dynamically resolve download links to the latest release from the Door43 Gitea API.
3 *
4 * Links with `data-download="{repo}"` get their href updated to the latest LETTER PDF.
5 * Links with `data-door43="{repo}"` get their href updated to the latest version on Door43.
6 *
7 * Fallback: if the API is unreachable, the links remain pointed at the releases/latest
8 * redirect page, which Door43 handles gracefully.
9 */
10(function () {
11  const DCS_API = 'https://git.door43.org/api/v1/repos/unfoldingWord';
12  const REPOS = ['en_tw', 'en_ta', 'en_ult', 'en_ust', 'en_tq'];
13
14  async function fetchLatestTag(repo) {
15    const resp = await fetch(`${DCS_API}/${repo}/releases/latest`, {
16      headers: { Accept: 'application/json' }
17    });
18    if (!resp.ok) throw new Error(`${repo}: HTTP ${resp.status}`);
19    const data = await resp.json();
20    return data.tag_name;
21  }
22
23  function buildPdfUrl(repo, tag) {
24    const filename = `${repo}_${tag}_LETTER.pdf`;
25    return `https://git.door43.org/unfoldingWord/${repo}/releases/download/${encodeURIComponent(tag)}/${encodeURIComponent(filename)}`;
26  }
27
28  function buildDoor43Url(repo, tag) {
29    return `https://preview.door43.org/u/unfoldingWord/${repo}/${tag}/`;
30  }
31
32  document.addEventListener('DOMContentLoaded', () => {
33    REPOS.forEach(async (repo) => {
34      try {
35        const tag = await fetchLatestTag(repo);
36
37        // Update download links
38        document.querySelectorAll(`[data-download="${repo}"]`).forEach((link) => {
39          link.href = buildPdfUrl(repo, tag);
40        });
41
42        // Update Door43 preview links
43        document.querySelectorAll(`[data-door43="${repo}"]`).forEach((link) => {
44          link.href = buildDoor43Url(repo, tag);
45        });
46      } catch (err) {
47        console.warn(`Could not fetch latest release for ${repo}:`, err);
48        // Links keep their fallback hrefs (releases/latest redirect)
49      }
50    });
51  });
52})();

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.