From dfed388139523f53018259e392ff829b87de13d0 Mon Sep 17 00:00:00 2001 From: Peter Bacon Darwin Date: Tue, 21 Feb 2017 16:57:19 +0000 Subject: [PATCH] fix(aio): convert API and content docs to JSON --- aio/transforms/angular.io-package/index.js | 14 ++++++++++--- .../processors/convertToJson.js | 20 +++++++++++++++++++ .../processors/generateKeywords.js | 2 +- 3 files changed, 32 insertions(+), 4 deletions(-) create mode 100644 aio/transforms/angular.io-package/processors/convertToJson.js diff --git a/aio/transforms/angular.io-package/index.js b/aio/transforms/angular.io-package/index.js index 49aa4fd3e7..b36cef2232 100644 --- a/aio/transforms/angular.io-package/index.js +++ b/aio/transforms/angular.io-package/index.js @@ -46,6 +46,7 @@ module.exports = .processor(require('./processors/extractDecoratedClasses')) .processor(require('./processors/matchUpDirectiveDecorators')) .processor(require('./processors/filterMemberDocs')) + .processor(require('./processors/convertToJson')) // overrides base packageInfo and returns the one for the 'angular/angular' repo. .factory('packageInfo', function() { return require(path.resolve(PROJECT_ROOT, 'package.json')); }) @@ -211,12 +212,12 @@ module.exports = doc.id.replace(/^@angular\//, API_SEGMENT + '/').replace(/\/index$/, ''); return doc.moduleFolder; }, - outputPathTemplate: '${moduleFolder}/index.html' + outputPathTemplate: '${moduleFolder}/index.json' }, { docTypes: EXPORT_DOC_TYPES.concat(['decorator', 'directive', 'pipe']), pathTemplate: '${moduleDoc.moduleFolder}/${name}', - outputPathTemplate: '${moduleDoc.moduleFolder}/${name}.html', + outputPathTemplate: '${moduleDoc.moduleFolder}/${name}.json', }, { docTypes: ['api-list-data', 'api-list-audit'], @@ -229,10 +230,17 @@ module.exports = outputPathTemplate: '${path}' }, {docTypes: ['example-region'], getOutputPath: function() {}}, - {docTypes: ['content'], pathTemplate: '${id}', outputPathTemplate: '${path}.html'} + {docTypes: ['content'], pathTemplate: '${id}', outputPathTemplate: '${path}.json'} ]; + }) + + .config(function(convertToJsonProcessor, EXPORT_DOC_TYPES) { + convertToJsonProcessor.docTypes = EXPORT_DOC_TYPES.concat([ + 'content', 'decorator', 'directive', 'pipe', 'module' + ]); }); + function requireFolder(folderPath) { const absolutePath = path.resolve(__dirname, folderPath); return fs.readdirSync(absolutePath) diff --git a/aio/transforms/angular.io-package/processors/convertToJson.js b/aio/transforms/angular.io-package/processors/convertToJson.js new file mode 100644 index 0000000000..66f95c0fa8 --- /dev/null +++ b/aio/transforms/angular.io-package/processors/convertToJson.js @@ -0,0 +1,20 @@ +module.exports = function convertToJsonProcessor() { + + return { + $runAfter: ['checkUnbalancedBackTicks'], + $runBefore: ['writeFilesProcessor'], + docTypes: [], + $process: function(docs) { + const docTypes = this.docTypes + docs.forEach((doc) => { + if (docTypes.indexOf(doc.docType) !== -1) { + const output = { + title: doc.title || doc.name, + content: doc.renderedContent + }; + doc.renderedContent = JSON.stringify(output, null, 2); + } + }); + } + }; +}; \ No newline at end of file diff --git a/aio/transforms/angular.io-package/processors/generateKeywords.js b/aio/transforms/angular.io-package/processors/generateKeywords.js index d2a22b6e9c..0e70499928 100644 --- a/aio/transforms/angular.io-package/processors/generateKeywords.js +++ b/aio/transforms/angular.io-package/processors/generateKeywords.js @@ -102,7 +102,7 @@ module.exports = function generateKeywordsProcessor(log, readFilesProcessor) { doc.searchTerms = { - titleWords: extractTitleWords(doc.name), + titleWords: extractTitleWords(doc.title || doc.name), keywords: words.sort().join(' '), members: members.sort().join(' ') };