Skip to content

Commit 070ce1a

Browse files
committed
Remove favicon option
Fixes #23
1 parent a2c3f4d commit 070ce1a

File tree

3 files changed

+3
-84
lines changed

3 files changed

+3
-84
lines changed

README.md

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ A [TypeDoc](https://github.com/TypeStrong/typedoc) plugin to add extras to the o
88

99
It allows you to:
1010

11-
- Set a custom favicon.
1211
- Add the date/time of generation after "Generated using TypeDoc" in the footer. (cf. the [example](#example) below)
1312
- Set a custom top-most title name (without changing the package name, like `--name` would do).
1413
- For example, you could have `--customTitle "Go back" --titleLink <url-of-your-parent-documentation>`
@@ -20,6 +19,9 @@ All extras are disabled by default: they are opt-in.
2019

2120
Feel free to ask for another extra or to make a PR 😉
2221

22+
> [!IMPORTANT]
23+
> TypeDoc [now natively supports specifying a favicon](https://typedoc.org/documents/Options.Output.html#favicon). Consequently, the `--favicon` option in this plugin has been removed to prevent conflicts.
24+
2325
## Example
2426

2527
![example](./public/example.png)
@@ -52,11 +54,6 @@ The following arguments can be used in addition to the default [TypeDoc argument
5254
Specify a custom `<meta name="description"` property.<br>
5355
Example: `An example description`
5456

55-
- `--favicon`<br>
56-
Specify the path or URL of the favicon file.<br>
57-
Example: `public/favicon.ico`<br>
58-
**Note:** If given a path, the favicon file is copied into the documentation's output directory (`--out`).
59-
6057
- `--footerTypedocVersion`<br>
6158
Appends the TypeDoc version in the footer.<br>
6259
Default: `false`

src/helpers.ts

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,6 @@
11
import type { Application } from "typedoc";
22
import type { PluginOptions } from "./main.js";
33

4-
/**
5-
* Creates a relative path from a host file to a target file which is located in the root.
6-
* @example `modules/_index_.html` --> `../favicon.ico`
7-
* @param hostPath The path of the file which will contain the resulting relative path.
8-
* @param targetFilename The name of the target file.
9-
*/
10-
export function makeRelativeToRoot(hostPath: string, targetFilename: string): string {
11-
// Find separators.
12-
const match = hostPath.match(/[/\\]/g);
13-
if (!match) return targetFilename;
14-
15-
// Create path with one '../' per separator and targetFilename at the end.
16-
const separatorCount = match.length;
17-
const parts = [...Array(separatorCount).fill('..'), targetFilename];
18-
return parts.join('/');
19-
}
20-
21-
/**
22-
* Appends a favicon link at the end of `<head>` in the given html.
23-
* @param html HTML string to append to.
24-
* @param url URL of the favicon.
25-
*/
26-
export function appendFavicon(html: string, url: string): string {
27-
return html.replace('</head>',
28-
`<link rel="icon" href="${url}" />` +
29-
'\n' + // Push the end of <head> to the next line.
30-
'</head>'
31-
);
32-
}
33-
344
/**
355
* Appends a string value after "Generated using TypeDoc".
366
* @param html HTML string to append to.
@@ -56,14 +26,6 @@ export function setupNewlineInFooter(html: string): string {
5626
);
5727
}
5828

59-
/**
60-
* Determines whether a string is a URL.
61-
* @param url The URL to check.
62-
*/
63-
export function isUrl(url: string): boolean {
64-
return /^https?:\/\//i.test(url);
65-
}
66-
6729
/**
6830
* Replaces the top-most title text.
6931
* @param html HTML string to replace into.

src/main.ts

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
import { Application, ParameterType, PageEvent, RendererEvent } from 'typedoc';
2-
import { join, basename } from 'path';
3-
import { copyFileSync } from 'fs';
42
import {
5-
appendFavicon,
63
appendToFooter,
7-
makeRelativeToRoot,
8-
isUrl,
94
replaceTopMostTitle,
105
replaceDescription,
116
setupNewlineInFooter,
@@ -24,7 +19,6 @@ export const pluginOptions = (app: Application) => ({
2419
return {
2520
outDir: app.options.getValue('out') as string | undefined,
2621
hideGenerator: app.options.getValue('hideGenerator') as boolean,
27-
favicon: app.options.getValue('favicon') as string | undefined,
2822
footerDate: app.options.getValue('footerDate') as boolean,
2923
footerTime: app.options.getValue('footerTime') as boolean,
3024
footerLastModified: app.options.getValue('footerLastModified') as boolean,
@@ -39,13 +33,6 @@ export type PluginOptionsGetter = ReturnType<typeof pluginOptions>;
3933
export type PluginOptions = ReturnType<PluginOptionsGetter['options']>;
4034

4135
export function load(app: Application) {
42-
app.options.addDeclaration({
43-
name: 'favicon',
44-
help: 'Extras Plugin: Specify the name of the favicon file.',
45-
type: ParameterType.String,
46-
defaultValue: undefined
47-
});
48-
4936
app.options.addDeclaration({
5037
name: 'footerTypedocVersion',
5138
help: 'Extras Plugin: Appends the TypeDoc version in the footer.',
@@ -101,7 +88,6 @@ export function load(app: Application) {
10188
const options = pluginOptions(app);
10289

10390
app.renderer.on(PageEvent.END, onPageRendered.bind(options));
104-
app.renderer.on(RendererEvent.END, onRenderFinished.bind(options));
10591
}
10692

10793
function onPageRendered(this: PluginOptionsGetter, page: PageEvent) {
@@ -110,15 +96,6 @@ function onPageRendered(this: PluginOptionsGetter, page: PageEvent) {
11096

11197
const options = this.options();
11298

113-
// Add icon.
114-
if (options.favicon) {
115-
const favicon = isUrl(options.favicon)
116-
? options.favicon
117-
: makeRelativeToRoot(page.url, basename(options.favicon));
118-
119-
page.contents = appendFavicon(page.contents, favicon);
120-
}
121-
12299
// Add TypeDoc version.
123100
if (options.footerTypedocVersion) {
124101
page.contents = appendToFooter(page.contents, ` v${TYPEDOC_VERSION}`);
@@ -159,20 +136,3 @@ function onPageRendered(this: PluginOptionsGetter, page: PageEvent) {
159136
}
160137
}
161138

162-
function onRenderFinished(this: PluginOptionsGetter) {
163-
const options = this.options()
164-
165-
// Copy favicon to output directory.
166-
if (options.favicon && !isUrl(options.favicon)) {
167-
const workingDir = process.cwd();
168-
const outDir = options.outDir || './docs';
169-
170-
const inputFavicon = (options.favicon.indexOf(workingDir) === -1) ?
171-
join(workingDir, options.favicon) : options.favicon;
172-
173-
const outputFavicon = (outDir.indexOf(workingDir) === -1) ?
174-
join(workingDir, outDir, basename(options.favicon)) : join(outDir, basename(options.favicon));
175-
176-
copyFileSync(inputFavicon, outputFavicon);
177-
}
178-
}

0 commit comments

Comments
 (0)