feat: add header links

This commit is contained in:
hamster1963 2024-10-25 01:16:59 +08:00
parent d41db008f5
commit c20740a152
2 changed files with 42 additions and 0 deletions

View File

@ -11,3 +11,4 @@ NEXT_PUBLIC_ForceUseSvgFlag=false
NEXT_PUBLIC_CustomLogo=https://nezha-cf.buycoffee.top/apple-touch-icon.png NEXT_PUBLIC_CustomLogo=https://nezha-cf.buycoffee.top/apple-touch-icon.png
NEXT_PUBLIC_CustomTitle=NezhaDash NEXT_PUBLIC_CustomTitle=NezhaDash
NEXT_PUBLIC_CustomDescription=NezhaDash is a dashboard for Nezha. NEXT_PUBLIC_CustomDescription=NezhaDash is a dashboard for Nezha.
NEXT_PUBLIC_Links=[{"link":"https://baidu.com","name":"Baidu"},{"link":"https://google.com","name":"Google"}]

View File

@ -51,6 +51,7 @@ function Header() {
</p> </p>
</section> </section>
<section className="flex items-center gap-2"> <section className="flex items-center gap-2">
<Links />
<LanguageSwitcher /> <LanguageSwitcher />
<ModeToggle /> <ModeToggle />
</section> </section>
@ -60,6 +61,46 @@ function Header() {
); );
} }
type links = {
link: string;
name: string;
};
function Links() {
const linksEnv = getEnv("NEXT_PUBLIC_Links");
const links: links[] | null = linksEnv
? JSON.parse(linksEnv)
: null;
console.log(links);
if (!links) return null;
return (
<div className="flex items-center gap-2">
{links.map((link, index) => {
return (
<a
key={index}
href={link.link}
target="_blank"
rel="noopener noreferrer"
className="flex items-center gap-1 text-sm font-medium opacity-50 transition-opacity hover:opacity-100"
>
{link.name}
</a>
)
})}
</div>
)
}
// https://github.com/streamich/react-use/blob/master/src/useInterval.ts // https://github.com/streamich/react-use/blob/master/src/useInterval.ts
const useInterval = (callback: Function, delay?: number | null) => { const useInterval = (callback: Function, delay?: number | null) => {
const savedCallback = useRef<Function>(() => { }); const savedCallback = useRef<Function>(() => { });