feat: simple url validation
This commit is contained in:
parent
e9fc737ce3
commit
695b9d337c
5 changed files with 17 additions and 10 deletions
|
@ -8,7 +8,10 @@ export interface Props {
|
|||
}
|
||||
---
|
||||
|
||||
<h2>{article.title}</h2>
|
||||
<p>by <em>{article.author}</em></p>
|
||||
|
||||
<span set:html={article.content} />
|
||||
{
|
||||
article ? (
|
||||
<h2>{article.title}</h2>
|
||||
<p>by <em>{article.author}</em></p>
|
||||
<span set:html={article.content} />
|
||||
) : ''
|
||||
}
|
||||
|
|
|
@ -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([
|
||||
{
|
||||
|
|
|
@ -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(
|
||||
|
|
2
src/utils/index.ts
Normal file
2
src/utils/index.ts
Normal file
|
@ -0,0 +1,2 @@
|
|||
export * from "./get-params";
|
||||
export * from "./is-url";
|
4
src/utils/is-url.ts
Normal file
4
src/utils/is-url.ts
Normal file
|
@ -0,0 +1,4 @@
|
|||
export function isURL(str: string): boolean {
|
||||
// TODO: improve pls
|
||||
return str.includes("http://") || str.includes("https://");
|
||||
}
|
Loading…
Reference in a new issue