mirror of
https://github.com/jsdoc/jsdoc.git
synced 2025-12-08 19:46:11 +00:00
fix several tutorial-related issues (#222)
- Tutorial code allowed JSON files to have a .js extension, then tried to parse all .js files as JSON. The code now only looks for JSON files with a .json extension. This allows .js files and tutorials to live in the same directory. - Recent changes caused tutorials to be generated with the wrong filename. This is now fixed.
This commit is contained in:
parent
ef6d78f88e
commit
dc75f6328b
@ -14,7 +14,7 @@ var tutorial = require('jsdoc/tutorial'),
|
||||
hasOwnProp = Object.prototype.hasOwnProperty,
|
||||
conf = {},
|
||||
tutorials = {},
|
||||
finder = /^(.*)\.(x(?:ht)?ml|html?|md|markdown|js(?:on)?)$/i;
|
||||
finder = /^(.*)\.(x(?:ht)?ml|html?|md|markdown|json)$/i;
|
||||
|
||||
/** Adds new tutorial.
|
||||
@param {tutorial.Tutorial} current - New tutorial.
|
||||
@ -75,7 +75,6 @@ exports.load = function(_path) {
|
||||
break;
|
||||
|
||||
// configuration file
|
||||
case 'js':
|
||||
case 'json':
|
||||
conf[name] = JSON.parse(content);
|
||||
// don't add this as a tutorial
|
||||
@ -100,9 +99,7 @@ exports.resolve = function() {
|
||||
current;
|
||||
for (var name in conf) {
|
||||
if ( hasOwnProp.call(conf, name) ) {
|
||||
// should we be restrictive here?
|
||||
// what is someone just wants to keep sample sources in same directory with tutorials?
|
||||
// I've decided to leave such cases alone
|
||||
// TODO: should we complain about this?
|
||||
if (!(name in tutorials)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -86,6 +86,11 @@ var linkMap = {
|
||||
urlToLongname: {}
|
||||
};
|
||||
|
||||
var tutorialLinkMap = {
|
||||
nameToUrl: {},
|
||||
urlToName: {}
|
||||
};
|
||||
|
||||
var longnameToUrl = exports.longnameToUrl = linkMap.longnameToUrl;
|
||||
|
||||
var linkto = exports.linkto = function(longname, linktext) {
|
||||
@ -336,7 +341,15 @@ var tutorialToUrl = exports.tutorialToUrl = function(tutorial) {
|
||||
return;
|
||||
}
|
||||
|
||||
return 'tutorial-' + getUniqueFilename(node.name);
|
||||
var url;
|
||||
// define the URL if necessary
|
||||
if (!tutorialLinkMap.nameToUrl[node.name]) {
|
||||
url = 'tutorial-' + getUniqueFilename(node.name);
|
||||
tutorialLinkMap.nameToUrl[node.name] = url;
|
||||
tutorialLinkMap.urlToName[url] = node.name;
|
||||
}
|
||||
|
||||
return tutorialLinkMap.nameToUrl[node.name];
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user