Commit e4c2794

HPCesia <me@hpcesia.com>
2025-04-04 15:01:36
feat: blank config for nav button
1 parent 01a2395
src/components/Navbar.astro
@@ -43,7 +43,11 @@ if (!title) title = 'Astral Halo';
                     <ul class="menu bg-base-200/50 absolute -translate-x-[50%] rounded-xl shadow backdrop-blur-md">
                       {item.items.map((subItem) => (
                         <Button
-                          {...('href' in subItem && subItem.href && { href: subItem.href })}
+                          {...('href' in subItem &&
+                            subItem.href && {
+                              href: subItem.href,
+                              target: subItem.blank ? '_blank' : undefined,
+                            })}
                           title={i18n(subItem.text)}
                           class="btn-ghost btn-primary rounded-field"
                         >
@@ -57,7 +61,11 @@ if (!title) title = 'Astral Halo';
             } else {
               return (
                 <Button
-                  {...('href' in item && item.href && { href: item.href })}
+                  {...('href' in item &&
+                    item.href && {
+                      href: item.href,
+                      target: item.blank ? '_blank' : undefined,
+                    })}
                   title={i18n(item.text)}
                   class="btn-ghost join-item btn-primary"
                 >
@@ -132,7 +140,11 @@ if (!title) title = 'Astral Halo';
                     {item.items.map((subItem) => (
                       <li>
                         <Button
-                          {...('href' in subItem && subItem.href && { href: subItem.href })}
+                          {...('href' in subItem &&
+                            subItem.href && {
+                              href: subItem.href,
+                              target: subItem.blank ? '_blank' : undefined,
+                            })}
                           title={i18n(subItem.text)}
                           class="btn-ghost"
                         >
@@ -148,7 +160,11 @@ if (!title) title = 'Astral Halo';
             return (
               <li>
                 <Button
-                  {...('href' in item && item.href && { href: item.href })}
+                  {...('href' in item &&
+                    item.href && {
+                      href: item.href,
+                      target: item.blank ? '_blank' : undefined,
+                    })}
                   title={i18n(item.text)}
                   class="btn-ghost"
                 >
src/components/SideToolBar.astro
@@ -46,7 +46,7 @@ import TocButton from './widgets/SideToolBar/TocButton.vue';
         const { icon, text } = item;
         if ('href' in item)
           return (
-            <Button href={item.href} title={text}>
+            <Button href={item.href} target={item.blank ? '_blank' : undefined} title={text}>
               <Icon name={icon} slot="icon" />
             </Button>
           );
src/types/config.ts
@@ -32,6 +32,14 @@ export type ButtonSubConfig<T extends string> = T extends 'text'
            * 按钮的 URL。
            */
           href?: string;
+          /**
+           * Whether to open the link in a new tab.
+           *
+           * 是否在新标签页中打开链接。
+           *
+           * @default false
+           */
+          blank?: boolean;
         }
       | {
           /**
@@ -69,6 +77,14 @@ export type ButtonSubConfig<T extends string> = T extends 'text'
              * 按钮的 URL。
              */
             href?: string;
+            /**
+             * Whether to open the link in a new tab.
+             *
+             * 是否在新标签页中打开链接。
+             *
+             * @default false
+             */
+            blank?: boolean;
           }
         | {
             /**
src/config.ts
@@ -106,6 +106,7 @@ export const navbarConfig: NavbarConfig = {
         icon: 'material-symbols:rss-feed-rounded',
         text: I18nKey.subscribe,
         href: '/rss.xml',
+        blank: true,
       },
       {
         icon: 'material-symbols:casino',