Skip to content

Commit

Permalink
add support for typedoc@0.16.x (#26)
Browse files Browse the repository at this point in the history
* add support for typedoc@0.16.x
* update readme
* fix bug: link doesn't generated correctly for path like "127.0.0.1/docs/modules/" and "127.0.0.1/docs/modules/foo_classes/"

Close #24
  • Loading branch information
goldenyz authored and Fleker committed Jan 21, 2020
1 parent 9fa76bc commit 51e5101
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 79 deletions.
8 changes: 8 additions & 0 deletions README.md
Expand Up @@ -25,6 +25,14 @@ After you install the module, you can use this theme in a build by running:

Build the plugin by running `yarn build:plugin`.

After you install the module, you can use this plugin in a build by running:

`typedoc --theme ./node_modules/typedoc-neo-theme/bin/default --plugin typedoc-neo-theme`

Alternatively it can be partially placed in the typedoc options:

`typedoc --options typedoc.json --theme node_modules/typedoc-neo-theme/bin/default`

### Typedoc options
This plugin adds additional options that can be placed in your `typedoc.json` file.

Expand Down
9 changes: 5 additions & 4 deletions index.js
Expand Up @@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
let { ParameterType } = require('typedoc/dist/lib/utils/options/declaration');
let plugin = require('./bin/default/plugin')
module.exports = (PluginHost) => {
const app = PluginHost.owner
Expand All @@ -23,22 +24,22 @@ module.exports = (PluginHost) => {
* url: string
* }
*/
app.options.addDeclaration({ name: 'links', type: 'Array' })
app.options.addDeclaration({ name: 'links', type: ParameterType.Mixed })
/*
* Expected array:
* interface Outline {
* [key: string]: string | Outline
* }
*/
app.options.addDeclaration({ name: 'outline', type: 'Array' })
app.options.addDeclaration({ name: 'outline', type: ParameterType.Mixed })
/*
* Expected array:
* interface Search {
* name: string
* subtitle: string
* }
*/
app.options.addDeclaration({ name: 'search', type: 'Array' })
app.options.addDeclaration({ name: 'search', type: ParameterType.Mixed })
/*
* Expected array:
interface Source {
Expand All @@ -47,7 +48,7 @@ module.exports = (PluginHost) => {
// Becomes https://github.com/actions-on-google/actions-on-google-nodejs/blob/master/src/assistant.ts#L1
}
*/
app.options.addDeclaration({ name: 'source', type: 'Array' })
app.options.addDeclaration({ name: 'source', type: ParameterType.Mixed })

app.converter.addComponent('neo-theme', plugin.ExternalModuleMapPlugin)
}
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -23,7 +23,7 @@
"node": ">=6"
},
"dependencies": {
"typedoc": "0.15.0"
"typedoc": "0.16.0"
},
"devDependencies": {
"grunt": "^1.0.1",
Expand Down
62 changes: 31 additions & 31 deletions third_party/src/default/assets/js/main.js
Expand Up @@ -413,46 +413,46 @@ function sanitizeModuleName(moduleName) {
return moduleName.toLowerCase().replace(/[^a-z0-9]/gi, '_');
}
function renderSimpleHTMLRecursive(obj, package, spacing) {
if (package === void 0) { package = ""; }
if (spacing === void 0) { spacing = " "; }
var html = "";
if (package === void 0) { package = ''; }
if (spacing === void 0) { spacing = ' '; }
var html = '';
var shownPackages = [];
for (var _i = 0, _a = Object.keys(obj); _i < _a.length; _i++) {
var key = _a[_i];
if (typeof obj[key] === "object") {
html += renderSimpleHTMLRecursive(obj[key], package + "_" + key, spacing + "&emsp;");
if (typeof obj[key] === 'object') {
html += renderSimpleHTMLRecursive(obj[key], package + '_' + key, spacing + '&emsp;');
}
else {
if (shownPackages.indexOf(package) === -1) {
html += "<div>" + package.replace(/_/g, "/") + "</div>";
html += '<div>' + package.replace(/_/g, '/') + '</div>';
shownPackages.push(package);
}
var href = "";
if (window.location.href.indexOf("modules") == -1) {
href = "modules/";
var href = '';
if (window.location.href.indexOf('/modules/') == -1) {
href = 'modules/';
}
if (window.location.href.indexOf("assets") > -1 ||
window.location.href.indexOf("classes") > -1 ||
window.location.href.indexOf("enums") > -1 ||
window.location.href.indexOf("interfaces") > -1) {
href = "../modules/";
if (window.location.href.indexOf('/assets/') > -1 ||
window.location.href.indexOf('/classes/') > -1 ||
window.location.href.indexOf('/enums/') > -1 ||
window.location.href.indexOf('/interfaces/') > -1) {
href = '../modules/';
}
if (window.location.href.indexOf("modules") > -1) {
href = "../modules/" + href;
if (window.location.href.indexOf('/modules/') > -1) {
href = '../' + href;
}
if (package) {
if (key === "Overview") {
href += "_" + package.substr(1) + "_.html";
if (key === 'Overview') {
href += '_' + package.substr(1) + '_.html';
}
else {
href +=
"_" + package.substr(1) + "_" + sanitizeModuleName(key) + "_.html";
'_' + package.substr(1) + '_' + sanitizeModuleName(key) + '_.html';
}
}
else {
href += "_" + sanitizeModuleName(key) + "_.html";
href += '_' + sanitizeModuleName(key) + '_.html';
}
html += "<a href='" + href + "'>" + key + "</a>";
html += '<a href=\'' + href + '\'>' + key + '</a>';
}
}
return html;
Expand All @@ -473,20 +473,20 @@ function renderHTMLRecursive(obj, package, spacing) {
shownPackages.push(package);
}
var href = '';
if (obj[key].indexOf("/") === -1) {
href = "modules/";
if (obj[key].indexOf('/') === -1) {
href = 'modules/';
}
if (window.location.href.indexOf("assets") > -1 ||
window.location.href.indexOf("classes") > -1 ||
window.location.href.indexOf("enums") > -1 ||
window.location.href.indexOf("interfaces") > -1) {
href = "../modules/";
if (window.location.href.indexOf('/assets/') > -1 ||
window.location.href.indexOf('/classes/') > -1 ||
window.location.href.indexOf('/enums/') > -1 ||
window.location.href.indexOf('/interfaces/') > -1) {
href = '../modules/';
}
if (window.location.href.indexOf("modules") > -1) {
href = "../modules/" + href;
if (window.location.href.indexOf('/modules/') > -1) {
href = '../' + href;
}
var pageName = href + obj[key];
var pageNamePath = pageName.replace("../", "") + ".html";
var pageNamePath = pageName.replace('../', '') + ".html";
if (window.location.href.indexOf(pageNamePath) > -1) {
html += "<a class=\"selected\" href='" + pageName + ".html'>" + key + "</a>";
}
Expand Down
Expand Up @@ -19,48 +19,48 @@
// For compatibility
// https://stackoverflow.com/questions/36713651/typescript-array-from-error-ts2339-property-from-does-not-exist-on-type
interface ArrayConstructor {
from(arrayLike: any, mapFn?, thisArg?): Array<any>;
from(arrayLike: any, mapFn?, thisArg?): Array<any>;
}

// https://codereview.stackexchange.com/questions/166160/convert-an-array-to-a-nested-object
function arrayToNest(array: Array<string>): object {
let res: object = {}
for(let i: number = array.length - 1; i >= 0 ; i--) {
if(i == array.length - 1)
res = { [array[i]] : array[i]}; // assign the value
else
res = { [array[i]] : res}; // put the prev object
}
return res
let res: object = {}
for (let i: number = array.length - 1; i >= 0; i--) {
if (i == array.length - 1)
res = { [array[i]]: array[i] }; // assign the value
else
res = { [array[i]]: res }; // put the prev object
}
return res
}

/*
* Recursively merge properties of two objects
* https://stackoverflow.com/questions/171251/how-can-i-merge-properties-of-two-javascript-objects-dynamically
*/
function mergeRecursive(obj1: object, obj2: object): object {
for (const p in obj2) {
try {
// Property in destination object set; update its value.
if (obj2[p].constructor == Object) {
if (obj1[p].constructor !== Object) {
// Convert string value to object value
// Store top-level values as 'Overview'
obj1[p] = {
Overview: obj1[p]
}
for (const p in obj2) {
try {
// Property in destination object set; update its value.
if (obj2[p].constructor == Object) {
if (obj1[p].constructor !== Object) {
// Convert string value to object value
// Store top-level values as 'Overview'
obj1[p] = {
Overview: obj1[p]
}
obj1[p] = mergeRecursive(obj1[p], obj2[p]);

} else {
obj1[p] = obj2[p];
}
} catch(e) {
// Property in destination object not set; create it and set its value.
obj1[p] = mergeRecursive(obj1[p], obj2[p]);

} else {
obj1[p] = obj2[p];
}
} catch (e) {
// Property in destination object not set; create it and set its value.
obj1[p] = obj2[p];
}
return obj1;
}
return obj1;
}

/**
Expand Down Expand Up @@ -94,19 +94,19 @@ function renderSimpleHTMLRecursive(
shownPackages.push(package);
}
var href = '';
if (window.location.href.indexOf('modules') == -1) {
if (window.location.href.indexOf('/modules/') == -1) {
href = 'modules/';
}
if (
window.location.href.indexOf('assets') > -1 ||
window.location.href.indexOf('classes') > -1 ||
window.location.href.indexOf('enums') > -1 ||
window.location.href.indexOf('interfaces') > -1
window.location.href.indexOf('/assets/') > -1 ||
window.location.href.indexOf('/classes/') > -1 ||
window.location.href.indexOf('/enums/') > -1 ||
window.location.href.indexOf('/interfaces/') > -1
) {
href = '../modules/';
}
if (window.location.href.indexOf('modules') > -1) {
href = '../modules/' + href;
if (window.location.href.indexOf('/modules/') > -1) {
href = '../' + href;
}
if (package) {
if (key === 'Overview') {
Expand Down Expand Up @@ -149,15 +149,15 @@ function renderHTMLRecursive(obj: object, package: string = '', spacing: string
}

if (
window.location.href.indexOf('assets') > -1 ||
window.location.href.indexOf('classes') > -1 ||
window.location.href.indexOf('enums') > -1 ||
window.location.href.indexOf('interfaces') > -1
window.location.href.indexOf('/assets/') > -1 ||
window.location.href.indexOf('/classes/') > -1 ||
window.location.href.indexOf('/enums/') > -1 ||
window.location.href.indexOf('/interfaces/') > -1
) {
href = '../modules/';
}
if (window.location.href.indexOf('modules') > -1) {
href = '../modules/' + href;
if (window.location.href.indexOf('/modules/') > -1) {
href = '../' + href;
}
// Check if the user is currently on this page. If so, bold this item.
const pageName = href + obj[key];
Expand Down Expand Up @@ -187,14 +187,14 @@ window.addEventListener('load', () => {
const modules = document.querySelectorAll(filter) as NodeListOf<HTMLAnchorElement>
const hierarchy = {}
Array.from(modules).forEach(m => {
const packageArr = m.innerText.split('/');
const nestedArr = arrayToNest(packageArr);
mergeRecursive(hierarchy, nestedArr)
const packageArr = m.innerText.split('/');
const nestedArr = arrayToNest(packageArr);
mergeRecursive(hierarchy, nestedArr)
})
const listItemFilter = '.tsd-navigation .tsd-kind-external-module'
const listItems = document.querySelectorAll(listItemFilter) as NodeListOf<HTMLElement>
Array.from(listItems).forEach(el => {
el.remove()
el.remove()
})
const navigationFilter = '.tsd-navigation ul'
document.querySelector(navigationFilter).innerHTML += renderSimpleHTMLRecursive(hierarchy)
Expand Down

0 comments on commit 51e5101

Please sign in to comment.