Skip to content

Commit

Permalink
Socials.svelte: split data and model
Browse files Browse the repository at this point in the history
  • Loading branch information
jimmy-zhening-luo committed Feb 2, 2025
1 parent 95f2bf4 commit d166022
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 47 deletions.
14 changes: 1 addition & 13 deletions src/routes/_social/Socials.svelte
Original file line number Diff line number Diff line change
@@ -1,18 +1,6 @@
<script
lang="ts">
import SocialsMenu from "./Socials";
const socials = SocialsMenu([
"Instagram",
"Facebook",
"Substack",
"GitHub",
"YouTube",
"Spotify",
"SoundCloud",
"Duolingo",
"LinkedIn",
]);
import { socials } from "./Socials";
</script>

<style
Expand Down
44 changes: 13 additions & 31 deletions src/routes/_social/Socials.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,13 @@
import { SocialButton } from "./button";
import { SocialManifest } from "./manifest";
import { SocialIcons } from "./lib";

export default function (apps: readonly SocialApp[]) {
if (new Set(apps).size !== apps.length)
throw new RangeError("Duplicate social menu buttons");

function assemble(app: SocialApp) {
const {
host,
username = "",
path: {
pre = "",
post = "",
} = {},
} = SocialManifest[app],
icon = SocialIcons[app];

return new SocialButton(
app,
host,
username,
pre,
post,
icon,
);
}

return apps.map(app => assemble(app));
}
import menu from "./menu";

export const socials = menu([
"Instagram",
"Facebook",
"Substack",
"GitHub",
"YouTube",
"Spotify",
"SoundCloud",
"Duolingo",
"LinkedIn",
]);
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
export const SocialManifest: Record<
export { icons } from "./lib";

export const manifest: Record<
SocialApp,
{
host: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import Spotify from "$lib/images/socials/spotify.svg";
import Substack from "$lib/images/socials/substack.svg";
import YouTube from "$lib/images/socials/youtube.svg";

export const SocialIcons: Record<SocialApp, string> = {
export const icons: Record<SocialApp, string> = {
Duolingo,
Facebook,
GitHub,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export class SocialButton {
export class Button {
public readonly url: string;

constructor(
Expand Down
29 changes: 29 additions & 0 deletions src/routes/_social/menu/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { Button } from "./button";
import { manifest, icons } from "../apps";

export function menu(apps: readonly SocialApp[]) {
if (new Set(apps).size !== apps.length)
throw new RangeError("Duplicate social menu buttons");

function assemble(app: SocialApp) {
const {
host,
username = "",
path: {
pre = "",
post = "",
} = {},
} = manifest[app],

return new Button(
app,
host,
username,
pre,
post,
icons[app],
);
}

return apps.map(app => assemble(app));
}

0 comments on commit d166022

Please sign in to comment.