As an example, this documentation has been made self-instantiatable using Components.js. This makes it possible to view the HTML-version of any page to the console, or serve it via HTTP on a local webserver.
The necessary files for this instantiation are available on the GitHub repository of this documentation.
Installation
In order to install the example, start by cloning the GitHub repository:
$ git clone git@github.com:LinkedSoftwareDependencies/Documentation-Components.js.git
After that, navigate to the repo directory and install its dependencies:
$ cd Documentation-Components.js
$ npm install
Example contents
This example contains the following elements:
- A
components/components.jsonld
containing the modulenpmd:documentation-components
and links to the separate component files:components/Page.jsonld
: An abstract page component.components/MarkdownPage.jsonld
: A page that refers to a markdown file and is rendered as HTML.components/PageLogger.jsonld
: Logs a page to the console.components/PageServer.jsonld
: Serves a page using HTTP.
- JavaScript implementations of the components:
- A JSON-LD context file
components/context.jsonld
. config/log_page
andconfig/serve_page
component configurations.- The
package.json
file contains links to the module id, the components file and the context file. - A simple script
bin/serve.js
that uses Components.js to run the given config file with a fixed config URIurn:components:documentation
. For this example, all config files share this URI as@id
.
Print a page to the console
Run node bin/serve.js config/log_page.jsonld
.
Note
Instead of running the example with a local path,
it can also refer to an URL of a config, such as the URL of this config file on GitHub:
node bin/serve.js https://raw.githubusercontent.com/LinkedSoftwareDependencies/Documentation-Components.js/master/config/serve_page.jsonld
The configuration config/log_page.jsonld
contains an instantiation of PageLogger
that will log a certain page to the console.
This logger is invoked with a MarkdownPage
as logPage
parameter.
This page has a path to a certain Markdown page, which at the moment refers to docs/index.md
, which is the index page of the documentation.
This value can be any changed to refer to any other page from the documentation.
Serving a page using HTTP
Run node bin/serve.js config/serve_page.jsonld
.
The configuration config/serve_page.jsonld
contains an instantiation of PageServer
that will serve a certain page via HTTP.
This logger is invoked with a MarkdownPage
as servePage
parameter
and uses 8080
as default servePort
.