Skip to content

Commit

Permalink
Refactored lib
Browse files Browse the repository at this point in the history
  • Loading branch information
hopperelec committed Nov 11, 2023
1 parent 74d7d61 commit 3bfce9c
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 15 deletions.
File renamed without changes.
File renamed without changes.
9 changes: 8 additions & 1 deletion src/lib/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,11 @@ export const SITE_DESCRIPTION =
export const BASE_URL = env["PUBLIC_BASE_URL"] || "http://localhost:5173";
export const BRAND_COLOR = "#c41313";

export default { SITE_NAME, SITE_DESCRIPTION, BASE_URL, BRAND_COLOR };
const constants = { SITE_NAME, SITE_DESCRIPTION, BASE_URL, BRAND_COLOR };

export function insertInto(text: string): string {
for (const [key, value] of Object.entries(constants)) {
text = text.replaceAll("%" + key + "%", value);
}
return text;
}
8 changes: 0 additions & 8 deletions src/lib/insert_constants.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/routes/+layout.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script lang="ts">
import { page } from "$app/stores";
import LogoText from "$lib/LogoText.svelte";
import LogoText from "$lib/components/LogoText.svelte";
import { title } from "$lib/title";
import { BRAND_COLOR } from "$lib/constants";
const links: { [key: string]: string } = {
Expand Down
3 changes: 2 additions & 1 deletion src/routes/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<script>
import { title } from "$lib/title";
import Slideshow from "$lib/Slideshow.svelte";
import Slideshow from "$lib/components/Slideshow.svelte";
title.set("Home");
</script>

Expand Down
4 changes: 2 additions & 2 deletions src/routes/robots.txt/+server.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { RequestHandler } from "@sveltejs/kit";
import robots from "./robots.txt?raw";
import insert_constants from "$lib/insert_constants";
import { insertInto } from "$lib/constants";

export const GET: RequestHandler = async () => {
return new Response(insert_constants(robots));
return new Response(insertInto(robots));
};
4 changes: 2 additions & 2 deletions src/routes/site.webmanifest/+server.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { RequestHandler } from "@sveltejs/kit";
import manifest from "./site.webmanifest?raw";
import insert_constants from "$lib/insert_constants";
import { insertInto } from "$lib/constants";

export const GET: RequestHandler = async () => {
return new Response(insert_constants(manifest));
return new Response(insertInto(manifest));
};

0 comments on commit 3bfce9c

Please sign in to comment.