| 1 |
package website.api; |
| 2 |
|
| 3 |
import sys.FileSystem; |
| 4 |
import ufront.web.HttpError; |
| 5 |
import ufront.api.UFApi; |
| 6 |
import sys.io.File; |
| 7 |
using tink.CoreApi; |
| 8 |
|
| 9 |
class DocumentationApi extends UFApi { |
| 10 |
@inject("documentationPath") public var docPath:String; |
| 11 |
|
| 12 |
public function getDocumentationHTML( page:String ):Outcome<String,Error> { |
| 13 |
if ( page==null ) |
| 14 |
page = "index"; |
| 15 |
var markdownFile = docPath+page+'.md'; |
| 16 |
var markdown = |
| 17 |
try File.getContent( markdownFile ) |
| 18 |
catch(e:Dynamic) return Failure( new Error(404,'Documentation page $page not found: $e') ); |
| 19 |
var html = Markdown.markdownToHtml( markdown ); |
| 20 |
return Success( html ); |
| 21 |
} |
| 22 |
} |