Skip to content

Commit

Permalink
Fix JS post last change.
Browse files Browse the repository at this point in the history
  • Loading branch information
hjoliver committed Apr 17, 2024
1 parent 7bf2442 commit 26f3474
Showing 1 changed file with 4 additions and 93 deletions.
97 changes: 4 additions & 93 deletions _layouts/default.html
Original file line number Diff line number Diff line change
Expand Up @@ -314,8 +314,8 @@ <h3 id="publications">Publications and Reports</h3>
href="https://doi.org/10.1109/MCSE.2019.2906593"
>

<svg xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink" width="208"
<svg xmlns="https://www.w3.org/2000/svg"
xmlns:xlink="https://www.w3.org/1999/xlink" width="208"
height="20" role="img" aria-label="DOI:
10.1109/MCSE.2019.2906593">
<title>DOI: 10.1109/MCSE.2019.2906593</title>
Expand Down Expand Up @@ -362,7 +362,7 @@ <h3 id="publications">Publications and Reports</h3>
href="https://doi.org/10.21105/joss.00737"
>
<img
src="http://joss.theoj.org/papers/10.21105/joss.00737/status.svg"
src="https://joss.theoj.org/papers/10.21105/joss.00737/status.svg"
style="width:auto" />
</a>
<br />
Expand Down Expand Up @@ -599,94 +599,6 @@ <h3 id="publications">Publications and Reports</h3>
}
}

// --- Releases

/**
* Populate HTML elements with information about the latest release.
*
* @param cylcx {string} - 'cylc8' or 'cylc7'
* @param name {string} - name of the release
* @param link {string} - URL of the release
* @param publishedAt {string} - raw text date as returned from the API
*/
function populateLatestReleaseInformation(cylcx, name, link, publishedAt) {
const latestReleaseName = document.getElementById(cylcx + "-latest-release-name");
latestReleaseName.innerHTML = name;

const latestReleaseURL = document.getElementById(cylcx + "-button");
latestReleaseURL.href = link;

const latestReleaseDateText = document.getElementById(cylcx + "-latest-release-pubdate-text");
latestReleaseDateText.innerHTML = `Released: ${publishedAt}`;
}

/**
* @param release {{
* name: String,
* published_at: String,
* tag_name: String
* }}
* @return {string} - Release date formatted as M/D/Y (e.g. 5/14/2020).
*/
function getReleaseDate (release) {
return new Date(release.published_at).toLocaleString().split(',')[0]
}

/**
* @param {[
* {
* name: String,
* published_at: String,
* tag_name: String
* }
* ]} releases - The list of releases.
*/
function showReleases(releases) {
// show latest Cylc 7 release
const latestCylc7 = releases
.filter(release => release.name.startsWith("cylc-7.9"))
.sort((left, right) => new Date(left.published_at) - new Date(right.published_at))
.pop()
if (latestCylc7) {
populateLatestReleaseInformation(
"cylc7",
latestCylc7.name,
`${TAGS_URL}${latestCylc7.tag_name}`,
getReleaseDate(latestCylc7))
}

// show latest Cylc 8 release
const latestCylc8 = releases
.filter(release => release.name.startsWith("cylc-flow-8"))
.sort((left, right) => new Date(left.published_at) - new Date(right.published_at))
.pop()
if (latestCylc8) {
populateLatestReleaseInformation(
"cylc8",
latestCylc8.name,
`${TAGS_URL}${latestCylc8.tag_name}`,
getReleaseDate(latestCylc8))
}
}

/**
* Retrieve the releases of the project.
* @return {Promise} A Promise object that populates and creates DOM elements, or returns the status text on error.
*/
function retrieveReleases() {
const releases = CACHE.get('releases');
if (releases !== null) {
return new Promise(function () {
showReleases(releases);
})
} else {
return doGet(RELEASES_URL).then(function (releases) {
CACHE.put('releases', releases);
showReleases(releases);
})
}
}

// --- window.onload

/**
Expand All @@ -696,8 +608,7 @@ <h3 id="publications">Publications and Reports</h3>
*/
window.onload = function () {
Promise.all([
retrieveProgress(),
retrieveReleases()
retrieveProgress()
])
.catch(function(error) {
// Any error propagated here will be logged to the browser console
Expand Down

0 comments on commit 26f3474

Please sign in to comment.