typedoc-plugin-extras
Advanced tools
Comparing version 1.1.7 to 1.1.8
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.appendDateTime = exports.appendFavicon = exports.makeRelativeToRoot = void 0; | ||
/** | ||
* Creates a relative path from a host file to a target file which is located in the root. | ||
* @example `modules/_index_.html` --> `../favicon.ico` | ||
* @param hostPath The path of the file which will contain the resulting relative path. | ||
* @param targetFilename The name of the target file. | ||
*/ | ||
function makeRelativeToRoot(hostPath, targetFilename) { | ||
// Find separators. | ||
const match = hostPath.match(/[/\\]/g); | ||
if (!match) | ||
return targetFilename; | ||
// Create path with one '../' per separator and targetFilename at the end. | ||
const separatorCount = match.length; | ||
@@ -13,14 +21,25 @@ const parts = [...Array(separatorCount).fill('..'), targetFilename]; | ||
exports.makeRelativeToRoot = makeRelativeToRoot; | ||
/** | ||
* Appends a favicon link at the end of `<head>` in the given html. | ||
* @param html HTML string to append to. | ||
* @param url URL of the favicon. | ||
*/ | ||
function appendFavicon(html, url) { | ||
return html.replace('</head>', '\t' + | ||
return html.replace('</head>', '\t' + // Some tabulation to fit the rest of the document. | ||
`<link rel="icon" href="${url}" />` + | ||
'\n' + | ||
'\n' + // Push the end of <head> to the next line. | ||
'</head>'); | ||
} | ||
exports.appendFavicon = appendFavicon; | ||
/** | ||
* Appends date and/or time after "Generated using TypeDoc". | ||
* @param html HTML string to append to. | ||
* @param dateTime A string containing date and/or time. | ||
*/ | ||
function appendDateTime(html, dateTime) { | ||
return html.replace(/(<p>Generated using.*TypeDoc.*)(<\/p>)/, '$1' + | ||
return html.replace(/(<p>Generated using.*TypeDoc.*)(<\/p>)/, '$1' + // Start of <p> | ||
dateTime + | ||
'$2'); | ||
'$2' // End of <p> | ||
); | ||
} | ||
exports.appendDateTime = appendDateTime; |
@@ -17,2 +17,3 @@ "use strict"; | ||
const hideTime = this.application.options.getValue('hideTime'); | ||
// Add icon. | ||
if (!noFavicon) { | ||
@@ -22,2 +23,3 @@ const faviconUrl = helpers_1.makeRelativeToRoot(page.url, favicon); | ||
} | ||
// Add generation date and/or time. | ||
if (!this.application.options.getValue('hideGenerator') && (!hideDate || !hideTime)) { | ||
@@ -24,0 +26,0 @@ const now = new Date(); |
{ | ||
"name": "typedoc-plugin-extras", | ||
"version": "1.1.7", | ||
"version": "1.1.8", | ||
"description": "A plugin for TypeDoc that adds extras to the generated documentation (favicon and date/time of generation).", | ||
@@ -10,3 +10,4 @@ "main": "dist/index.js", | ||
"scripts": { | ||
"start": "npx typedoc --plugin typedoc-plugin-extras", | ||
"start": "tsc --watch", | ||
"test": "npx typedoc --plugin typedoc-plugin-extras src/index.ts", | ||
"build": "tsc", | ||
@@ -37,7 +38,6 @@ "prepublishOnly": "npm run build" | ||
"devDependencies": { | ||
"@types/node": "^13.7.5", | ||
"typedoc": "^0.17.8", | ||
"typescript": "^3.8.3" | ||
}, | ||
"dependencies": {} | ||
"@types/node": "^15.0.2", | ||
"typedoc": "^0.20.36", | ||
"typescript": "^4.2.4" | ||
} | ||
} |
@@ -12,3 +12,3 @@ # typedoc-plugin-extras | ||
Feel free to ask for another extras or to make a PR 😉 | ||
Feel free to ask for another extra or to make a PR 😉 | ||
@@ -24,3 +24,3 @@ [![npm](https://img.shields.io/npm/v/typedoc-plugin-extras.svg)](https://www.npmjs.com/package/typedoc-plugin-extras) | ||
```bash | ||
npm install --save-dev typedoc typedoc-plugin-extras | ||
npm install --save-dev typedoc-plugin-extras | ||
``` | ||
@@ -50,4 +50,28 @@ | ||
## Testing | ||
To test this plugin, you can generate TypeDoc documentation _for this plugin_. | ||
First, link the package with npm: | ||
```bash | ||
npm link | ||
``` | ||
Then, you can generate the documentation with the plugin (from source): | ||
```bash | ||
npm run test | ||
``` | ||
If you want, you can watch your changes with: | ||
```bash | ||
npm start | ||
``` | ||
You will need to generate the documentation each time. | ||
## License | ||
[MIT](https://github.com/Drarig29/typedoc-plugin-extras/blob/master/LICENSE) |
Sorry, the diff of this file is not supported yet
9603
130
75