From 2d354e8401abf10e8340c13417eda7441fafd7cd Mon Sep 17 00:00:00 2001 From: Lio Date: Tue, 23 Jul 2024 19:55:50 +0200 Subject: [PATCH] move other options to ENV --- src/components/Social.astro | 11 ++++++----- src/layouts/Index.astro | 3 +-- src/lib/boolify.ts | 17 +++++++++++++++++ 3 files changed, 24 insertions(+), 7 deletions(-) create mode 100644 src/lib/boolify.ts diff --git a/src/components/Social.astro b/src/components/Social.astro index 974bcd0..ecf63de 100644 --- a/src/components/Social.astro +++ b/src/components/Social.astro @@ -1,19 +1,20 @@ --- -import config from "../../config.yaml"; +import { Boolify } from "../lib/boolify"; const { href, text, icon } = Astro.props; +const useIcons = Boolify(import.meta.env.PUBLIC_USEICONS); --- { - config.socialIcons && ( + useIcons && ( - + ) } { - !config.socialIcons && ( + !useIcons && ( - + {text} ) } diff --git a/src/layouts/Index.astro b/src/layouts/Index.astro index 6115231..9785596 100644 --- a/src/layouts/Index.astro +++ b/src/layouts/Index.astro @@ -1,5 +1,4 @@ --- -import config from "../../config.yaml"; import pb from "../lib/pb"; export const prerender = false const backgroundRec = await pb.collection('images').getFirstListItem('useAsBackground=true'); @@ -15,7 +14,7 @@ const background = await pb.files.getUrl(backgroundRec, backgroundRec.file); - {config.title} + {import.meta.env.PUBLIC_TITLE} diff --git a/src/lib/boolify.ts b/src/lib/boolify.ts new file mode 100644 index 0000000..be59757 --- /dev/null +++ b/src/lib/boolify.ts @@ -0,0 +1,17 @@ +var BoolArray = [true, false, 'true', 'false', 1, 0]; +const isBoolean = function (arg) { + if (BoolArray.indexOf(arg) === -1) { + return false; + } else { + return true; + } +} +const Boolify = function (arg) { + if (BoolArray.indexOf(arg) === -1) { + return null; + } else { + return (arg == true || arg == 'true' || arg == 1) ? true : false; + } +} + +export { isBoolean, Boolify }; \ No newline at end of file