Docfx: [Question] Is it possible to make http requests within a preprocessor?

Created on 21 Mar 2019  ·  11Comments  ·  Source: dotnet/docfx

Operation System: Windows

DocFX Version Used: 2.40.8

Template used: custom template

Our team has been trying to resolve this for a week or so. I'm not sure if this is a request for added documentation, a bug, or something else. I do hope it's okay to post this here.

Steps to Reproduce:

  1. Create a custom template
  2. Create conceptual.extension.js within root of custom template
  3. Attempt to make http requests:
var http = require('http');
exports.preTransform = function (model) {
  return model;
}
exports.postTransform = function (model) {

  // var result = Some http request here
  // model._testme = result;

  return model;
}

Expected Behavior:

To allow requests to be made within a preprocessor, and assign the response to the model.

Actual Behavior:

Various forms of the following from different attempts:

Not a valid preprocessor

Additional Info
I can successfully assign some static value to the model and render that within a template partial. The issue arises when I try to do any type of "outside" requests.

Most helpful comment

Of course 😄 @nvisionative

All 11 comments

DocFX uses Jint, which cannot require a Node library directly. Usually it is easier to make such call in C#. DocFX plugins can be an valid option. Could you provide more details about your scenario?

@superyyrrzz Thank you for your response. We need to make a github api call to get contributors and pack this within an array that we can later iterate over within the template. There are api call limits so we're trying to attain this information on build and not on page load. So is the js file the wrong place to accomplish this?

DocFX has a similar plugin to generate contributors for articles on docs.microsoft.com. The plugin is a build step for ConceptualDocuemntProcessor to insert some data into model, by calling GitHub at build time. You can refer to this about how to create a plugin: https://dotnet.github.io/docfx/tutorial/howto_build_your_own_type_of_documentation_with_custom_plug-in.html

@superyyrrzz I am working with @patrickryan79 on this project and have been looking for an example of how to insert data into the model via a build step plugin. I have read the documentation (many times), but I am struggling a bit to see how this can be done. Would you happen to be able to share an example, some snippets or point us in the right direction? Thanks!

I agree this document is not clear enough for your requirement. You can refer to CountWord. It almost does the same thing as what you want: calculate some data and insert into model.

After compling this into a DLL, you can refer to this part of documentation to enable it.

@superyyrrzz thank you! So, in this example, “wordCount” can be used in a Mustache or Liquid template renderer?

Of course 😄 @nvisionative

@superyyrrzz Thank you for the confirmation and assistance - much appreciated!

@superyyrrzz Thank you for standing out of the crowd for us :)

@superyyrrzz for what it's worth, we are working on a new documentation site for DNN Platform. 🙌

@superyyrrzz just to close the loop on this - your recommendation worked like a charm. Thanks so much. I'm sure @patrickryan79 is cool with this issue being closed now.

Was this page helpful?
0 / 5 - 0 ratings