diff --git a/src/components/article.astro b/src/components/article.astro index ff809e1..a0c8315 100644 --- a/src/components/article.astro +++ b/src/components/article.astro @@ -8,7 +8,10 @@ export interface Props { } --- -
by {article.author}
- - +{ +article ? ( +by {article.author}
+ + ) : '' +} diff --git a/src/pages/index.astro b/src/pages/index.astro index 65c634e..a005dae 100644 --- a/src/pages/index.astro +++ b/src/pages/index.astro @@ -1,13 +1,13 @@ --- import Form, { FormGroup } from "@astro-reactive/form"; import { Validators } from "@astro-reactive/validator"; -import getParams from "../utils/get-params"; import { extract } from "@extractus/article-extractor"; import Article from "../components/article.astro"; +import { getParams, isURL } from "../utils"; const params = getParams(Astro.url); -const url = params?.url; -const article = await extract(url); +const url: string = params?.url; +const article = isURL(url) && (await extract(url)); const form = new FormGroup([ { diff --git a/src/utils/get-params.ts b/src/utils/get-params.ts index 5442d84..ef68b75 100644 --- a/src/utils/get-params.ts +++ b/src/utils/get-params.ts @@ -1,6 +1,4 @@ -export default function getParams( - url: URL -): { [key: string]: string } | undefined { +export function getParams(url: URL): { [key: string]: string } | undefined { if (url.search === "") return; return Object.fromEntries( diff --git a/src/utils/index.ts b/src/utils/index.ts new file mode 100644 index 0000000..a213a7d --- /dev/null +++ b/src/utils/index.ts @@ -0,0 +1,2 @@ +export * from "./get-params"; +export * from "./is-url"; diff --git a/src/utils/is-url.ts b/src/utils/is-url.ts new file mode 100644 index 0000000..56c62e6 --- /dev/null +++ b/src/utils/is-url.ts @@ -0,0 +1,4 @@ +export function isURL(str: string): boolean { + // TODO: improve pls + return str.includes("http://") || str.includes("https://"); +}