|
59 | 59 | </div> |
60 | 60 | </section> |
61 | 61 |
|
62 | | - <section class="section" id="downloads"> |
| 62 | + |
| 63 | + <section class="section" id="downloads"> |
63 | 64 | <div class="container"> |
64 | 65 | <h2 class="mb-5">Downloads</h2> |
65 | 66 |
|
66 | | - <h3>Nightly</h3> |
67 | | - <p class="mt-2 mb-5">Fresh doukutsu-rs builds with freeware game data, compiled on each commit of <code>master</code> branch.</p> |
68 | | - |
69 | | - <div class="columns is-multiline"> |
70 | | - {{ range .Site.Params.downloads_nightly }} |
71 | | - <div class="column is-one-third"> |
72 | | - <div class="card"> |
73 | | - <header class="card-header"> |
74 | | - <p class="card-header-title">{{ .platform }}</p> |
75 | | - </header> |
76 | | - |
77 | | - <div class="card-content"> |
78 | | - <div class="content"> |
79 | | - {{ if .job_name }} |
80 | | - <div id="info-{{ .job_name }}" class="mb-5"> |
81 | | - <strong>Version: </strong> |
82 | | - <span class="version">...</span><br/> |
83 | | - |
84 | | - <strong>Git commit ID: </strong> |
85 | | - <span class="commit">...</span><br/> |
86 | | - </div> |
87 | | - {{ end }} |
88 | | - |
89 | | - <div class="buttons"> |
90 | | - {{ if .link }} |
91 | | - <a class="button is-primary link" href="{{ .link }}">Download</a> |
92 | | - {{ else }} |
93 | | - <p>No prebuilts for this platform yet.</p> |
94 | | - {{ end }} |
95 | | - </div> |
96 | | - </div> |
97 | | - </div> |
98 | | - </div> |
99 | | - </div> |
100 | | - {{ end }} |
| 67 | + <div id="downloads-nightly"> |
| 68 | + <h3>Nightly</h3> |
| 69 | + <p class="mt-2 mb-5">Fresh doukutsu-rs builds, compiled on each commit of <code>master</code> and features branch.</p> |
| 70 | + |
| 71 | + <div class="columns is-multiline"> |
| 72 | + {{ range .Site.Params.downloads.platforms }} |
| 73 | + {{ partial "downloads-section.html" (dict "platform" . "channel" "nightly" "fallback" true) }} |
| 74 | + {{ end }} |
| 75 | + </div> |
| 76 | + </div> |
| 77 | + <div class="mt-6" id="downloads-stable"> |
| 78 | + <h3>Stable</h3> |
| 79 | + <p class="mt-2 mb-5">The latest changes and fixes are missing, but in general all features are tested and works fine.</p> |
| 80 | + |
| 81 | + <div class="columns is-multiline"> |
| 82 | + {{ range .Site.Params.downloads.platforms }} |
| 83 | + {{ partial "downloads-section.html" (dict "platform" . "channel" "stable" "fallback" false) }} |
| 84 | + {{ end }} |
| 85 | + </div> |
101 | 86 | </div> |
102 | 87 | </div> |
103 | 88 | </section> |
104 | 89 |
|
105 | 90 | <script> |
106 | | - async function setInfo(el, info) { |
107 | | - if (el) { |
108 | | - const verEl = el.querySelector('.version'); |
109 | | - if (verEl) { |
110 | | - verEl.innerText = info.version |
111 | | - } |
| 91 | + async function setInfo(container, info) { |
| 92 | + if (!container) { |
| 93 | + return; |
| 94 | + } |
112 | 95 |
|
113 | | - const commEl = el.querySelector('.commit'); |
114 | | - if (commEl) { |
115 | | - commEl.innerHTML = "<code>" + info.commit.slice(0, 7) + "</code>"; |
116 | | - } |
| 96 | + const versionEl = container.querySelector('.info .version'); |
| 97 | + if (versionEl) { |
| 98 | + versionEl.innerText = info.version |
| 99 | + } |
117 | 100 |
|
118 | | - const linkEl = el.parentNode.querySelector('.link'); |
119 | | - if (linkEl) { |
120 | | - linkEl.href = info.link; |
121 | | - } |
| 101 | + const commitEl = container.querySelector('.info .commit'); |
| 102 | + if (commitEl && info.commit) { |
| 103 | + commitEl.innerHTML = '<code>' + info.commit.slice(0, 7) + '</code>'; |
| 104 | + } else if (commitEl) { |
| 105 | + commitEl.parentNode.remove(); |
| 106 | + } |
| 107 | + |
| 108 | + const dateEl = container.querySelector('.info .date'); |
| 109 | + if (dateEl && info.date) { |
| 110 | + dateEl.innerHTML = (new Date(info.date * 1000)).toLocaleDateString('{{ .Site.LanguageCode }}', { |
| 111 | + year: "numeric", |
| 112 | + month: "long", |
| 113 | + day: "2-digit", |
| 114 | + hour: "numeric", |
| 115 | + minute: "numeric", |
| 116 | + second: "numeric", |
| 117 | + //timeZoneName: "short" |
| 118 | + }); |
| 119 | + } |
| 120 | + |
| 121 | + const linkEl = container.querySelector('.link'); |
| 122 | + if (linkEl) { |
| 123 | + linkEl.classList.remove("is-loading"); |
| 124 | + |
| 125 | + linkEl.href = info.link; |
| 126 | + linkEl.textContent = "Download"; |
122 | 127 | } |
123 | 128 | } |
124 | | - |
125 | | - (async() => { |
126 | | - const req = await fetch('{{ .Site.Params.metadata.nightly.link }}', { |
127 | | - headers: { |
128 | | - 'Accept': 'application/json' |
129 | | - } |
130 | | - }); |
131 | | - const data = await req.json(); |
132 | 129 |
|
133 | | - for (const platform in data) { |
134 | | - const info = data[platform]; |
135 | | - if (info.version !== undefined) { |
136 | | - const el = document.getElementById(`info-${platform}`); |
| 130 | + async function setFail(channel, msg) { |
| 131 | + const channelContainer = document.getElementById(`downloads-${channel}`); |
| 132 | + const blocks = channelContainer.querySelectorAll('.content'); |
| 133 | + |
| 134 | + if (!msg) { |
| 135 | + msg = "Failed to fetch direct download link." |
| 136 | + } |
| 137 | + |
| 138 | + for (const block of blocks) { |
| 139 | + block.innerHTML = String.raw`<p>${msg}</p>`; |
| 140 | + } |
| 141 | + } |
| 142 | + |
| 143 | + async function fetchBuilds(channel, link, fallback = false, failMsg = null) { |
| 144 | + try { |
| 145 | + const req = await fetch(link, { |
| 146 | + headers: { |
| 147 | + 'Accept': 'application/json' |
| 148 | + } |
| 149 | + }); |
| 150 | + |
| 151 | + const data = await req.json(); |
| 152 | + console.log(data); |
| 153 | + |
| 154 | + for (const platform in data) { |
| 155 | + const info = data[platform]; |
| 156 | + console.log(info); |
| 157 | + if (info.version !== undefined) { |
| 158 | + const container = document.getElementById(`downloads-${channel}-${platform}`); |
| 159 | + |
| 160 | + await setInfo(container, info); |
| 161 | + continue; |
| 162 | + } |
137 | 163 |
|
138 | | - setInfo(el, info); |
139 | | - } else { |
140 | 164 | for (const arch in info) { |
141 | 165 | const archInfo = info[arch]; |
142 | | - const el = document.getElementById(`info-${platform}-${arch}`); |
| 166 | + const container = document.getElementById(`downloads-${channel}-${platform}-${arch}`); |
143 | 167 |
|
144 | | - setInfo(el, archInfo); |
| 168 | + await setInfo(container, archInfo); |
145 | 169 | } |
146 | 170 | } |
| 171 | + } catch (ex) { |
| 172 | + console.error(`Failed to fetch builds for '${channel}' channel.`); |
| 173 | + console.error(ex); |
| 174 | + |
| 175 | + if (!fallback) { |
| 176 | + await setFail(channel, failMsg); |
| 177 | + } |
| 178 | + |
| 179 | + return; |
147 | 180 | } |
| 181 | + |
| 182 | + |
| 183 | + } |
| 184 | + |
| 185 | + (async() => { |
| 186 | + await fetchBuilds('nightly', '{{ .Site.Params.downloads.nightly.metadata }}', true); |
| 187 | + await fetchBuilds( |
| 188 | + 'stable', |
| 189 | + '{{ .Site.Params.downloads.stable.metadata }}', |
| 190 | + false, |
| 191 | + 'Failed to fetch a direct download link. Check out the releases <a class="link" href="{{ .Site.Params.downloads.stable.fail_page }}">download page</a>.'); |
148 | 192 | })(); |
149 | 193 | </script> |
150 | 194 |
|
|
0 commit comments