Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display LTS and Stable on the frontpage #260

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion build.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const filterStylusPartials = require('./scripts/plugins/filter-stylus-partials')
const mapHandlebarsPartials = require('./scripts/plugins/map-handlebars-partials')
const anchorMarkdownHeadings = require('./scripts/plugins/anchor-markdown-headings')
const loadVersions = require('./scripts/load-versions')
const latestVersion = require('./scripts/helpers/latestversion')

/** Build **/

Expand Down Expand Up @@ -181,8 +182,12 @@ function fullbuild () {
project: {
versions,
currentVersion: versions[0].version,
currentVersions: {
stable: latestVersion.stable(versions),
lts: latestVersion.lts(versions)
},
banner: {
visible: true,
visible: false,
content: '<a href="https://nodejs.org/en/blog/release/v4.2.1/">Long Term Support Release</a>'
}
}
Expand Down
16 changes: 12 additions & 4 deletions layouts/css/page-modules/_home.styl
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@
margin-top 1em

.home-secondary-links
$home-secondary-links-color = saturation($node-green, 20%)

color $home-secondary-links-color

a
$home-secondary-links-color = saturation($node-green, 20%)
font-size 1rem
color $home-secondary-links-color

Expand All @@ -27,13 +30,16 @@
padding-top 30px
text-align center

#home-downloadbutton
h2
margin-bottom 0

.home-downloadbutton
display inline-block
margin 10px 4px
padding 0.2em 0.6em

background-color $node-green
color #fff
color #fff !important
border-radius 2px
font-size 30px
font-weight 400
Expand All @@ -43,4 +49,6 @@
&:hover
background-color saturation($node-green, 80%)


small
display block
font-size 1rem
27 changes: 23 additions & 4 deletions layouts/index.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,32 @@
{{ labels.current-version }}: {{ project.currentVersion }}<br>
{{{ project.banner.content }}}
</p>
{{else}}
<p class="home-version">{{ labels.current-version }}: {{ project.currentVersion }}</p>
{{/if}}

<a href="https://nodejs.org/dist/{{ project.currentVersion }}/" id="home-downloadbutton" data-version="{{ project.currentVersion }}" data-dl-local="{{ labels.download-for }}">{{ labels.download }}</a>
<h2 id="home-downloadhead" data-dl-local="{{ labels.download-for }}">{{ labels.download }}</h2>

<a href="https://nodejs.org/dist/{{ project.currentVersions.lts }}/" class="home-downloadbutton" title="{{ labels.download }} {{ project.currentVersions.lts }} {{ labels.lts }}" data-version="{{ project.currentVersions.lts }}">
{{ project.currentVersions.lts }} {{ labels.lts }}
<small>{{ labels.tagline-lts }}</small>
</a>

{{#if project.currentVersions.stable}}
<a href="https://nodejs.org/dist/{{ project.currentVersions.stable }}/" class="home-downloadbutton" title="{{ labels.download }} {{ project.currentVersions.stable }} {{ labels.stable }}" data-version="{{ project.currentVersions.stable }}">
{{ project.currentVersions.stable }} {{ labels.stable }}
<small>{{ labels.tagline-stable }}</small>
</a>
{{/if}}

<ul class="list-divider-pipe home-secondary-links">
<li><a href="https://nodejs.org/dist/{{ project.currentVersion }}/">{{ labels.other-downloads }}</a></li>
<li>
<a href="https://nodejs.org/dist/{{ project.currentVersions.lts }}/">{{ labels.other-lts-downloads }}</a>

{{#if project.currentVersions.stable}}
&#47; <a href="https://nodejs.org/dist/{{ project.currentVersions.stable }}/" title="{{ labels.other-stable-downloads }}">
{{ labels.stable }}
</a>
{{/if}}
</li>
<li><a href="https://github.com/nodejs/node/blob/{{ project.currentVersion }}/CHANGELOG.md">{{ labels.changelog }}</a></li>
<li><a href="{{ site.docs.api.link }}">{{ labels.api }}</a></li>
</ul>
Expand Down Expand Up @@ -73,5 +91,6 @@

{{> footer }}
<script src="/static/js/download.js" async defer></script>

</body>
</html>
6 changes: 6 additions & 0 deletions locale/en/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ labels:
download: Download
download-for: Download for
other-downloads: Other Downloads
other-lts-downloads: Other LTS Downloads
other-stable-downloads: Other Stable Downloads
stable: Stable
lts: LTS
tagline-stable: Latest Features
tagline-lts: Mature and Dependable
changelog: Changelog
api: API Docs
---
Expand Down
10 changes: 10 additions & 0 deletions scripts/helpers/latestversion.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
'use strict'

const semver = require('semver')

exports.stable = (releases) => {
const match = releases.find((release) => !release.lts && semver.gte(release.version, '5.0.0'))
return match && match.version
}

exports.lts = (releases) => releases.find((release) => release.lts).version
78 changes: 60 additions & 18 deletions static/js/download.js
Original file line number Diff line number Diff line change
@@ -1,38 +1,80 @@
;
(function (d, n) {
'use strict';
var os = n.platform.match(/(Win|Mac|Linux)/);
var x = n.userAgent.match(/x86_64|Win64|WOW64/) ||

// document.querySelectorAll polyfill for ancient IEs
// https://gist.github.com/chrisjlee/8960575
if (!document.querySelectorAll) {
document.querySelectorAll = function (selectors) {
var style = document.createElement('style'), elements = [], element;
document.documentElement.firstChild.appendChild(style);
document._qsa = [];

style.styleSheet.cssText = selectors + '{x-qsa:expression(document._qsa && document._qsa.push(this))}';
window.scrollBy(0, 0);
style.parentNode.removeChild(style);

while (document._qsa.length) {
element = document._qsa.shift();
element.style.removeAttribute('x-qsa');
elements.push(element);
}
document._qsa = null;
return elements;
};
}

var osMatch = n.platform.match(/(Win|Mac|Linux)/);
var os = (osMatch && osMatch[1]) || '';
var arch = n.userAgent.match(/x86_64|Win64|WOW64/) ||
n.cpuClass === 'x64' ? 'x64' : 'x86';
var text = 'textContent' in d ? 'textContent' : 'innerText';
var db = d.getElementById('home-downloadbutton');
var version;
if (db) {
version = db.getAttribute('data-version');
var dlLocal = db.getAttribute('data-dl-local');
switch (os && os[1]) {
var buttons = d.querySelectorAll('.home-downloadbutton');
var downloadHead = d.getElementById('home-downloadhead');
var dlLocal;

function versionIntoHref(nodeList, filename) {
var linkEls = Array.prototype.slice.call(nodeList);
var version;
var el;

for (var i = 0; i < linkEls.length; i++) {
version = linkEls[i].getAttribute('data-version');
el = linkEls[i]

// Windows 64-bit files for 0.x.x need to be prefixed with 'x64/'
if (os === 'Win' && (version[1] === '0' && arch === 'x64')) {
el.href += arch + '/';
}

el.href += filename.replace('%version%', version);
}
}

if (downloadHead && buttons) {
dlLocal = downloadHead.getAttribute('data-dl-local');
switch (os) {
case 'Mac':
db.href += 'node-' + version + '.pkg';
db[text] = dlLocal + ' OS X (x64)';
versionIntoHref(buttons, 'node-%version%.pkg');
downloadHead[text] = dlLocal + ' OS X (x64)';
break;
case 'Win':
// Windows 64-bit files for 0.x.x need to be prefixed with 'x64/'
db.href += (version[1] == '0' && x == 'x64' ? x + '/' : '') + 'node-' + version + '-' + x + '.msi';
db[text] = dlLocal + ' Windows (' + x +')';
versionIntoHref(buttons, 'node-%version%-' + arch + '.msi');
downloadHead[text] = dlLocal + ' Windows (' + arch +')';
break;
case 'Linux':
db.href += 'node-' + version + '-linux-' + x + '.tar.gz';
db[text] = dlLocal + ' Linux (' + x + ')';
versionIntoHref(buttons, 'node-%version%-linux-' + arch + '.tar.gz');
downloadHead[text] = dlLocal + ' Linux (' + arch + ')';
break;
}
}

// Windows button on download page
var winButton = d.getElementById('windows-downloadbutton');
if (winButton && os && os[1] === 'Win') {
if (winButton && os === 'Win') {
var winText = winButton.getElementsByTagName('p')[0];
version = winButton.getAttribute('data-version');
winButton.href = winButton.href.replace(/x(86|64)/, x);
winText[text] = winText[text].replace(/x(86|64)/, x);
winButton.href = winButton.href.replace(/x(86|64)/, arch);
winText[text] = winText[text].replace(/x(86|64)/, arch);
}
})(document, navigator);