This is how you get the DocFX view model in JSON form. Now you can create classes to represent it, and deserialise using Newtonsoft.Json
.
Make that the model for your Razor views, and have an MVC action that can select the appropriate JSON file, deserialise it, and pass that to View()
as the model.
Last active
January 14, 2018 04:16
-
-
Save tintoy/9a86e4185b24cc74f3feda50ee58f715 to your computer and use it in GitHub Desktop.
DocFX template to produce JSON for consumption in Razor views
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
{{!body}} |
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
var common = require('./common.js'); | |
var extension = require('./conceptual.extension.js') | |
var util = require('./statictoc.util.js'); | |
exports.transform = function (model) { | |
if (extension && extension.preTransform) { | |
model = extension.preTransform(model); | |
} | |
model._disableToc = model._disableToc || !model._tocPath || (model._navPath === model._tocPath); | |
model.docurl = model.docurl || common.getImproveTheDocHref(model, model._gitContribute, model._gitUrlPattern); | |
model = util.setToc(model); | |
if (extension && extension.postTransform) { | |
model = extension.postTransform(model); | |
} | |
// AF: yesyesyes, super-hacky; I should feel dirty, etc. BUT... | |
// The TOC is actually a DynamicExpandoObject from DocFX managed code; it contains cycles and so JSON.stringify(model) fails; but not anymore (muhahaha!) | |
model._toc = JSON.parse(JSON.stringify(model._toc)); | |
model._nav = JSON.parse(JSON.stringify(model._nav)); | |
// Our template just spits out this property. | |
model.rawJson = JSON.stringify(model, null, ' '); | |
return model; | |
} |
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
{{!master(_raw.tmpl)}} | |
{{{rawJson}}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment