2020-03-21 21:03:29 -06:00
|
|
|
const moduleDocsPathPrefix = "/docs/modules/";
|
|
|
|
|
|
|
|
var moduleID = window.location.pathname.substr(moduleDocsPathPrefix.length);
|
|
|
|
if (moduleID) {
|
2021-06-02 15:16:15 -06:00
|
|
|
// update page title and load the docs for these modules (possibly more than 1 with this ID)
|
2020-03-21 21:03:29 -06:00
|
|
|
document.title = "Module " + moduleID + " - Caddy Documentation";
|
|
|
|
$.get("/api/docs/module/"+moduleID, function(json) {
|
2021-06-02 15:16:15 -06:00
|
|
|
var modules = json.result;
|
|
|
|
|
2020-03-21 21:03:29 -06:00
|
|
|
// wait until the DOM has finished loading before rendering the results
|
|
|
|
$(function() {
|
|
|
|
$('#module-docs-container').show();
|
2021-06-02 15:16:15 -06:00
|
|
|
$('.module-name').text("Module "+moduleID);
|
|
|
|
modules.forEach((module) => {
|
|
|
|
$tpl = $('#module-template').clone().attr('id', stripScheme(module.repo));
|
|
|
|
if (modules.length > 1) {
|
|
|
|
$('article', $tpl).hide();
|
|
|
|
}
|
|
|
|
beginRenderingInto($tpl, moduleID, module);
|
|
|
|
$('#module-docs-container').append($tpl);
|
|
|
|
});
|
|
|
|
if (modules.length > 1) {
|
|
|
|
$('#module-multiple-repos .module-name').text(moduleID);
|
|
|
|
$('#module-multiple-repos').show();
|
|
|
|
} else {
|
|
|
|
$('.module-repo-selector').hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
// if a specific repo's module is wanted, expand and scroll to it
|
|
|
|
if (window.location.hash.length > 1) {
|
|
|
|
// TODO: weird bug in jQuery(??) that it can't select IDs with slashes in them, so we use vanilla JS
|
|
|
|
var container = document.getElementById(window.location.hash.substr(1));
|
|
|
|
$('.module-repo-selector', container).click();
|
|
|
|
container.scrollIntoView();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
$(function() {
|
|
|
|
$('body').on('click', '.module-repo-selector', function() {
|
|
|
|
if ($(this).hasClass('expanded')) {
|
|
|
|
// collapse
|
|
|
|
$('.module-repo-selector-arrow', this).html('▸');
|
|
|
|
} else {
|
|
|
|
// expand
|
|
|
|
$('.module-repo-selector-arrow', this).html('▾');
|
|
|
|
}
|
|
|
|
$(this).toggleClass('expanded');
|
|
|
|
$(this).next('article').toggle();
|
2020-03-21 21:03:29 -06:00
|
|
|
});
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
// populate the module list
|
2020-07-16 15:51:46 -06:00
|
|
|
$.get("/api/modules", function(json) {
|
|
|
|
var moduleList = json.result;
|
2021-06-02 15:16:15 -06:00
|
|
|
|
|
|
|
console.log("MODULE LIST:", moduleList);
|
2020-07-16 15:51:46 -06:00
|
|
|
|
2020-03-21 21:03:29 -06:00
|
|
|
// wait until the DOM has finished loading before rendering the results
|
|
|
|
$(function() {
|
|
|
|
$('#module-list-container').show();
|
|
|
|
$table = $('#module-list');
|
|
|
|
for (modID in moduleList) {
|
2021-06-02 15:16:15 -06:00
|
|
|
var infos = moduleList[modID];
|
2021-05-25 17:26:35 -06:00
|
|
|
|
2021-06-02 15:16:15 -06:00
|
|
|
infos.forEach((info) => {
|
|
|
|
// refine a short preview of the module's docs
|
|
|
|
let shortDoc = truncate(info.docs, 200);
|
|
|
|
if (shortDoc && shortDoc.indexOf(modID) === 0) {
|
|
|
|
shortDoc = shortDoc.substr(modID.length).trim();
|
|
|
|
}
|
|
|
|
|
|
|
|
let modLink = "./"+modID;
|
|
|
|
if (infos.length > 1) {
|
|
|
|
modLink += "#"+stripScheme(info.repo);
|
|
|
|
}
|
|
|
|
|
|
|
|
var standard = isStandard(info.package);
|
|
|
|
var $tr = $('<tr/>');
|
|
|
|
$tr.append('<td>'+(standard ? standardFlag : nonStandardFlag)+'</td>');
|
|
|
|
var $tdLink = $('<td><a href="'+modLink+'" class="module-link">'+modID+'</a></td>');
|
|
|
|
if (infos.length > 1) {
|
|
|
|
$tdLink.append($('<div class="module-repo-differentiator">').text('('+stripScheme(info.repo)+')'));
|
|
|
|
}
|
|
|
|
$tr.append($tdLink);
|
|
|
|
$tr.append($('<td/>').text(shortDoc));
|
|
|
|
$table.append($tr);
|
|
|
|
});
|
2020-03-21 21:03:29 -06:00
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2021-06-02 15:16:15 -06:00
|
|
|
}
|