simple-links/src/app/page.tsx

190 lines
6.1 KiB
TypeScript
Raw Normal View History

2023-07-13 09:39:37 +00:00
import { Config } from "@/src/types/config";
import { library } from "@fortawesome/fontawesome-svg-core";
import { fab } from "@fortawesome/free-brands-svg-icons";
import { far } from "@fortawesome/free-regular-svg-icons";
import { fas } from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
2023-07-02 11:02:11 +00:00
import Image from "next/image";
2023-10-14 16:45:04 +00:00
import Link from "next/link";
2023-07-12 16:58:47 +00:00
import Avatar from "./components/Avatar";
2023-07-01 21:08:39 +00:00
2023-07-13 09:39:37 +00:00
const Config: Config = require("../../config.yml") as any;
library.add(fab, far, fas); // Loading in the icons from FontAwesome
2023-07-01 20:43:53 +00:00
export default function Home() {
2023-07-10 04:06:28 +00:00
const {
background,
infoCard,
avatar,
name,
links,
2023-07-12 08:40:24 +00:00
socialLinks,
2023-07-10 04:06:28 +00:00
options,
description,
2023-07-12 08:40:24 +00:00
theme,
2023-07-10 04:06:28 +00:00
} = Config; // All of the settings pulled from the config file
2023-07-10 02:54:12 +00:00
2023-07-10 04:06:28 +00:00
// Theme colors to use when using the selected theme
// all used colors are from TailwindCSS
const themeColors: {
[key: string]: {
backgroundColor: string;
2023-07-12 10:04:55 +00:00
infoCardColor: string;
2023-07-10 04:06:28 +00:00
textColor: string;
buttonTextColor: string;
2023-07-12 10:04:55 +00:00
footerTextColor: string;
2023-07-10 04:06:28 +00:00
};
} = {
dark: {
2023-07-12 10:04:55 +00:00
backgroundColor: "bg-neutral-800",
infoCardColor: "bg-neutral-900",
2023-07-10 04:06:28 +00:00
textColor: "text-white",
buttonTextColor: "text-white",
2023-07-12 10:04:55 +00:00
footerTextColor: "text-blue-300",
2023-07-10 04:06:28 +00:00
},
light: {
2023-07-12 10:04:55 +00:00
backgroundColor: "bg-gray-300",
infoCardColor: "bg-white",
2023-07-10 04:06:28 +00:00
textColor: "text-black",
buttonTextColor: "text-white",
2023-07-12 10:04:55 +00:00
footerTextColor: "text-black",
2023-07-10 04:06:28 +00:00
},
};
2023-07-10 04:15:39 +00:00
const selectedTheme = themeColors[theme] || themeColors.dark; // The theme to use (fallback of dark)
2023-07-09 06:19:08 +00:00
2023-07-10 04:06:28 +00:00
return (
<>
<main
2023-07-12 10:04:55 +00:00
className={`flex flex-col items-center justify-center w-screen h-screen ${selectedTheme.backgroundColor} ${selectedTheme.textColor}`}
2023-07-10 04:06:28 +00:00
>
{/* Background Image */}
{background.showBackground && background.backgroundImage && (
<Image
alt="Background image"
src={background.backgroundImage}
fill={true}
style={{
zIndex: 0,
filter: `${background.blur && "blur(4px)"} brightness(${
background.darken.enabled && background.darken.amount / 2
})`,
}}
/>
)}
2023-08-02 01:10:40 +00:00
{/* Info Card */}
2023-07-10 04:06:28 +00:00
<div
className={`${
infoCard.transparency != 0
? `${selectedTheme.infoCardColor} shadow-lg rounded-lg`
: ``
} text-center`}
2023-07-10 04:06:28 +00:00
style={{
zIndex: 1,
opacity: infoCard.transparency != 0 ? infoCard.transparency : 1,
2023-07-10 04:06:28 +00:00
}}
>
<div className="m-5">
<div className="flex flex-col items-center justify-center">
2023-07-12 16:58:47 +00:00
<Avatar avatar={avatar} />
2023-07-10 04:06:28 +00:00
<div className="mb-3"></div>
<h1 className="text-4xl font-bold">{name}</h1>
</div>
2023-07-01 21:08:39 +00:00
2023-07-12 08:40:24 +00:00
{/* Description of user */}
2023-07-10 04:06:28 +00:00
<p className="mt-4 text-lg max-w-lg">{description}</p>
2023-07-01 20:43:53 +00:00
2023-07-12 08:40:24 +00:00
{/* Links (Buttons) */}
2023-07-10 04:06:28 +00:00
<div className="flex flex-col items-center">
2023-07-12 08:41:04 +00:00
{links &&
links.map((link, index) => {
const icons: any = link.icon?.split(" ") ?? [];
2023-07-12 10:18:31 +00:00
let color: any = link.color;
// Here so old configs don't break
if (color.normal != undefined) {
color = color.normal;
} else {
color = link.color;
}
2023-07-12 08:41:04 +00:00
return (
<a
key={index}
href={link.url}
target="_blank"
rel="noopener noreferrer"
className={`flex flex-row items-center justify-center mt-4 px-4 w-60 py-2 rounded
2023-08-02 01:10:40 +00:00
${selectedTheme.buttonTextColor} ${color} hover:brightness-75 transition gap-2 shadow-lg`}
style={{
opacity:
infoCard.transparency != 0
? infoCard.transparency
: 0.8,
}}
2023-07-12 08:41:04 +00:00
>
{link.icon && <FontAwesomeIcon icon={icons} />}
<p>{link.title}</p>
</a>
);
})}
2023-07-10 04:06:28 +00:00
</div>
2023-07-12 08:40:24 +00:00
{/* Social Links */}
<div className="flex items-center justify-center gap-3 mt-4">
{socialLinks &&
socialLinks.map((link, index) => {
const icons: any = link.icon?.split(" ") ?? [];
return (
<a
key={index}
href={link.url}
target="_blank"
rel="noopener noreferrer"
2023-08-02 01:10:40 +00:00
className="hover:brightness-75 transition shadow-lg"
style={{
opacity:
infoCard.transparency != 0
? infoCard.transparency
: 0.8,
}}
2023-07-12 08:40:24 +00:00
>
2023-07-12 09:02:26 +00:00
{link.icon && (
<FontAwesomeIcon
color={link.color && link.color}
size="2xl"
icon={icons}
/>
)}
2023-07-12 08:40:24 +00:00
</a>
);
})}
</div>
2023-07-10 04:06:28 +00:00
</div>
</div>
2023-07-12 08:40:24 +00:00
{/* Footer */}
2023-07-12 10:04:55 +00:00
<div
className={`absolute bottom-0 right-0 mb-5 mr-5 ${selectedTheme.footerTextColor}`}
>
2023-07-10 04:06:28 +00:00
{options.showSourceLink && (
2023-10-14 16:45:04 +00:00
<Link
2023-07-10 04:06:28 +00:00
href="https://git.fascinated.cc/Fascinated/simple-links"
target="_blank"
2023-07-12 10:04:55 +00:00
className="mt-5"
2023-07-10 04:06:28 +00:00
>
2023-10-14 16:45:04 +00:00
<Image
src="https://cdn.fascinated.cc/assets/simple-links/icon.png"
alt="Simple Links Icon"
width={32}
height={32}
/>
</Link>
2023-07-10 04:06:28 +00:00
)}
</div>
</main>
</>
);
2023-07-01 20:43:53 +00:00
}