feat: favicon

This commit is contained in:
HPCesia 2025-02-09 23:39:08 +08:00
parent 0a04480abc
commit 2210d608e4
8 changed files with 59 additions and 2 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

View File

@ -16,7 +16,10 @@ export const siteConfig: SiteConfig = {
title: 'Astral Halo',
subtitle: '',
lang: 'en', // "en" | "zh_CN" | "zh_TW"
favicon: [''],
favicon: [
// Leave this array empty to use the default favicon.
// 留空数组以使用默认的 favicon。
],
postsPerPage: 10,
};

20
src/constants/icon.ts Normal file
View File

@ -0,0 +1,20 @@
import type { Favicon } from '@/types/config';
export const defaultFavicons: Favicon[] = [
{
src: '/favicon/favicon-32x32.png',
sizes: '32x32',
},
{
src: '/favicon/favicon-128x128.png',
sizes: '128x128',
},
{
src: '/favicon/favicon-180x180.png',
sizes: '180x180',
},
{
src: '/favicon/favicon-192x192.png',
sizes: '192x192',
},
];

View File

@ -1,6 +1,8 @@
---
import { profileConfig, siteConfig } from '@/config';
import '@/styles/global.css';
import type { Favicon } from '@/types/config';
import { defaultFavicons } from '@constants/icon';
import { ClientRouter } from 'astro:transitions';
interface Props {
@ -18,6 +20,9 @@ else
if (!lang) lang = `${siteConfig.lang}`;
const siteLang = lang.replace('_', '-');
const favicons: Favicon[] =
siteConfig.favicon.length > 0 ? siteConfig.favicon : defaultFavicons;
---
<!doctype html>
@ -45,6 +50,20 @@ const siteLang = lang.replace('_', '-');
<meta name="generator" content={Astro.generator} />
{
favicons.map((favicon) => (
<link
rel="icon"
href={
favicon.src.startsWith('/')
? ['', import.meta.env.BASE_URL, favicon.src].join('/').replace(/\/+/g, '/')
: favicon.src
}
sizes={favicon.sizes}
/>
))
}
<slot name="head" />
</head>
<body class="bg-base-100 text-base-content flex min-h-screen flex-col">

View File

@ -1,5 +1,20 @@
import type I18nKey from '@i18n/I18nKey';
export type Favicon = {
/**
* The URL of the favicon.
*
* favicon URL
*/
src: string;
/**
* The sizes of the favicon.
*
* favicon
*/
sizes?: `${string}x${string}`;
};
export type ButtonSubConfig<T extends string> = T extends 'text'
? {
/**
@ -94,7 +109,7 @@ export type SiteConfig = {
*
* favicon
*/
favicon: string[];
favicon: Favicon[];
/**
* The number of posts displayed per page.
*