Created
March 31, 2014 18:41
-
-
Save xdumaine/9899202 to your computer and use it in GitHub Desktop.
A controller for serving arbitrary markdown documents from a directory, and having preprocessed keywords for writing.
This file contains hidden or 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
public class DocumentationController : Controller | |
{ | |
private const string DefaultDocPage = "Overview"; | |
public ActionResult Index(string id = null) | |
{ | |
ViewBag.HomeLinkPage = string.IsNullOrEmpty(id) || id == DefaultDocPage ? string.Empty : DefaultDocPage; | |
if (string.IsNullOrEmpty(ViewBag.HomeLinkPage)) | |
{ | |
id = DefaultDocPage; | |
} | |
var filePath = Server.MapPath(Url.Content("~/Content/Documentation/" + id.Trim("/".ToCharArray()) + ".md")); | |
if(!System.IO.File.Exists(filePath)) | |
{ | |
Response.StatusCode = (int)HttpStatusCode.NotFound; | |
return null; | |
} | |
var contents = new StringBuilder(System.IO.File.ReadAllText(filePath)); | |
contents.Replace("{{AppRoot}}/", Url.Content("~")); | |
contents.Replace("{{Documentation}}", Url.Content("~/Documentation")); | |
contents.Replace("{{DocumentationImages}}", Url.Content("~/Content/Documentation/images")); | |
contents.Replace("{{SupportLink}}", ConfigurationManager.AppSettings["SupportLink"]); | |
return View("Index", (object)contents.ToString()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment