After running a basic JSDoc compile/render from Node.js:
jsdoc file1.js file2.js
I get a well-formatted document using the default template
I had a similar but different problem with the Home Page. The small in-house JavaScript library that I wanted to generate JSDOC pages for was just a collection of global functions, and I didn't want to display the home page at all. I only want to display the global.html page.
Since we use NPM to install JSDOC, I didn't want to duplicate the entire module just to customize the global page. Instead, I copied just the layout page to a separate directory and specified that in my jsdoc.json config file:
"templates" : {
"default": {
"layoutFile": "config/layout.tmpl"
}
}
and then I edited layout.tmpl to add a <style> tag, with a style rule that does not display the link to the home.html page:
nav > h2 {
display: none;
}
Create markdown file README.md
Generating jsdoc:
$ jsdoc path/to/js path/to/readme/README.md
To read more about this visit official documentation
I don't think this is a proper way to do it but this works.
If you have jsdoc installed in your project find template file in your working directory, mine was:
./node_modules/jsdoc/templates/default/publish.js
Then search for 'Home' with search command and replace with your text, next step is to specify template when generating jsdoc:
$ jsdoc ./src/scripts/ ./README.md -t node_modules/jsdoc/templates/default/
'Home' is harcoded (passed as title
when generating the index) in the default template so there is no variable or config that you could set to modify this title.
If multiple people are generating/editing the docs, editing the node_modules
is an obvious no-go.
It's enough to create a layout.tmpl (or a full custom template, if you're using one), point JSDoc to it (CLI option or config file) and replace <?js= title ?>
with <?js= title==='Home' ? 'Your Title' : title ?>
.
I can't comment so I'll add a note here to clarify how to do all of the things in the original question without altering the default template, based on the directions in a file found in the "\npm\node_modules\jsdoc\templates" folder, which explains how to create your own templates. The steps to change the "Home" headings in the generated js documentation to project specific headings (e.g., "MyDescription") and include the overview blurb at the top of main page are outlined below.
jsdoc -c pathTo\conf.json
for the command line (see example in item 4 below). (As the link explains, you could make a file with any name or extension as long as it is in Markdown and you tell jsdoc where to find it).\npm\node_modules\jsdoc\templates\default
) to a new directory, renaming the new folder to something like myTemplate
.publish.js
inside the new myTemplate
folder and replace "Home" with "MyDescription". Two points to note here: the file name has to remain publish.js
, and "Home" appeared in two places in my original "publish.js", in the line var nav = '<h2><a href="index.html">Home</a></h2>';and the line starting
generate('Home',...
.Tell the jsdoc generator where to find your custom template (myTemplate
folder) and your overview file ("README.md"). You can add -t pathTo\myTemplate
to the command line, or you can use a very short command line, jsdoc -c pathTo\conf.json
if you create a file named conf.json
in a text editor, something like the file below, which specifies the source, destination, etc. for the documentation. That file puts the overview into the main page by telling the doc generator to use README.md
in the "source" section, and changes the headings from "Home" to the new heading, "MyDescription", using the new myTemplate
folder in the "opts" section.
{
"tags": {
"allowUnknownTags": true,
"dictionaries": ["jsdoc","closure"]
},
"opts": {
"template": "pathTo/myTemplate",
"destination": "pathTo/myJScriptDocs",
"recurse": true
},
"source": {
"includePattern": ".+\\.js(doc)?$",
"excludePattern": "(^|\\/|\\\\)_",
"include": ["pathTo/myJSSources", "pathTo/README.md"]
},
"plugins": [],
"templates": {
"cleverLinks": false,
"monospaceLinks": false
}
}
You can also add an @file
(or @fileOverview
) to one or more of your source files.
All of the files' overview sections will be included on the JSDoc home page. If you also feed your README to JSDoc, the file overviews will be placed after the Readme content.
Example:
/**
* @file index.js is the root file for the example.
* It kicks things off.
* @author Your name goes here
* @see <a href="https://developers.docusign.com">DocuSign Developer Center</a>
*/