From c4d5815740949945e8d2c47dc4b41a81cde870c3 Mon Sep 17 00:00:00 2001 From: Ayo Ayco Date: Mon, 12 Jun 2023 21:39:54 +0200 Subject: [PATCH] fix+style: errors got cached (#35) --- src/components/Library.astro | 108 ++++++++++------------------------- src/pages/index.astro | 6 +- src/utils/library-utils.ts | 71 +++++++++++++++++++++++ 3 files changed, 103 insertions(+), 82 deletions(-) create mode 100644 src/utils/library-utils.ts diff --git a/src/components/Library.astro b/src/components/Library.astro index e3c070b..a761568 100644 --- a/src/components/Library.astro +++ b/src/components/Library.astro @@ -7,7 +7,6 @@ export interface Props { const {postDivSelector, skipSave = false} = Astro.props; ---
-

@@ -15,6 +14,7 @@ const {postDivSelector, skipSave = false} = Astro.props; diff --git a/src/pages/index.astro b/src/pages/index.astro index 83ef006..732d959 100644 --- a/src/pages/index.astro +++ b/src/pages/index.astro @@ -19,7 +19,7 @@ try { article = await extract(url); if (!article ) { article = error; - skipSave = true; + // skipSave = true; } } catch { article = error; @@ -38,11 +38,11 @@ if (url === '') { --- -
{ url ? : - +
} +
diff --git a/src/utils/library-utils.ts b/src/utils/library-utils.ts new file mode 100644 index 0000000..c6e9086 --- /dev/null +++ b/src/utils/library-utils.ts @@ -0,0 +1,71 @@ +export function getPostCard(html: HTMLHtmlElement) { + const title = + html + .querySelector('meta[property="cozy:title"]') + ?.getAttribute("content") || + html.querySelector("title")?.innerHTML?.replace("Cozy 🧸 | ", ""); + + const description = html + .querySelector('meta[property="cozy:description"]') + ?.getAttribute("content"); + const image = html + .querySelector('meta[property="cozy:image"]') + ?.getAttribute("content"); + const url = html + .querySelector('meta[property="cozy:url"]') + ?.getAttribute("content"); + const source = html + .querySelector('meta[property="cozy:source"]') + ?.getAttribute("content"); + const published = html + .querySelector('meta[property="cozy:published"]') + ?.getAttribute("content"); + + const postCard = ` +
+
+ ${ + image + ? ` + ${title} | ${description} + ` + : '' + } +
+
+ ${ + source || published + ? ` +
+ ${ + source + ? ` +

${source}

+ ` + : "" + } + ${ + published + ? ` +

${ + new Date(published)?.toLocaleDateString() || "" + }

+ ` + : "" + } +
+ ` + : "" + } +

${title}

+ ${ + description + ? ` +

${description}

` + : "" + } +
+
+ `; + return postCard; +}