Skip to content

Commit bb8dee6

Browse files
authored
Add Javascript to automatically fetch latest release from Github (#7)
* Adapted from rain's https://gist.github.com/Rainyan/322e811504ec11296538849299a0da29
1 parent 9cddbba commit bb8dee6

File tree

4 files changed

+97
-9
lines changed

4 files changed

+97
-9
lines changed

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ SITE_TITLE := Neotokyo; Rebuild
44
SRC_DIR := src
55
DST_DIR := _out
66
SRCS := $(shell find $(SRC_DIR) -name '*.md' | grep -vxF "src/index.md")
7-
SRCS_CPY := $(SRC_DIR)/style.css $(SRC_DIR)/favicon.ico $(shell find $(SRC_DIR) -name '*.png')
7+
SRCS_CPY := $(SRC_DIR)/style.css $(SRC_DIR)/favicon.ico $(shell find $(SRC_DIR) -name '*.png') $(SRC_DIR)/releases.js
88

99
BLOG_LIST_FILE := _metadata/blog_list
1010
BLOG_DATES := _metadata/blog_dates
@@ -29,7 +29,7 @@ $(DST_DIR)/%.html: $(SRC_DIR)/%.md $(SRC_DIR)/_header.html $(SRC_DIR)/_footer.ht
2929
@mkdir -p $(dir $@)
3030
@SSG_TITLE=$$(lowdown -X title $<); \
3131
m4 -DSSG_TITLE="$$SSG_TITLE" $(SRC_DIR)/_header.html > $@.header.html.tmp
32-
@lowdown -Thtml -o $@.tmp $<
32+
@lowdown -Thtml --html-no-skiphtml --html-no-escapehtml -o $@.tmp $<
3333
@cat $@.header.html.tmp $@.tmp $(SRC_DIR)/_footer.html > $@
3434
@rm $@.tmp $@.header.html.tmp
3535
@case $< in $(SRC_DIR)/blog/*) \
@@ -55,7 +55,7 @@ $(DST_DIR)/index.html: $(SRC_DIR)/blog/*/*.md $(SRC_DIR)/_header.html $(SRC_DIR)
5555
@cat $(BLOG_LIST_FILE).tmp | sort -ur > $(BLOG_LIST_FILE)
5656
@rm $(BLOG_LIST_FILE).tmp
5757
@m4 -DSSG_TITLE="Home" $(SRC_DIR)/_header.html > $@.header.html.tmp
58-
@lowdown -Thtml -o $@.tmp < $(SRC_DIR)/index.md
58+
@lowdown -Thtml --html-no-skiphtml --html-no-escapehtml -o $@.tmp < $(SRC_DIR)/index.md
5959
@echo "<ul>" >> $@.mid
6060
@cat $(BLOG_LIST_FILE) | while read line; do \
6161
entry_date=$$(echo "$$line" | cut -f1); \

src/guide/install/index.md

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,18 @@ Install [Source SDK Base 2013 (MP) Multiplayer](steam://rungameid/243750) (AppID
2525

2626
## Downloading NT;RE
2727

28-
For Pre-alpha v9.0, click on the following links to download the zip files:
29-
30-
* Windows and Linux: [neo-20241012-bc3a767-resources.zip](https://github.com/NeotokyoRebuild/neo/releases/download/v9.0-prealpha/neo-20241012-bc3a767-resources.zip)
31-
* Windows-only: [neo-20241012-bc3a767-libraries-Windows-Release.zip](https://github.com/NeotokyoRebuild/neo/releases/download/v9.0-prealpha/neo-20241012-bc3a767-libraries-Windows-Release.zip)
32-
* Linux-only: [neo-20241012-bc3a767-libraries-Linux-Release.zip](https://github.com/NeotokyoRebuild/neo/releases/download/v9.0-prealpha/neo-20241012-bc3a767-libraries-Linux-Release.zip)
28+
Click on the following links to download the zip files:
29+
30+
<div id="downloading-ntre-div">
31+
<noscript>
32+
<p>Sorry, Javascript is required to generate the download links.</p>
33+
<p>
34+
If you don't want to enable Javascript, see the download links manually from:
35+
<a href="https://github.com/NeotokyoRebuild/neo/releases">https://github.com/NeotokyoRebuild/neo/releases</a>
36+
</p>
37+
</noscript>
38+
<script type="text/javascript" src="/releases.js"></script>
39+
</div>
3340

3441
For other versions, go to the [GitHub release](https://github.com/NeotokyoRebuild/neo/releases/) page and find the
3542
version you want and expand the "Assets" section. You only need to install a zip file that ends with

src/index.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,25 @@ title: Home
33
# Neotokyo; Rebuild
44
Neotokyo; Rebuild is a work in progress Source SDK 2013 mod of
55
[NEOTOKYO](https://store.steampowered.com/app/244630/NEOTOKYO/).
6-
Builds are available for Windows and Linux on GitHub, the latest release is [Pre-Alpha v9.0](https://github.com/NeotokyoRebuild/neo/releases/tag/v9.0-prealpha).
6+
Builds available for Windows and Linux are hosted on GitHub.
77

88
* [Install NT;RE (client)](/guide/install/)
99
* [Git Repository on GitHub](https://github.com/NeotokyoRebuild/neo)
1010

11+
12+
## Downloading NT;RE
13+
14+
<div id="downloading-ntre-div">
15+
<noscript>
16+
<p>Sorry, Javascript is required to generate the download links.</p>
17+
<p>
18+
If you don't want to enable Javascript, see the download links manually from:
19+
<a href="https://github.com/NeotokyoRebuild/neo/releases">https://github.com/NeotokyoRebuild/neo/releases</a>
20+
</p>
21+
</noscript>
22+
<script type="text/javascript" src="/releases.js"></script>
23+
</div>
24+
1125
## Blog
1226
[Atom feed](/atom.xml)
1327

src/releases.js

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
"use strict";
2+
3+
function getDownloadLinks() {
4+
const SCHEME = "https",
5+
API = "api.github.com",
6+
RES = "repos",
7+
ORG = "NeotokyoRebuild",
8+
REPO = "neo",
9+
QUERY = "releases/latest";
10+
11+
const url = `${SCHEME}://${API}/${RES}/${ORG}/${REPO}/${QUERY}`;
12+
13+
fetch(url)
14+
.catch((e) => console.error(e))
15+
.then((res) => {
16+
res
17+
.json()
18+
.catch((e) => console.error(e))
19+
.then((j) => {
20+
const tagName = j["tag_name"];
21+
const published = new Date(j["published_at"]);
22+
23+
let assets = Array.from(j["assets"]).filter((a) => {
24+
return [
25+
"libraries-Linux-Release",
26+
"libraries-Windows-Release",
27+
"resources",
28+
].some((v) => a.name.includes(v));
29+
});
30+
31+
const labels = [
32+
"Linux-only binaries: ",
33+
"Windows-only binaries: ",
34+
"Windows and Linux resources: ",
35+
];
36+
let i = 0;
37+
38+
let div = document.getElementById("downloading-ntre-div");
39+
if (!div) {
40+
console.error("div not found");
41+
return;
42+
}
43+
44+
let pInfo = document.createElement("p");
45+
pInfo.appendChild(document.createTextNode("Current release: " + tagName));
46+
pInfo.appendChild(document.createElement("br"));
47+
pInfo.appendChild(document.createTextNode("Published on: " + published.toISOString().split('T')[0]));
48+
div.appendChild(pInfo);
49+
50+
assets.forEach((asset) => {
51+
console.log(asset);
52+
53+
div.appendChild(document.createTextNode(labels[i]));
54+
i += 1;
55+
56+
let a = document.createElement("a");
57+
a.appendChild(document.createTextNode(asset.name));
58+
a.appendChild(document.createElement("br"));
59+
a.href = asset.browser_download_url;
60+
61+
div.appendChild(a);
62+
});
63+
});
64+
});
65+
}
66+
67+
window.onload = getDownloadLinks;

0 commit comments

Comments
 (0)