From 9edaf4aac4e9139bb0abc1dbeca963b7601706d1 Mon Sep 17 00:00:00 2001 From: mistic100 Date: Sat, 30 Nov 2024 10:33:11 +0100 Subject: [PATCH 1/3] Closes #2790 allow png favicon --- site/options/output.md | 2 +- src/lib/internationalization/locales/en.cts | 4 ++-- src/lib/output/plugins/AssetsPlugin.ts | 9 ++------- src/lib/output/themes/default/layouts/default.tsx | 2 ++ src/lib/utils/options/sources/typedoc.ts | 2 +- 5 files changed, 8 insertions(+), 11 deletions(-) diff --git a/site/options/output.md b/site/options/output.md index 626a8b8ba..152e968e6 100644 --- a/site/options/output.md +++ b/site/options/output.md @@ -262,7 +262,7 @@ Create a CNAME file in the output directory with the specified text. $ typedoc --favicon favicon.ico ``` -Specify a `favicon.ico` or `favicon.svg` file to reference as the site favicon. +Specify a `.ico`, `.png` or `.svg` file to reference as the site favicon. ## sourceLinkExternal diff --git a/src/lib/internationalization/locales/en.cts b/src/lib/internationalization/locales/en.cts index ff9981940..d72eec8f5 100644 --- a/src/lib/internationalization/locales/en.cts +++ b/src/lib/internationalization/locales/en.cts @@ -269,7 +269,7 @@ export = { help_cname: "Set the CNAME file text, it's useful for custom domains on GitHub Pages", help_favicon: - "Path to a favicon.ico or favicon.svg to include as the site icon", + "Path to a .ico, .png or .svg file to include as the site icon", help_sourceLinkExternal: "Specifies that source links should be treated as external links to be opened in a new tab", help_markdownLinkExternal: @@ -388,7 +388,7 @@ export = { "hostedBaseUrl must start with http:// or https://", useHostedBaseUrlForAbsoluteLinks_requires_hostedBaseUrl: "The useHostedBaseUrlForAbsoluteLinks option requires that hostedBaseUrl be set", - favicon_must_be_ico_or_svg: "Favicon file must be either a .ico or .svg", + favicon_must_be_ico_or_svg: "Favicon file must be either a .ico, .png or .svg", option_0_must_be_an_object: "The '{0}' option must be a non-array object", option_0_must_be_a_function: "The '{0}' option must be a function", option_0_must_be_object_with_urls: `{0} must be an object with string labels as keys and URL values`, diff --git a/src/lib/output/plugins/AssetsPlugin.ts b/src/lib/output/plugins/AssetsPlugin.ts index 55b17f41f..df9f54fa7 100644 --- a/src/lib/output/plugins/AssetsPlugin.ts +++ b/src/lib/output/plugins/AssetsPlugin.ts @@ -43,13 +43,8 @@ export class AssetsPlugin extends RendererComponent { private onRenderBegin(event: RendererEvent) { const dest = join(event.outputDirectory, "assets"); - switch (extname(this.favicon)) { - case ".ico": - copySync(this.favicon, join(dest, "favicon.ico")); - break; - case ".svg": - copySync(this.favicon, join(dest, "favicon.svg")); - break; + if ([".ico", ".png", ".svg"].includes(extname(this.favicon))) { + copySync(this.favicon, join(dest, "favicon" + extname(this.favicon))); } if (this.customCss) { diff --git a/src/lib/output/themes/default/layouts/default.tsx b/src/lib/output/themes/default/layouts/default.tsx index 27320f3da..7cbf20f73 100644 --- a/src/lib/output/themes/default/layouts/default.tsx +++ b/src/lib/output/themes/default/layouts/default.tsx @@ -13,6 +13,8 @@ function favicon(context: DefaultThemeRenderContext) { switch (extname(fav)) { case ".ico": return ; + case ".png": + return ; case ".svg": return ; default: diff --git a/src/lib/utils/options/sources/typedoc.ts b/src/lib/utils/options/sources/typedoc.ts index df2cb9a75..6da318bf5 100644 --- a/src/lib/utils/options/sources/typedoc.ts +++ b/src/lib/utils/options/sources/typedoc.ts @@ -473,7 +473,7 @@ export function addTypeDocOptions(options: Pick) { name: "favicon", help: (i18n) => i18n.help_favicon(), validate(value, i18n) { - if (![".ico", ".svg"].includes(extname(value))) { + if (![".ico", ".png", ".svg"].includes(extname(value))) { throw new Error(i18n.favicon_must_be_ico_or_svg()); } }, From 845c8904dc719b4bf2e5823997e742ce7d579569 Mon Sep 17 00:00:00 2001 From: mistic100 Date: Sat, 30 Nov 2024 10:45:03 +0100 Subject: [PATCH 2/3] run prettier --- src/lib/internationalization/locales/en.cts | 3 ++- src/lib/output/plugins/AssetsPlugin.ts | 5 ++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/lib/internationalization/locales/en.cts b/src/lib/internationalization/locales/en.cts index d72eec8f5..3e5a8938a 100644 --- a/src/lib/internationalization/locales/en.cts +++ b/src/lib/internationalization/locales/en.cts @@ -388,7 +388,8 @@ export = { "hostedBaseUrl must start with http:// or https://", useHostedBaseUrlForAbsoluteLinks_requires_hostedBaseUrl: "The useHostedBaseUrlForAbsoluteLinks option requires that hostedBaseUrl be set", - favicon_must_be_ico_or_svg: "Favicon file must be either a .ico, .png or .svg", + favicon_must_be_ico_or_svg: + "Favicon file must be either a .ico, .png or .svg", option_0_must_be_an_object: "The '{0}' option must be a non-array object", option_0_must_be_a_function: "The '{0}' option must be a function", option_0_must_be_object_with_urls: `{0} must be an object with string labels as keys and URL values`, diff --git a/src/lib/output/plugins/AssetsPlugin.ts b/src/lib/output/plugins/AssetsPlugin.ts index df9f54fa7..ea55907d6 100644 --- a/src/lib/output/plugins/AssetsPlugin.ts +++ b/src/lib/output/plugins/AssetsPlugin.ts @@ -44,7 +44,10 @@ export class AssetsPlugin extends RendererComponent { const dest = join(event.outputDirectory, "assets"); if ([".ico", ".png", ".svg"].includes(extname(this.favicon))) { - copySync(this.favicon, join(dest, "favicon" + extname(this.favicon))); + copySync( + this.favicon, + join(dest, "favicon" + extname(this.favicon)), + ); } if (this.customCss) { From 1c237e9c356bae103b96ae3343a8214280a5049c Mon Sep 17 00:00:00 2001 From: mistic100 Date: Sun, 1 Dec 2024 09:17:38 +0100 Subject: [PATCH 3/3] rework i18n --- src/lib/internationalization/locales/en.cts | 7 +++---- src/lib/internationalization/locales/zh.cts | 3 +-- src/lib/utils/options/sources/typedoc.ts | 9 +++++++-- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/lib/internationalization/locales/en.cts b/src/lib/internationalization/locales/en.cts index 3e5a8938a..41ad6ebfd 100644 --- a/src/lib/internationalization/locales/en.cts +++ b/src/lib/internationalization/locales/en.cts @@ -268,8 +268,7 @@ export = { "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", help_cname: "Set the CNAME file text, it's useful for custom domains on GitHub Pages", - help_favicon: - "Path to a .ico, .png or .svg file to include as the site icon", + help_favicon: "Path to favicon to include as the site icon", help_sourceLinkExternal: "Specifies that source links should be treated as external links to be opened in a new tab", help_markdownLinkExternal: @@ -388,8 +387,8 @@ export = { "hostedBaseUrl must start with http:// or https://", useHostedBaseUrlForAbsoluteLinks_requires_hostedBaseUrl: "The useHostedBaseUrlForAbsoluteLinks option requires that hostedBaseUrl be set", - favicon_must_be_ico_or_svg: - "Favicon file must be either a .ico, .png or .svg", + favicon_must_have_one_of_the_following_extensions_0: + "Favicon must have on of the following extensions: {0}", option_0_must_be_an_object: "The '{0}' option must be a non-array object", option_0_must_be_a_function: "The '{0}' option must be a function", option_0_must_be_object_with_urls: `{0} must be an object with string labels as keys and URL values`, diff --git a/src/lib/internationalization/locales/zh.cts b/src/lib/internationalization/locales/zh.cts index e2ab44cdb..5770ac4a3 100644 --- a/src/lib/internationalization/locales/zh.cts +++ b/src/lib/internationalization/locales/zh.cts @@ -279,7 +279,7 @@ export = localeUtils.buildIncompleteTranslation({ help_readme: "应显示在索引页上的自述文件路径。传递“none”以禁用索引页并在全局页上启动文档", help_cname: "设置 CNAME 文件文本,这对于 GitHub Pages 上的自定义域很有用", - help_favicon: "作为站点图标包含的 favicon.ico 或 favicon.svg 的路径", + help_favicon: "作为站点图标包含的 favicon 的路径", help_sourceLinkExternal: "指定哪些源代码链接应被视为外部链接,并在新选项卡中打开", help_markdownLinkExternal: @@ -371,7 +371,6 @@ export = localeUtils.buildIncompleteTranslation({ "hostingBaseUrl 必须以 http:// 或 https:// 开头", useHostedBaseUrlForAbsoluteLinks_requires_hostedBaseUrl: "useHostedBaseUrlForAbsoluteLinks 选项要求设置 hostingBaseUrl", - favicon_must_be_ico_or_svg: "Favicon 文件必须是一个 .ico 或 .svg 文件", option_0_must_be_an_object: "“{0}”选项必须是非数组对象", option_0_must_be_a_function: "‘{0}’ 选项必须是一个函数", option_0_must_be_object_with_urls: diff --git a/src/lib/utils/options/sources/typedoc.ts b/src/lib/utils/options/sources/typedoc.ts index 6da318bf5..2ff938ff2 100644 --- a/src/lib/utils/options/sources/typedoc.ts +++ b/src/lib/utils/options/sources/typedoc.ts @@ -473,8 +473,13 @@ export function addTypeDocOptions(options: Pick) { name: "favicon", help: (i18n) => i18n.help_favicon(), validate(value, i18n) { - if (![".ico", ".png", ".svg"].includes(extname(value))) { - throw new Error(i18n.favicon_must_be_ico_or_svg()); + const allowedExtension = [".ico", ".png", ".svg"]; + if (!allowedExtension.includes(extname(value))) { + throw new Error( + i18n.favicon_must_have_one_of_the_following_extensions_0( + allowedExtension.join(", "), + ), + ); } }, type: ParameterType.Path,