diff --git a/controller/markdownToHtml.js b/controller/markdownToHtml.js index 774127bbc..3f0fbbead 100644 --- a/controller/markdownToHtml.js +++ b/controller/markdownToHtml.js @@ -1,27 +1,29 @@ -var markdown = require('markdown').markdown; -var fs = require('fs'); +const markdown = require('markdown').markdown; +const fs = require('fs'); -function setup(peliasConfig, markdownFile){ +function setup(peliasConfig, markdownFile) { - var styleString = ''; - var text = '# Pelias API\n'; - text += '### Version: [' + peliasConfig.version + '](https://github.com/pelias/api/releases)\n'; - text += fs.readFileSync( markdownFile, 'utf8'); - var html = styleString + markdown.toHTML(text); + // read markdown + const md = fs.readFileSync(markdownFile, 'utf8').trim(); - function controller( req, res ) { - if (req.accepts('html')) { - res.send(html); - return; - } - // default behaviour - res.json({ - markdown: text, - html: html - }); - } + // convert to HTML + const html = ` + + + + + Pelias Geocoder + + + + ${markdown.toHTML(md)} + +`.trim(); - return controller; + // send HTML + return function controller(req, res) { + res.send(html); + }; } module.exports = setup; diff --git a/public/apiDoc.md b/public/apiDoc.md index e00265938..6b4bcd442 100644 --- a/public/apiDoc.md +++ b/public/apiDoc.md @@ -1 +1,4 @@ +# Pelias API +### Version: [1.0](https://github.com/pelias/api/releases) + ## [View our documentation on GitHub](https://github.com/pelias/documentation/) diff --git a/public/attribution.md b/public/attribution.md index fc96eaa84..c0c579323 100644 --- a/public/attribution.md +++ b/public/attribution.md @@ -1,3 +1,6 @@ +# Pelias API +### Version: [1.0](https://github.com/pelias/api/releases) + ## Attribution * Geocoding by [Pelias](https://pelias.io). * Data from diff --git a/test/unit/controller/index.js b/test/unit/controller/index.js index b6a5a3966..a86062821 100644 --- a/test/unit/controller/index.js +++ b/test/unit/controller/index.js @@ -10,30 +10,11 @@ module.exports.tests.interface = function(test, common) { }); }; -module.exports.tests.info_json = function(test, common) { - test('returns server info in json', function(t) { - var controller = setup({}, './public/attribution.md'); - var req = { - accepts: function (format) { - t.equal(format, 'html', 'check for Accepts:html'); - return false; - } - }; - var res = { json: function( json ){ - t.equal(typeof json, 'object', 'returns json'); - t.assert(json.hasOwnProperty('markdown'), 'return object contains markdown property'); - t.assert(json.hasOwnProperty('html'), 'return object contains html property'); - t.end(); - }}; - controller( req, res ); - }); -}; - module.exports.tests.info_html = function(test, common) { test('returns server info in html', function(t) { var filePath = './foo.md'; - var style = ''; + var style = ''; var mockText = 'this text should show up in the html content'; var fsMock = { readFileSync: function (path, format) { @@ -56,8 +37,8 @@ module.exports.tests.info_html = function(test, common) { }; var res = { send: function( content ){ t.equal(typeof content, 'string', 'returns string'); - t.assert(content.indexOf(style) === 0, 'style set'); - t.assert(content.indexOf(mockText) !== -1, 'file content added'); + t.assert(content.includes(style), 'style set'); + t.assert(content.includes(mockText), 'file content added'); t.end(); }}; controller( req, res ); @@ -73,4 +54,4 @@ module.exports.all = function (tape, common) { for( var testCase in module.exports.tests ){ module.exports.tests[testCase](test, common); } -}; \ No newline at end of file +};