33

There are a lot of great options for generating API documentation for other languages, but I have yet to find a solution for my JavaScript API that I want to host on GitHub Pages. It seem that I can use JSDoc3 but I would need to create a custom plugin that outputs Jekyll markup.

I would also like the code URLs to link to GitHub itself. I found jsdoc-githubify that will munge the output to change the links, but I'd prefer a more straightforward option where I have more control.

Do I have to create my own JSDoc plugin, or is there a better solution out there that I've missed. What do folks use for this?

Andy Armstrong
  • 688
  • 6
  • 8
  • i looked around a bit, and i think scraping the output html is the simplest path forward. – dandavis Mar 04 '16 at 15:58
  • I eventually settled on using JSDox which generates very clean markdown, combined with https://github.com/shinnn/gulp-gh-pages. You can see how I implemented it here https://github.com/edx/edx-ui-toolkit/pull/60, and the end result here: http://ui-toolkit.edx.org. Thanks for all the suggestions. – Andy Armstrong May 02 '16 at 20:35

6 Answers6

26

If you're familiar with Grunt, you can easily generate .html docs with grunt-jsdoc.

  • Document your code with JSDoc.
  • Use grunt-jsdoc which internally uses jsdoc to generate code documentation.
  • This will also output the source code in HTML and within the documentation it will include links to code lines for each publicly accessible member.
  • You can also have control on the links by simply using the @link directive of JSDoc:
    See {@link https://github.com/onury|My GitHub Profile}.

See a Gruntfile example below.
Note that this supports all JSDoc CLI options.

grunt.initConfig({
    'jsdoc': {
        dist: {
            src: ['./src/core/mylib.js'],
            options: {
                destination: './doc/html'
            }
        }
    }
});

And you run this task with grunt jsdoc. Or you can add the grunt-contrib-watch plugin to auto-run each time the file changes.

Templates and Styling:

  • You can always play with the CSS file and overwrite it for your own taste.
  • Or you can use docstrap template for JSDoc3 based on Bootstrap which can be used with grunt-jsdoc.

Using Jekyll for documentation:

Although it's natively supported, you do not have to use Jekyll for GitHub Pages. Jekyll is actually designed for static websites or blogs. But it can take markdown files. So, I'd first create github flavoured markdown files from code via jsdoc-to-markdown (there is also a Grunt plugin grunt-jsdoc2md) then configure a Jekyll project accordingly.

But note that you'll need to do some extra work to install and configure Jekyll. Here is a good article and a sample project to start with.

UPDATE:

After answering this, I started working on a tool for building documentation easily. Now, it's mature enough to post here and see if you like it. It's called Docma.

Key Docma features are; it can both parse JSDoc and Markdown files into HTML documentation, generates a web-app, extremely configurable and works great with Github Pages.

See Docma documentation here, which is also built with Docma and hosted on GitHub Pages.

A sample screenshot of Docma generated SPA:

enter image description here

Onur Yıldırım
  • 32,327
  • 12
  • 84
  • 98
7

I think this is what you are looking for: http://jsdox.org/

jsdox is a simple jsdoc 3 generator. It pulls documentation tags based on a subset of jsdoc 3 from your javascript files and generates markdown files.

  • Thanks, Xavi. I looked at this briefly but it seems a little limited for my tastes. I was hoping to generate something that looks like the React documentation: https://facebook.github.io/react/docs/top-level-api.html . I'm not sure what tools they are using. – Andy Armstrong Mar 04 '16 at 20:41
  • Despite my previous comment, I eventually settled on using JSDox *because* the markdown generated was so clean that it was easy to skin. You can see how I implemented it here https://github.com/edx/edx-ui-toolkit/pull/60, and the end result here: http://ui-toolkit.edx.org/. Thanks Xavi! – Andy Armstrong May 02 '16 at 20:33
3

JSDox is exactly what you are looking for.

Charlie
  • 22,886
  • 11
  • 59
  • 90
1

Though I haven't updated it in a while, https://github.com/punkave/dox-foundation is another option. It will just generate HTML files that you could commit to your gh-pages branch.

mattmcmanus
  • 1,786
  • 2
  • 18
  • 27
1

I'm a fan of swagger: https://github.com/swagger-api/swagger-ui & http://swagger.io/.

It includes more than just API documentation so maybe it's overkill for you but it does a beautiful job of documenting APIs.

obi1
  • 314
  • 2
  • 6
1

trying to simplify it

  • In GitHub pages generating API documentation that outputs Jekyll markup.

    Escape liquid template with {% raw %} tag.

    {% raw %}
       I want to be {{escaped}}.
    {% endraw %}
    

    ref: github/.com/Shopify/liquid/wiki/Liquid-for-Designers#raw

    ref: jekyllrb/.com/docs/github-pages/#project-pages

    create two branch, one for master one for gh-pages, master branch contain your .md file and gh-pages contain static generated .html file. In local computer: $ jekyll build in current project folder will be generated into ./_site.

    upload to GitHub.

    jekyll

    • master branch: github/.com/jekyll/jekyll
    • gh-pages branch: github/.com/jekyll/jekyll/tree/gh-pages

    fb/react

    • master branch: github/.com/facebook/react/edit/master/docs/docs/ref-01-top-level-api.md
    • gh-pages branch: github/.com/facebook/react/blob/gh-pages/docs/top-level-api.html
  • Pages URLs link to GitHub document itself.

    In _layouts folder (html template) Add link "Edit on GitHub" on docs pages this is blog post about it

  • blinksmith
    • 556
    • 6
    • 7