diff --git a/docs/docs.config.js b/docs/docs.config.js index 6be2674ee3..f639ce6879 100644 --- a/docs/docs.config.js +++ b/docs/docs.config.js @@ -20,13 +20,16 @@ module.exports = function(config) { config.set('basePath', __dirname); config.set('source.projectPath', '.'); config.set('rendering.outputFolder', '../tmp/ionic-site'); - config.set('rendering.contentsFolder', 'docs/' + config.get('currentVersion')); + + var versionData = require('./generate-versions')(config); + config.set('versionData', versionData); + config.set('rendering.contentsFolder', 'docs/' + versionData.current.folder); config.set('processing.api-docs', { - outputPath: '${area}/${module}/${docType}/${name}/index.md', - path: '${area}/${module}/${docType}/${name}', - moduleOutputPath: '${area}/${name}/index.md', - modulePath: '${area}/${name}' + outputPath: 'api/${docType}/${name}/index.md', + path: 'api/${docType}/${name}', + moduleOutputPath: 'api/module/${name}/index.md', + modulePath: 'api/module/${name}' }); config.set('processing.pages-data', { @@ -60,11 +63,9 @@ module.exports = function(config) { config.append('processing.processors', [ require('./processors/version-data'), - require('./processors/git-data'), require('./processors/keywords'), require('./processors/pages-data'), require('./processors/index-page'), - require('./processors/debug-dump') ]); return config; diff --git a/docs/generate-versions.js b/docs/generate-versions.js new file mode 100644 index 0000000000..951f78c70b --- /dev/null +++ b/docs/generate-versions.js @@ -0,0 +1,55 @@ +var _ = require('lodash'); +var fs = require('fs'); +var semver = require('semver'); +var path = require('canonical-path'); + +module.exports = function(config) { + var basePath = config.get('basePath'); + var outputFolder = config.get('rendering.outputFolder'); + var currentVersion = config.get('currentVersion'); + + var docsBaseFolder = path.resolve(basePath, outputFolder, 'docs'); + + var versions; + try { + versions = require(docsBaseFolder + '/version-data.json'); + } catch(e) { + versions = []; + } + + var nightlyVersion = { + href: '/docs/nightly', + folder: 'nightly', + name: 'nightly' + }; + + if ( !_.find(versions, {name: currentVersion}) ) { + //Make sure nightly version is always at the front of the list + if (currentVersion != 'nightly') { + versions.unshift({ + href: '/docs/latest', + folder: 'latest', + name: currentVersion + }); + //Make sure that if we have a nightly version, it moves back to the front + if (_.contains(versions, {name:'nightly'})) { + _.remove(versions, {name:'nightly'}); + versions.unshift(nightlyVersion); + } + } else { + versions.unshift(nightlyVersion); + } + } + + //Add current version to the top of the list if not exists + if (!_.find(versions, {name: currentVersion})) { + versions.unshift(currentVersion); + } + + return { + list: versions, + current: _.find(versions, { name: currentVersion }), + latest: _.find(versions, function(v) { return semver.valid(v.name); }) || + _.first(versions) + }; +}; diff --git a/docs/inline-tag-defs/link.js b/docs/inline-tag-defs/link.js index 8090953971..2c2be8d216 100644 --- a/docs/inline-tag-defs/link.js +++ b/docs/inline-tag-defs/link.js @@ -7,7 +7,7 @@ module.exports = { handlerFactory: function(partialNames, config) { return function handleLinkTags(doc, tagName, tagDescription) { - var version = config.get('currentVersion'); + var versionData = config.get('versionData'); // Parse out the uri and title return tagDescription.replace(INLINE_LINK, function(match, uri, title) { @@ -19,7 +19,7 @@ module.exports = { linkInfo.title = 'TODO:' + linkInfo.title; } - return '' + linkInfo.title + ''; + return '' + linkInfo.title + ''; }); }; } diff --git a/docs/processors/debug-dump.js b/docs/processors/debug-dump.js deleted file mode 100644 index 644091a363..0000000000 --- a/docs/processors/debug-dump.js +++ /dev/null @@ -1,26 +0,0 @@ -var writer = require('dgeni/lib/utils/doc-writer'); -var log = require('winston'); -var util = require("util"); - -var filter, outputPath, depth; - -module.exports = { - name: 'debug-dump', - runBefore: ['write-files'], - description: 'This processor dumps docs that match a filter to a file', - init: function(config, injectables) { - filter = config.get('processing.debug-dump.filter'); - outputPath = config.get('processing.debug-dump.outputPath'); - depth = config.get('processing.debug-dump.depth', 2); - }, - process: function(docs) { - if ( filter && outputPath ) { - log.info('Dumping docs:', filter, outputPath); - var filteredDocs = filter(docs); - var dumpedDocs = util.inspect(filteredDocs, depth); - return writer.writeFile(outputPath, dumpedDocs).then(function() { - return docs; - }); - } - } -}; \ No newline at end of file diff --git a/docs/processors/git-data.js b/docs/processors/git-data.js deleted file mode 100644 index c62836faa9..0000000000 --- a/docs/processors/git-data.js +++ /dev/null @@ -1,28 +0,0 @@ -var pkg = require('../../package.json'); - -//TODO get versions from git - -var version = { - major: '0', - minor: '9', - dot: '26', - codename: 'rabbit', - full: 'Nightly', - cdn: '0.9.26' -}; - -module.exports = { - name: 'git-data', - runBefore: ['loading-files'], - description: 'This processor adds information from the local git repository to the extraData injectable', - init: function(config, injectables) { - injectables.value('gitData', { - version: version, - versions: [], - info: 'git-data Information' - }); - }, - process: function(extraData, gitData) { - extraData.git = gitData; - } -}; diff --git a/docs/processors/version-data.js b/docs/processors/version-data.js index 33ba88530c..8d4d53f239 100644 --- a/docs/processors/version-data.js +++ b/docs/processors/version-data.js @@ -1,46 +1,13 @@ -var _ = require('lodash'); -var fs = require('fs'); -var semver = require('semver'); -var path = require('canonical-path'); - -var basePath; -var outputFolder; -var currentVersion; module.exports = { name: 'version-data', - description: 'Give a list of all available versions to the template', runBefore: ['pages-data'], - init: function(config) { - basePath = config.get('basePath'); - outputFolder = config.get('rendering.outputFolder'); - currentVersion = config.get('currentVersion'); - }, - process: function(docs, extraData) { - var docsBaseFolder = path.resolve(basePath, outputFolder, 'docs'); - - //Array of versions sorted backwards - var versions = fs.readdirSync(docsBaseFolder) - .filter(semver.valid) - .sort(semver.rcompare); - - //Add current version to the top of the list if not exists - !_.contains(versions, currentVersion) && versions.unshift(currentVersion); - - //Add nightly to the top of the list if not exists - !_.contains(versions, 'nightly') && versions.unshift('nightly'); - - versions = versions.map(function(ver) { - return { - href: '/docs/' + ver, - name: ver - }; + process: function(docs, config, extraData) { + extraData.version = config.get('versionData'); + docs.push({ + docType: 'version-data', + id: 'version-data', + template: 'version-data.template.json', + outputPath: 'docs/version-data.json' }); - extraData.version = { - list: versions, - current: _.find(versions, { name: currentVersion }), - //Stable = most recent (first) valid semver version - stable: _.find(versions, function(v) { return semver.valid(v.name); }) || - _.first(versions) - }; } }; diff --git a/docs/templates/pages-data.template.html b/docs/templates/pages-data.template.html index 281ccf06e5..bed752cac6 100644 --- a/docs/templates/pages-data.template.html +++ b/docs/templates/pages-data.template.html @@ -24,7 +24,7 @@ <@ endfor @> @@ -57,7 +57,7 @@