npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@forsakringskassan/docs-generator

v2.15.0

Published

Documentation generator

Downloads

6,963

Readme

@forsakringskassan/docs-generator

npm install --save-dev --save-exact @forsakringskassan/docs-generator

Setup

Watch (development mode)

You can start a development server with watch for incremental builds using .serve().

import {
    Generator,
    livereloadProcessor,
} from "@forsakringskassan/docs-generator";

const docs = new Generator({
    site: {
        name: "My Awesome Site",
    },
    setupPath: "docs/src/setup.ts",
    processors: [livereloadProcessor({ enabled: true })],
});

docs.build([
    /* ... */
]);

docs.serve();

Vendor alias

Vendor alias is optional, it lets you substitute one package for another when bundling. The example below substitutes the package vue with the package vue/dist/esm.bundle.js. When an alias is given the package can be imported using the given alias as well as the original package name. For instance, when using the following configuration "vue" can be imported and resolved as "vue/dist/esm.bundle.js".

import {
    Generator,
    livereloadProcessor,
} from "@forsakringskassan/docs-generator";

const docs = new Generator({
    site: {
        name: "My Awesome Site",
    },
    setupPath: "docs/src/setup.ts",

    vendor: [
        {
            package: "vue",
            expose: "named",
            subpaths: [],
            alias: "vue/dist/esm.bundle.js",
        },
    ],
});

Usage

Using with Vue 2

Vue 2 requires an additional dependency to be installed:

npm install --save-dev --save-exact @vue/component-compiler

Create the setup callback in docs/src/setup.ts:

import Vue from "vue";
import { type SetupOptions } from "@forsakringskassan/docs-generator";

/* optionally add global plugins or configuration */
//Vue.use(MyAwesomePlugin);

export function setup(options: SetupOptions): void {
    const { rootComponent, selector } = options;
    const vm = new Vue(rootComponent);
    vm.$mount(selector);
}

Using with Vue 3

Create the setup callback in docs/src/setup.ts:

import { createApp } from "vue";
import { type SetupOptions } from "@forsakringskassan/docs-generator";

export function setup(options: SetupOptions): void {
    const { rootComponent, selector } = options;
    const app = createApp(rootComponent);

    /* optionally add global plugins or configuration */
    //app.use(MyAwesomePlugin);

    app.mount(selector);
}

Styling

Three CSS files are provided:

  • @forsakringskassan/docs-generator/style/index.css (aliased as @forsakringskassan/docs-generator/style)
  • @forsakringskassan/docs-generator/style/core.css
  • @forsakringskassan/docs-generator/style/site.css

core contains the necessary styling for components and elements and site contains the layout, typography etc required for a documentation site to work. index is a combination of the two and should be used in most cases.

Style can be compiled with compileStyle(name, src, [options]):

import { Generator } from "@forsakringskassan/docs-generator";

const docs = new Generator({
    site: {
        name: "My Awesome Site",
    },
    setupPath: "docs/src/setup.ts",
});

docs.compileStyle("docs", "./docs/src/style.scss", {
    appendTo: "head",
});

Where docs/src/style.scss contains:

@use "~@forsakringskassan/docs-generator/style";

Markdown

Links {@link ...}

To create link to a different document use {@link ID [TITLE]}, e.g.:

See {@link MyAwesomeComponent} for details or the {@link getting-started getting started guide}.

will be rendered as:

See
<a href="./components/my-awesome-component.html"
    >MyAwesomeComponent<a>
        for details or the
        <a href="../guides/getting-started.html">getting started guide</a>.</a
    ></a
>

The ID can be either the document identifier, name or one of the aliases. The link destination will always be relative to the current document.

Code fence

For configured languages (default html and vue) code fences are run as a live example in the browser with an option to display the source code. The following tags can be used:

  • borderless - removes the border from the example.
  • fullscreen - enable support for viewing the example in fullscreen.
  • static - force code to be rendered without live preview (only syntax highlight).
  • live-example - mark example as containing the LiveExample component.
  • nomarkup - for live examples this hides the syntax highlighted code and only displays the result of the running code.
  • test-id=STRING - Sets the data-test attribute.

static and live are used to manually set whenever the code should be run as a live example or not.

```html static
<p>This is displayed as syntax highlighted code only</p>
```
```js live
alert("This is run in the browser");
```

Examples can be imported using the import directive:

```import
MyAwesomeFile.vue
```

This will search for MyAwesomeFile.vue in the configured exampleFolders. HTML-comments may be placed before or after the filename.

To import an example that uses the LiveExample component you also need to use the live-example tag.

```import live-example
MyAwesomeLiveExampleFile.vue
```

Frontmatter

status

Set a status badge for a component.

The following statuses are recognized:

  • Produktionsklar
  • Deprekerad
  • Experimentell
  • Preliminär
  • Draft (deprecated alias for Preliminär)
  • Beta (deprecated alias for Preliminär)

title

Document title used for <title> and <nav>

short-title

Document title used when a shorter title is needed, e.g. site navigation.

visible

Set to false to hide document from navigation menu. Default true.

include

Set to false to not write the document to file or include as a page. Default true.

Inline tags

{@@link ...}

Implicit title:

Use the {@@link MyAwesomeComponent} component.

Explicit title:

Use the {@@link MyAwesomeComponent awesome component}.

{@@optional}

Creates a tag (badge) to mark something as optional.

Input:

{@@optional}

Output:

{@optional}

Templating

The Nunjucks templating engine is used for rendering documents to HTML. See templating documentation for help.

These custom filters and tags are available:

container

{% container "awesome-name" %}

Creates a container which processors may inject content into.

Environment variables

DOCS_ICON_LIB

Preferred icon library package name. Defaults to @fkui/icon-lib-default. Makes it possible to dynamically load icons and get access to icon metadata. The library must have been built using @fkui/icon-lib-builder.

const icons = await import(process.env.DOCS_ICON_LIB);

for (const entry of Object.values(icons)) {
    entry.injectSpritesheet();
}

Processors

Matomo

 const docs = new Generator({
     processors: [
+        matomoProcessor({
+            siteId: "1",
+            apiUrl: "https://matomo.example.net/",
+            trackerUrl: "https://matomo.example.net/",
+        }),
     ],
 });

Optionally set hostname to limit which hostnames can run Matomo analytics:

 const docs = new Generator({
     processors: [
         matomoProcessor({
             siteId: "1",
             apiUrl: "https://matomo.example.net/",
             trackerUrl: "https://matomo.example.net/",
+            hostname: "docs.example.net",
         }),
     ],
 });

Only the domain must be specified, e.g it should not include https:// or a path /path/to/docs. Multiple hostnames can be specified as an array.