Skip to content

Commit e472283

Browse files
authored
Merge pull request #2791 from mistic100/favicon-png
Closes #2790 allow png favicon
2 parents 25e59ff + 1c237e9 commit e472283

File tree

6 files changed

+19
-15
lines changed

6 files changed

+19
-15
lines changed

site/options/output.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ Create a CNAME file in the output directory with the specified text.
262262
$ typedoc --favicon favicon.ico
263263
```
264264

265-
Specify a `favicon.ico` or `favicon.svg` file to reference as the site favicon.
265+
Specify a `.ico`, `.png` or `.svg` file to reference as the site favicon.
266266

267267
## sourceLinkExternal
268268

src/lib/internationalization/locales/en.cts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -268,8 +268,7 @@ export = {
268268
"Path to the readme file that should be displayed on the index page. Pass `none` to disable the index page and start the documentation on the globals page",
269269
help_cname:
270270
"Set the CNAME file text, it's useful for custom domains on GitHub Pages",
271-
help_favicon:
272-
"Path to a favicon.ico or favicon.svg to include as the site icon",
271+
help_favicon: "Path to favicon to include as the site icon",
273272
help_sourceLinkExternal:
274273
"Specifies that source links should be treated as external links to be opened in a new tab",
275274
help_markdownLinkExternal:
@@ -388,7 +387,8 @@ export = {
388387
"hostedBaseUrl must start with http:// or https://",
389388
useHostedBaseUrlForAbsoluteLinks_requires_hostedBaseUrl:
390389
"The useHostedBaseUrlForAbsoluteLinks option requires that hostedBaseUrl be set",
391-
favicon_must_be_ico_or_svg: "Favicon file must be either a .ico or .svg",
390+
favicon_must_have_one_of_the_following_extensions_0:
391+
"Favicon must have on of the following extensions: {0}",
392392
option_0_must_be_an_object: "The '{0}' option must be a non-array object",
393393
option_0_must_be_a_function: "The '{0}' option must be a function",
394394
option_0_must_be_object_with_urls: `{0} must be an object with string labels as keys and URL values`,

src/lib/internationalization/locales/zh.cts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ export = localeUtils.buildIncompleteTranslation({
279279
help_readme:
280280
"应显示在索引页上的自述文件路径。传递“none”以禁用索引页并在全局页上启动文档",
281281
help_cname: "设置 CNAME 文件文本,这对于 GitHub Pages 上的自定义域很有用",
282-
help_favicon: "作为站点图标包含的 favicon.ico 或 favicon.svg 的路径",
282+
help_favicon: "作为站点图标包含的 favicon 的路径",
283283
help_sourceLinkExternal:
284284
"指定哪些源代码链接应被视为外部链接,并在新选项卡中打开",
285285
help_markdownLinkExternal:
@@ -371,7 +371,6 @@ export = localeUtils.buildIncompleteTranslation({
371371
"hostingBaseUrl 必须以 http:// 或 https:// 开头",
372372
useHostedBaseUrlForAbsoluteLinks_requires_hostedBaseUrl:
373373
"useHostedBaseUrlForAbsoluteLinks 选项要求设置 hostingBaseUrl",
374-
favicon_must_be_ico_or_svg: "Favicon 文件必须是一个 .ico 或 .svg 文件",
375374
option_0_must_be_an_object: "“{0}”选项必须是非数组对象",
376375
option_0_must_be_a_function: "‘{0}’ 选项必须是一个函数",
377376
option_0_must_be_object_with_urls:

src/lib/output/plugins/AssetsPlugin.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,11 @@ export class AssetsPlugin extends RendererComponent {
4343
private onRenderBegin(event: RendererEvent) {
4444
const dest = join(event.outputDirectory, "assets");
4545

46-
switch (extname(this.favicon)) {
47-
case ".ico":
48-
copySync(this.favicon, join(dest, "favicon.ico"));
49-
break;
50-
case ".svg":
51-
copySync(this.favicon, join(dest, "favicon.svg"));
52-
break;
46+
if ([".ico", ".png", ".svg"].includes(extname(this.favicon))) {
47+
copySync(
48+
this.favicon,
49+
join(dest, "favicon" + extname(this.favicon)),
50+
);
5351
}
5452

5553
if (this.customCss) {

src/lib/output/themes/default/layouts/default.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ function favicon(context: DefaultThemeRenderContext) {
1313
switch (extname(fav)) {
1414
case ".ico":
1515
return <link rel="icon" href={context.relativeURL("assets/favicon.ico", true)} />;
16+
case ".png":
17+
return <link rel="icon" href={context.relativeURL("assets/favicon.png", true)} type="image/png" />;
1618
case ".svg":
1719
return <link rel="icon" href={context.relativeURL("assets/favicon.svg", true)} type="image/svg+xml" />;
1820
default:

src/lib/utils/options/sources/typedoc.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -473,8 +473,13 @@ export function addTypeDocOptions(options: Pick<Options, "addDeclaration">) {
473473
name: "favicon",
474474
help: (i18n) => i18n.help_favicon(),
475475
validate(value, i18n) {
476-
if (![".ico", ".svg"].includes(extname(value))) {
477-
throw new Error(i18n.favicon_must_be_ico_or_svg());
476+
const allowedExtension = [".ico", ".png", ".svg"];
477+
if (!allowedExtension.includes(extname(value))) {
478+
throw new Error(
479+
i18n.favicon_must_have_one_of_the_following_extensions_0(
480+
allowedExtension.join(", "),
481+
),
482+
);
478483
}
479484
},
480485
type: ParameterType.Path,

0 commit comments

Comments
 (0)