Browse Source

doc: add links to alternative versions of doc

Each page of the API documentation should have links to other versions
of the same page. This will make it easier to switch between the current
"live" release at nodejs.org and LTS versions.

PR-URL: https://github.com/nodejs/node/pull/10958
Fixes: https://github.com/nodejs/node/issues/10726
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Evan Lucas <evanlucas@me.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
canary-base
Chris Young 8 years ago
committed by Tobias Nießen
parent
commit
cacce304cb
  1. 2
      doc/api/addons.md
  2. 2
      doc/api/assert.md
  3. 2
      doc/api/buffer.md
  4. 2
      doc/api/child_process.md
  5. 1
      doc/api/cli.md
  6. 2
      doc/api/cluster.md
  7. 2
      doc/api/console.md
  8. 2
      doc/api/crypto.md
  9. 2
      doc/api/debugger.md
  10. 2
      doc/api/dgram.md
  11. 2
      doc/api/dns.md
  12. 1
      doc/api/documentation.md
  13. 2
      doc/api/domain.md
  14. 1
      doc/api/errors.md
  15. 2
      doc/api/events.md
  16. 2
      doc/api/fs.md
  17. 1
      doc/api/globals.md
  18. 2
      doc/api/http.md
  19. 2
      doc/api/https.md
  20. 2
      doc/api/modules.md
  21. 2
      doc/api/net.md
  22. 2
      doc/api/os.md
  23. 2
      doc/api/path.md
  24. 1
      doc/api/process.md
  25. 2
      doc/api/punycode.md
  26. 2
      doc/api/querystring.md
  27. 2
      doc/api/readline.md
  28. 2
      doc/api/repl.md
  29. 2
      doc/api/stream.md
  30. 2
      doc/api/string_decoder.md
  31. 1
      doc/api/synopsis.md
  32. 2
      doc/api/timers.md
  33. 2
      doc/api/tls.md
  34. 2
      doc/api/tty.md
  35. 2
      doc/api/url.md
  36. 2
      doc/api/util.md
  37. 2
      doc/api/v8.md
  38. 2
      doc/api/vm.md
  39. 2
      doc/api/zlib.md
  40. 58
      doc/api_assets/style.css
  41. 16
      doc/template.html
  42. 53
      tools/doc/html.js

2
doc/api/addons.md

@ -1,5 +1,7 @@
# C++ Addons
<!--introduced_in=v0.10.0-->
Node.js Addons are dynamically-linked shared objects, written in C++, that
can be loaded into Node.js using the [`require()`][require] function, and used
just as if they were an ordinary Node.js module. They are used primarily to

2
doc/api/assert.md

@ -1,5 +1,7 @@
# Assert
<!--introduced_in=v0.10.0-->
> Stability: 2 - Stable
The `assert` module provides a simple set of assertion tests that can be used to

2
doc/api/buffer.md

@ -1,5 +1,7 @@
# Buffer
<!--introduced_in=v0.10.0-->
> Stability: 2 - Stable
Prior to the introduction of [`TypedArray`] in ECMAScript 2015 (ES6), the

2
doc/api/child_process.md

@ -1,5 +1,7 @@
# Child Process
<!--introduced_in=v0.10.0-->
> Stability: 2 - Stable
The `child_process` module provides the ability to spawn child processes in

1
doc/api/cli.md

@ -1,5 +1,6 @@
# Command Line Options
<!--introduced_in=v5.9.1-->
<!--type=misc-->
Node.js comes with a variety of CLI options. These options expose built-in

2
doc/api/cluster.md

@ -1,5 +1,7 @@
# Cluster
<!--introduced_in=v0.10.0-->
> Stability: 2 - Stable
A single instance of Node.js runs in a single thread. To take advantage of

2
doc/api/console.md

@ -1,5 +1,7 @@
# Console
<!--introduced_in=v0.10.13-->
> Stability: 2 - Stable
The `console` module provides a simple debugging console that is similar to the

2
doc/api/crypto.md

@ -1,5 +1,7 @@
# Crypto
<!--introduced_in=v0.3.6-->
> Stability: 2 - Stable
The `crypto` module provides cryptographic functionality that includes a set of

2
doc/api/debugger.md

@ -1,5 +1,7 @@
# Debugger
<!--introduced_in=v0.9.12-->
> Stability: 2 - Stable
<!-- type=misc -->

2
doc/api/dgram.md

@ -1,5 +1,7 @@
# UDP / Datagram Sockets
<!--introduced_in=v0.10.0-->
> Stability: 2 - Stable
<!-- name=dgram -->

2
doc/api/dns.md

@ -1,5 +1,7 @@
# DNS
<!--introduced_in=v0.10.0-->
> Stability: 2 - Stable
The `dns` module contains functions belonging to two different categories:

1
doc/api/documentation.md

@ -1,5 +1,6 @@
# About this Documentation
<!--introduced_in=v0.10.0-->
<!-- type=misc -->
The goal of this documentation is to comprehensively explain the Node.js

2
doc/api/domain.md

@ -7,6 +7,8 @@ changes:
the first promise of a chain was created.
-->
<!--introduced_in=v0.10.0-->
> Stability: 0 - Deprecated
**This module is pending deprecation**. Once a replacement API has been

1
doc/api/errors.md

@ -1,5 +1,6 @@
# Errors
<!--introduced_in=v4.0.0-->
<!--type=misc-->
Applications running in Node.js will generally experience four categories of

2
doc/api/events.md

@ -1,5 +1,7 @@
# Events
<!--introduced_in=v0.10.0-->
> Stability: 2 - Stable
<!--type=module-->

2
doc/api/fs.md

@ -1,5 +1,7 @@
# File System
<!--introduced_in=v0.10.0-->
> Stability: 2 - Stable
<!--name=fs-->

1
doc/api/globals.md

@ -1,5 +1,6 @@
# Global Objects
<!--introduced_in=v0.10.0-->
<!-- type=misc -->
These objects are available in all modules. The following variables may appear

2
doc/api/http.md

@ -1,5 +1,7 @@
# HTTP
<!--introduced_in=v0.10.0-->
> Stability: 2 - Stable
To use the HTTP server and client one must `require('http')`.

2
doc/api/https.md

@ -1,5 +1,7 @@
# HTTPS
<!--introduced_in=v0.10.0-->
> Stability: 2 - Stable
HTTPS is the HTTP protocol over TLS/SSL. In Node.js this is implemented as a

2
doc/api/modules.md

@ -1,5 +1,7 @@
# Modules
<!--introduced_in=v0.10.0-->
> Stability: 2 - Stable
<!--name=module-->

2
doc/api/net.md

@ -1,5 +1,7 @@
# Net
<!--introduced_in=v0.10.0-->
> Stability: 2 - Stable
The `net` module provides an asynchronous network API for creating stream-based

2
doc/api/os.md

@ -1,5 +1,7 @@
# OS
<!--introduced_in=v0.10.0-->
> Stability: 2 - Stable
The `os` module provides a number of operating system-related utility methods.

2
doc/api/path.md

@ -1,5 +1,7 @@
# Path
<!--introduced_in=v0.10.0-->
> Stability: 2 - Stable
The `path` module provides utilities for working with file and directory paths.

1
doc/api/process.md

@ -1,5 +1,6 @@
# Process
<!-- introduced_in=v0.10.0 -->
<!-- type=global -->
The `process` object is a `global` that provides information about, and control

2
doc/api/punycode.md

@ -6,6 +6,8 @@ changes:
description: Accessing this module will now emit a deprecation warning.
-->
<!--introduced_in=v0.10.0-->
> Stability: 0 - Deprecated
**The version of the punycode module bundled in Node.js is being deprecated**.

2
doc/api/querystring.md

@ -1,5 +1,7 @@
# Query String
<!--introduced_in=v0.10.0-->
> Stability: 2 - Stable
<!--name=querystring-->

2
doc/api/readline.md

@ -1,5 +1,7 @@
# Readline
<!--introduced_in=v0.10.0-->
> Stability: 2 - Stable
The `readline` module provides an interface for reading data from a [Readable][]

2
doc/api/repl.md

@ -1,5 +1,7 @@
# REPL
<!--introduced_in=v0.10.0-->
> Stability: 2 - Stable
The `repl` module provides a Read-Eval-Print-Loop (REPL) implementation that

2
doc/api/stream.md

@ -1,5 +1,7 @@
# Stream
<!--introduced_in=v0.10.0-->
> Stability: 2 - Stable
A stream is an abstract interface for working with streaming data in Node.js.

2
doc/api/string_decoder.md

@ -1,5 +1,7 @@
# String Decoder
<!--introduced_in=v0.10.0-->
> Stability: 2 - Stable
The `string_decoder` module provides an API for decoding `Buffer` objects into

1
doc/api/synopsis.md

@ -1,5 +1,6 @@
# Usage
<!--introduced_in=v0.10.0-->
<!--type=misc-->
`node [options] [v8 options] [script.js | -e "script" | - ] [arguments]`

2
doc/api/timers.md

@ -1,5 +1,7 @@
# Timers
<!--introduced_in=v0.10.0-->
> Stability: 2 - Stable
The `timer` module exposes a global API for scheduling functions to

2
doc/api/tls.md

@ -1,5 +1,7 @@
# TLS (SSL)
<!--introduced_in=v0.10.0-->
> Stability: 2 - Stable
The `tls` module provides an implementation of the Transport Layer Security

2
doc/api/tty.md

@ -1,5 +1,7 @@
# TTY
<!--introduced_in=v0.10.0-->
> Stability: 2 - Stable
The `tty` module provides the `tty.ReadStream` and `tty.WriteStream` classes.

2
doc/api/url.md

@ -1,5 +1,7 @@
# URL
<!--introduced_in=v0.10.0-->
> Stability: 2 - Stable
The `url` module provides utilities for URL resolution and parsing. It can be

2
doc/api/util.md

@ -1,5 +1,7 @@
# Util
<!--introduced_in=v0.10.0-->
> Stability: 2 - Stable
The `util` module is primarily designed to support the needs of Node.js' own

2
doc/api/v8.md

@ -1,5 +1,7 @@
# V8
<!--introduced_in=v4.0.0-->
The `v8` module exposes APIs that are specific to the version of [V8][]
built into the Node.js binary. It can be accessed using:

2
doc/api/vm.md

@ -1,5 +1,7 @@
# VM (Executing JavaScript)
<!--introduced_in=v0.10.0-->
> Stability: 2 - Stable
<!--name=vm-->

2
doc/api/zlib.md

@ -1,5 +1,7 @@
# Zlib
<!--introduced_in=v0.10.0-->
> Stability: 2 - Stable
The `zlib` module provides compression functionality implemented using Gzip and

58
doc/api_assets/style.css

@ -81,6 +81,61 @@ em code {
#gtoc {
font-size: .8em;
margin-bottom: 1em;
}
#gtoc ul {
list-style: none;
margin-left: 0;
}
#gtoc li {
display: inline;
}
li.version-picker {
position: relative;
}
li.version-picker:hover > ol {
display: block;
}
li.version-picker a span {
font-size: .7em;
}
ol.version-picker {
background: #fff;
border: 1px #43853d solid;
border-radius: 2px;
display: none;
list-style: none;
position: absolute;
right: -2px;
width: 101%;
}
#gtoc ol.version-picker li {
display: block;
}
ol.version-picker li a {
border-radius: 0;
display: block;
margin: 0;
padding: .1em;
padding-left: 1em;
}
ol.version-picker li:first-child a {
border-top-right-radius: 1px;
border-top-left-radius: 1px;
}
ol.version-picker li:last-child a {
border-bottom-right-radius: 1px;
border-bottom-left-radius: 1px;
}
.line {
@ -507,6 +562,9 @@ th > *:last-child, td > *:last-child {
#content {
font-size: 3.5em;
}
#gtoc {
font-size: 0.6em;
}
}
@media print {

16
doc/template.html

@ -23,11 +23,21 @@
<header>
<h1>Node.js __VERSION__ Documentation</h1>
<div id="gtoc">
<p>
<ul>
<li>
<a href="index.html" name="toc">Index</a> |
</li>
<li>
<a href="all.html">View on single page</a> |
<a href="__FILENAME__.json">View as JSON</a>
</p>
</li>
<li>
<a href="__FILENAME__.json">View as JSON</a> |
</li>
<li class="version-picker">
<a href="#">View another version <span>&#x25bc;</span></a>
__ALTDOCS__
</li>
</ul>
</div>
<hr>
</header>

53
tools/doc/html.js

@ -31,6 +31,7 @@ const typeParser = require('./type-parser.js');
module.exports = toHTML;
const STABILITY_TEXT_REG_EXP = /(.*:)\s*(\d)([\s\S]*)/;
const DOC_CREATED_REG_EXP = /<!--\s*introduced_in\s*=\s*v([0-9]+)\.([0-9]+)\.([0-9]+)\s*-->/;
// customized heading without id attribute
const renderer = new marked.Renderer();
@ -52,13 +53,17 @@ const gtocPath = path.resolve(path.join(
));
var gtocLoading = null;
var gtocData = null;
var docCreated = null;
var nodeVersion = null;
/**
* opts: input, filename, template, nodeVersion.
*/
function toHTML(opts, cb) {
const template = opts.template;
const nodeVersion = opts.nodeVersion || process.version;
nodeVersion = opts.nodeVersion || process.version;
docCreated = opts.input.match(DOC_CREATED_REG_EXP);
if (gtocData) {
return onGtocLoaded();
@ -157,6 +162,8 @@ function render(opts, cb) {
);
}
template = template.replace(/__ALTDOCS__/, altDocs(filename));
// content has to be the last thing we do with
// the lexed tokens, because it's destructive.
const content = marked.parser(lexed);
@ -188,6 +195,50 @@ function replaceInText(text) {
return linkJsTypeDocs(linkManPages(text));
}
function altDocs(filename) {
let html = '';
if (!docCreated) {
console.error(`Failed to add alternative version links to ${filename}`);
return html;
}
function lte(v) {
const ns = v.num.split('.');
if (docCreated[1] > +ns[0])
return false;
if (docCreated[1] < +ns[0])
return true;
return docCreated[2] <= +ns[1];
}
const versions = [
{ num: '8.x' },
{ num: '7.x' },
{ num: '6.x', lts: true },
{ num: '5.x' },
{ num: '4.x', lts: true },
{ num: '0.12.x' },
{ num: '0.10.x' }
];
const host = 'https://nodejs.org';
const href = (v) => `${host}/docs/latest-v${v.num}/api/${filename}.html`;
function li(v, i) {
let html = `<li><a href="${href(v)}">${v.num}`;
if (v.lts)
html += ' <b>LTS</b>';
return html + '</a></li>';
}
const lis = (vs) => vs.filter(lte).map(li).join('\n');
return `<ol class="version-picker">${lis(versions)}</ol>`;
}
// handle general body-text replacements
// for example, link man page references to the actual page
function parseText(lexed) {

Loading…
Cancel
Save