typedoc-plugin-extras
Advanced tools
Comparing version 2.3.3 to 3.0.0
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.insertGAScriptInHead = exports.getDateTimeScript = exports.getLastModifiedScript = exports.replaceTopMostTitleLink = exports.replaceDescription = exports.replaceTopMostTitle = exports.isUrl = exports.setupNewlineInFooter = exports.appendToFooter = exports.appendFavicon = exports.makeRelativeToRoot = void 0; | ||
exports.deprecatedOption = exports.getDateTimeScript = exports.getLastModifiedScript = exports.replaceDescription = exports.replaceTopMostTitle = exports.isUrl = exports.setupNewlineInFooter = exports.appendToFooter = exports.appendFavicon = exports.makeRelativeToRoot = void 0; | ||
/** | ||
@@ -89,16 +89,2 @@ * Creates a relative path from a host file to a target file which is located in the root. | ||
exports.replaceDescription = replaceDescription; | ||
/** | ||
* Replaces the top-most title link. | ||
* @param html HTML string to replace into. | ||
* @param link The new link to set. | ||
*/ | ||
function replaceTopMostTitleLink(html, link) { | ||
return html.replace(/(<a href=")([^"]*)(" class="title">)([^<]*)(<\/a>)/, '$1' + // Start of <a> | ||
link + | ||
'$3' + // The class | ||
'$4' + // The title | ||
'$5' // End of <a> | ||
); | ||
} | ||
exports.replaceTopMostTitleLink = replaceTopMostTitleLink; | ||
const getLastModifiedScript = () => { | ||
@@ -155,18 +141,10 @@ // Use English as the locale because we say "Last modified". | ||
exports.getDateTimeScript = getDateTimeScript; | ||
const insertGAScriptInHead = (html, measurementId) => { | ||
const script = `<!-- Google tag (gtag.js) --> | ||
<script async src="https://www.googletagmanager.com/gtag/js?id=${measurementId}"></script> | ||
<script> | ||
window.dataLayer = window.dataLayer || []; | ||
function gtag(){dataLayer.push(arguments);} | ||
gtag('js', new Date()); | ||
gtag('config', '${measurementId}'); | ||
</script>`; | ||
return html.replace('<head>', '<head>' + | ||
'\n' + | ||
script + | ||
'\n'); | ||
const deprecatedOption = (app, { name, inFavorOf }) => { | ||
if (app.options.getValue(name)) { | ||
const error = Error(`[typedoc-plugin-extras] The \`--${name}\` option is deprecated. Please use \`--${inFavorOf}\` instead.`); | ||
delete error.stack; | ||
throw error; | ||
} | ||
}; | ||
exports.insertGAScriptInHead = insertGAScriptInHead; | ||
exports.deprecatedOption = deprecatedOption; | ||
//# sourceMappingURL=helpers.js.map |
@@ -10,15 +10,17 @@ "use strict"; | ||
const pluginOptions = (app) => ({ | ||
options: () => ({ | ||
outDir: app.options.getValue('out'), | ||
hideGenerator: app.options.getValue('hideGenerator'), | ||
favicon: app.options.getValue('favicon'), | ||
footerDate: app.options.getValue('footerDate'), | ||
footerTime: app.options.getValue('footerTime'), | ||
footerLastModified: app.options.getValue('footerLastModified'), | ||
footerTypedocVersion: app.options.getValue('footerTypedocVersion'), | ||
customTitle: app.options.getValue('customTitle'), | ||
customTitleLink: app.options.getValue('customTitleLink'), | ||
customDescription: app.options.getValue('customDescription'), | ||
gaMeasurementId: app.options.getValue('gaMeasurementId'), | ||
}), | ||
options: () => { | ||
(0, helpers_1.deprecatedOption)(app, { name: 'customTitleLink', inFavorOf: 'titleLink' }); | ||
(0, helpers_1.deprecatedOption)(app, { name: 'gaMeasurementId', inFavorOf: 'gaID' }); | ||
return { | ||
outDir: app.options.getValue('out'), | ||
hideGenerator: app.options.getValue('hideGenerator'), | ||
favicon: app.options.getValue('favicon'), | ||
footerDate: app.options.getValue('footerDate'), | ||
footerTime: app.options.getValue('footerTime'), | ||
footerLastModified: app.options.getValue('footerLastModified'), | ||
footerTypedocVersion: app.options.getValue('footerTypedocVersion'), | ||
customTitle: app.options.getValue('customTitle'), | ||
customDescription: app.options.getValue('customDescription'), | ||
}; | ||
}, | ||
}); | ||
@@ -64,8 +66,2 @@ exports.pluginOptions = pluginOptions; | ||
app.options.addDeclaration({ | ||
name: 'customTitleLink', | ||
help: 'Extras Plugin: Specify a custom link for the top-most title.', | ||
type: typedoc_1.ParameterType.String, | ||
defaultValue: undefined | ||
}); | ||
app.options.addDeclaration({ | ||
name: 'customDescription', | ||
@@ -77,4 +73,8 @@ help: 'Extras Plugin: Specify a custom description for the website.', | ||
app.options.addDeclaration({ | ||
name: 'customTitleLink', | ||
help: 'Extras Plugin: deprecated. Will be removed in the next release.', | ||
}); | ||
app.options.addDeclaration({ | ||
name: 'gaMeasurementId', | ||
help: 'Extras Plugin: Specify a Google Analytics measurement ID to insert in a gtag.js snippet.' | ||
help: 'Extras Plugin: deprecated. Will be removed in the next release.' | ||
}); | ||
@@ -125,6 +125,2 @@ const options = (0, exports.pluginOptions)(app); | ||
} | ||
// Set custom title link. | ||
if (options.customTitleLink) { | ||
page.contents = (0, helpers_1.replaceTopMostTitleLink)(page.contents, options.customTitleLink); | ||
} | ||
// Set custom description. | ||
@@ -134,6 +130,2 @@ if (options.customDescription) { | ||
} | ||
// Insert Google Analytics script. | ||
if (options.gaMeasurementId) { | ||
page.contents = (0, helpers_1.insertGAScriptInHead)(page.contents, options.gaMeasurementId); | ||
} | ||
} | ||
@@ -140,0 +132,0 @@ function onRenderFinished() { |
{ | ||
"name": "typedoc-plugin-extras", | ||
"version": "2.3.3", | ||
"description": "A TypeDoc plugin to add extras (favicon, generation date, Google Analytics...) to the output documentation", | ||
"version": "3.0.0", | ||
"description": "A TypeDoc plugin to add extras (favicon, description, generation date...) to the output documentation", | ||
"main": "./dist/main.js", | ||
@@ -37,3 +37,3 @@ "exports": "./dist/main.js", | ||
"peerDependencies": { | ||
"typedoc": "0.24.x" | ||
"typedoc": "0.25.x" | ||
}, | ||
@@ -40,0 +40,0 @@ "devDependencies": { |
@@ -9,5 +9,8 @@ # typedoc-plugin-extras | ||
- It can set a custom top-most title name and/or link. | ||
- It can find the `<head>` of the documents and append a favicon to it. | ||
- It can also add date/time of generation after "Generated using TypeDoc" in the footer. (cf. the [example](#example) below) | ||
It allows you to: | ||
- Set a custom favicon. | ||
- Add the date/time of generation after "Generated using TypeDoc" in the footer. (cf. the [example](#example) below) | ||
- Set a custom top-most title name (without changing the package name, like `--name` would do). | ||
- For example, you could have `--customTitle "Go back" --titleLink <url-of-your-parent-documentation>` | ||
- And more... (cf. the list of [arguments](#arguments) below) | ||
@@ -49,9 +52,5 @@ | ||
- `--customTitleLink`<br> | ||
Specify a custom link for the top-most title.<br> | ||
Example: `https://parent-docs-site.com` | ||
- `--customDescription`<br> | ||
Specify a custom meta description.<br> | ||
Example: `A test description` | ||
Specify a custom `<meta name="description"` property.<br> | ||
Example: `An example description` | ||
@@ -82,6 +81,2 @@ - `--favicon`<br> | ||
- `--gaMeasurementId`<br> | ||
Specify a [Google Analytics](https://support.google.com/analytics/answer/1008080?hl=en&ref_topic=1008079#zippy=%2Cin-this-article%2Cstatic-website) measurement ID to insert in a `gtag.js` snippet.<br> | ||
Example: `abc123`<br> | ||
## Testing | ||
@@ -88,0 +83,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
23803
281
98