Skip to content

Commit f43cf72

Browse files
committed
Fix JS error on other pages and use Standard formatting
1 parent 0fa76a9 commit f43cf72

File tree

3 files changed

+57
-25
lines changed

3 files changed

+57
-25
lines changed

README.md

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,44 @@
33
Welcome to the [Rust Forge]! Rust Forge serves as a repository of supplementary
44
documentation useful for members of [The Rust Programming Language].
55

6+
[the rust programming language]: https://rust-lang.org
7+
[rust forge]: https://forge.rust-lang.org
8+
69
# Building
10+
711
```
812
$ mdbook build
913
```
1014

1115
# Development
16+
1217
When developing it's recommended to use the `serve` command to launch a local
1318
server to allow you to easily see and update changes you make.
19+
1420
```
1521
$ mdbook serve
1622
```
1723

18-
[The Rust Programming Language]: https://rust-lang.org
19-
[Rust Forge]: https://forge.rust-lang.org
24+
## JavaScript
25+
26+
Forge uses JavaScript to display dates for releases and "no tools breakage
27+
week". When making modifications to the JavaScript make sure it matches the
28+
[standard] style. You can install `standard` and automatically format the code
29+
using the following commands.
30+
31+
[standard]: https://standardjs.com/index.html
2032

33+
### Install
34+
35+
```bash
36+
# With Yarn
37+
yarn global add standard
38+
# With NPM
39+
npm install --global standard
40+
```
41+
42+
### Formatting
43+
44+
```bash
45+
standard --fix js/
46+
```

js/index.js

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,32 @@
1-
// Rust 1.5.0 was released on 2015-12-10
2-
const epochDate = moment.utc("2015-12-10");
3-
const epochRelease = 5;
4-
const dateFormat = "MMMM Do YYYY";
1+
/* global moment */
52

6-
const newReleases = Math.floor(moment.utc().diff(epochDate, "weeks") / 6);
3+
// Rust 1.5.0 was released on 2015-12-10
4+
const EPOCH_DATE = moment.utc('2015-12-10')
5+
const EPOCH_RELEASE = 5
6+
const DATE_FORMAT = 'MMMM Do YYYY'
7+
const newReleases = Math.floor(moment.utc().diff(EPOCH_DATE, 'weeks') / 6)
78

8-
const addRelease = (kind, incr, tools_week) => {
9-
const releaseNumber = epochRelease + newReleases + incr;
10-
const displayVersion = `1.${releaseNumber}`
11-
const releaseDate = epochDate.clone().add((newReleases + incr) * 6, "weeks");
9+
function addRelease (kind, incr, toolsWeek) {
10+
const releaseNumber = EPOCH_RELEASE + newReleases + incr
11+
const displayVersion = `1.${releaseNumber}`
12+
const releaseDate = EPOCH_DATE.clone().add((newReleases + incr) * 6, 'weeks')
1213

13-
document.querySelector(`#${kind}-version`).textContent = displayVersion;
14-
document.querySelector(`#${kind}-release-date`).textContent = releaseDate.format(dateFormat);
14+
document.querySelector(`#${kind}-version`).textContent = displayVersion
15+
document.querySelector(`#${kind}-release-date`).textContent = `${releaseDate.format(DATE_FORMAT)} UTC`
1516

16-
if (tools_week === true) {
17-
const noBreakagesTo = releaseDate.clone().day(2);
18-
const noBreakagesFrom = noBreakagesTo.clone().subtract(6, 'day');
19-
const toDate = noBreakagesTo.format(dateFormat);
20-
const fromDate = noBreakagesFrom.format(dateFormat);
17+
if (toolsWeek) {
18+
const noBreakagesTo = releaseDate.clone().day(2)
19+
const noBreakagesFrom = noBreakagesTo.clone().subtract(6, 'days')
20+
const toDate = noBreakagesTo.format(DATE_FORMAT)
21+
const fromDate = noBreakagesFrom.format(DATE_FORMAT)
2122

22-
document.querySelector(`#${kind}-cycle`).textContent = displayVersion;
23-
document.querySelector(`#${kind}-timespan`).textContent = `${fromDate}${toDate}`;
24-
}
25-
};
23+
document.querySelector(`#${kind}-cycle`).textContent = displayVersion
24+
document.querySelector(`#${kind}-timespan`).textContent = `${fromDate}${toDate}`
25+
}
26+
}
2627

27-
addRelease("stable", 0, false);
28-
addRelease("beta", 1, true);
29-
addRelease("nightly", 2, true);
28+
if (document.querySelector('#current-release-versions')) {
29+
addRelease('stable', 0, false)
30+
addRelease('beta', 1, true)
31+
addRelease('nightly', 2, true)
32+
}

src/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ file an issue or PR on the [Rust Forge GitHub].
1010
<!-- All `<span id="..."></span>` elements are filled at run time when a reader
1111
visits the website. Please refer to `js/index.js` for how these values
1212
are generated.
13+
14+
Avoid changing the "Current Release Versions" without also updating the selector
15+
in `js/index.js.
1316
-->
1417

1518
### Current Release Versions

0 commit comments

Comments
 (0)