forked from pelias/api
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(markdown): refactor controller/markdownToHtml.js module (pelias#…
…1599) * Added Missing HTML / BODY tag * Updated Text var to use Template Literal plus Simplified controller function * feat(markdown): refactor markdownToHtml controller Co-authored-by: Dhananjay-JSR <[email protected]> Co-authored-by: Dhananjay-JSR <[email protected]>
- Loading branch information
1 parent
a5aabc2
commit 5c650df
Showing
4 changed files
with
32 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 = '<style>html{font-family:monospace}</style>'; | ||
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 = ` | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>Pelias Geocoder</title> | ||
<style>html { font-family:monospace; }</style> | ||
</head> | ||
<body> | ||
${markdown.toHTML(md)} | ||
</body> | ||
</html>`.trim(); | ||
|
||
return controller; | ||
// send HTML | ||
return function controller(req, res) { | ||
res.send(html); | ||
}; | ||
} | ||
|
||
module.exports = setup; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,4 @@ | ||
# Pelias API | ||
### Version: [1.0](https://github.com/pelias/api/releases) | ||
|
||
## [View our documentation on GitHub](https://github.com/pelias/documentation/) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters