feat(header): custom links

This commit is contained in:
hamster1963 2024-11-19 14:34:40 +08:00
parent 2b10bd4510
commit 271e0c5b60
3 changed files with 34 additions and 0 deletions

View File

@ -12,6 +12,7 @@ NEXT_PUBLIC_FixedTopServerName=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://github.com/hamster1963/nezha-dash","name":"GitHub"},{"link":"https://buycoffee.top/coffee","name":"Buycoffee☕"}]"
NEXT_PUBLIC_DisableIndex=false NEXT_PUBLIC_DisableIndex=false
NEXT_PUBLIC_BASE_PATH=/ NEXT_PUBLIC_BASE_PATH=/
NEXT_PUBLIC_ShowTagCount=false NEXT_PUBLIC_ShowTagCount=false

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,37 @@ 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;
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: () => void, delay: number | null) => { const useInterval = (callback: () => void, delay: number | null) => {
const savedCallback = useRef<() => void>(() => {}); const savedCallback = useRef<() => void>(() => {});

View File

@ -12,5 +12,6 @@ NEXT_PUBLIC_FixedTopServerName=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://github.com/hamster1963/nezha-dash","name":"GitHub"},{"link":"https://buycoffee.top/coffee","name":"Buycoffee☕"}]"
NEXT_PUBLIC_DisableIndex=false NEXT_PUBLIC_DisableIndex=false
NEXT_PUBLIC_ShowTagCount=false NEXT_PUBLIC_ShowTagCount=false