remove is-url checker

we get url validation for free with `extract`
This commit is contained in:
Ayo 2023-05-27 10:10:40 +02:00
parent f72610d16c
commit f196df0068
4 changed files with 8 additions and 11 deletions

View file

@ -4,7 +4,7 @@ export interface Props {
article: ArticleData; article: ArticleData;
} }
const article = Astro.props.article; const { article } = Astro.props;
const datePublished = const datePublished =
article?.published && new Date(article.published).toDateString(); article?.published && new Date(article.published).toDateString();
--- ---

View file

@ -1,19 +1,22 @@
--- ---
import { extract } from "@extractus/article-extractor"; import { extract } from "@extractus/article-extractor";
import { getParams, isURL } from "../utils"; import { getParams } from "../utils";
import AddressBar from "../components/address-bar.astro"; import AddressBar from "../components/address-bar.astro";
import Post from "../components/post.astro"; import Post from "../components/post.astro";
import Layout from "../layouts/layout.astro"; import Layout from "../layouts/layout.astro";
// temporary default content while we don't have any good thing to put yet :)
const defaultUrl = "https://github.com/ayoayco/cozy-reader";
const params = getParams(Astro.url); const params = getParams(Astro.url);
const url = params?.url; const url = params?.url || defaultUrl;
let article; let article;
try { try {
article = isURL(url) && (await extract(url)); article = await extract(url);
} catch { } catch {
article = { article = {
title: "Something is not right", title: "Something is not right",
content: "<p>The article extractor did not get any result</p>", content: "<p>The article extractor did not get any result.</p>",
}; };
} }
--- ---

View file

@ -1,2 +1 @@
export * from "./get-params"; export * from "./get-params";
export * from "./is-url";

View file

@ -1,5 +0,0 @@
export function isURL(str: string): boolean {
// TODO: improve pls
if (!str) return false;
return str.includes("http://") || str.includes("https://");
}