diff --git a/src/components/Library.astro b/src/components/Library.astro
index 5bb9826..3fd259b 100644
--- a/src/components/Library.astro
+++ b/src/components/Library.astro
@@ -22,53 +22,141 @@ const {postDivSelector, skipSave = false} = Astro.props;
const skipSave = document.getElementById('skipSave') as HTMLInputElement;
const postDiv = document.querySelector(postDivSelector?.value);
- if (!response && !skipSave.checked) {
+ if (!response && !skipSave?.checked) {
+ console.log('skip?', skipSave?.checked)
await cache.add(url);
}
const cachedResponses = await cache.keys();
const list = document.querySelector('#post-list');
- if (cachedResponses.length) {
- const heading = document.querySelector('#library h2') as HTMLHeadingElement;
- heading.innerText = 'Previously viewed:';
- }
+ if(cachedResponses?.length) {
+ const headingEl = document.querySelector('#library h2');
+ if(headingEl)
+ headingEl.innerHTML = 'Previously Viewed';
- cachedResponses
- .filter(request => {
- const urlObj = new URL(request.url);
- return urlObj.search !== '';
- })
- .reverse()
- .forEach(async (request) => {
- const {url} = request;
- const link = document.createElement('a');
+ cachedResponses
+ .filter(request => {
+ const urlObj = new URL(request.url);
+ return urlObj.search !== '';
+ })
+ .reverse()
+ .forEach(async (request) => {
+ const {url} = request;
+ const link = document.createElement('a');
- let responseText;
+ let responseText;
- const fullResponse = await cache.match(url)
- fullResponse?.text().then(data => {
- responseText = data;
- const html = document.createElement('html');
- html.innerHTML = responseText;
- const title = html.querySelector('title');
- link.innerText = (title?.innerText || url).replace('Cozy 🧸 | ', '');
- });
-
- link.href = url;
- link.onclick = async (e) => {
- e.preventDefault();
- scroll(0,0);
+ const fullResponse = await cache.match(url)
+ fullResponse?.text().then(data => {
+ responseText = data;
const html = document.createElement('html');
html.innerHTML = responseText;
- const newPost = html.querySelector('body')?.querySelector('#post');
- if (postDiv && newPost?.innerHTML) {
- postDiv.innerHTML = newPost.innerHTML
- }
- }
- const item = document.createElement('li');
- item.appendChild(link);
- list?.appendChild(item);
- });
+ const title = html.querySelector('title');
+ const postCard = getPostCard(html);
+ link.innerHTML = postCard;
+ });
-
\ No newline at end of file
+ link.href = url;
+ link.onclick = async (e) => {
+ e.preventDefault();
+ scroll(0,0);
+ const html = document.createElement('html');
+ html.innerHTML = responseText;
+ const newPost = html.querySelector('body')?.querySelector('#post');
+ if (postDiv && newPost?.innerHTML) {
+ postDiv.innerHTML = newPost.innerHTML
+ }
+ }
+ const item = document.createElement('li');
+ item.appendChild(link);
+ list?.appendChild(item);
+ });
+ }
+
+
+ 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 postCard = `
+
+ ${
+ image ? `
+
+

+
+ `
+ : ''
+ }
+
+ ${
+ source ? `
+
${source}
+ `
+ : ''
+ }
+
${title}
+ ${
+ description ? `
+
${description}
`
+ : ''
+ }
+
+
+ `;
+ return postCard;
+ }
+
+
+
\ No newline at end of file
diff --git a/src/components/Post.astro b/src/components/Post.astro
index 8b6a846..f2c55e6 100644
--- a/src/components/Post.astro
+++ b/src/components/Post.astro
@@ -24,14 +24,14 @@ const datePublished =
)
}
-
-
-
\ No newline at end of file
diff --git a/src/layouts/Layout.astro b/src/layouts/Layout.astro
index b9a0093..4c0ee61 100644
--- a/src/layouts/Layout.astro
+++ b/src/layouts/Layout.astro
@@ -1,10 +1,11 @@
---
+import { ArticleData } from "@extractus/article-extractor";
import "./reset.css";
export interface Props {
- title?: string;
+ meta: ArticleData
}
const appTitle = "Cozy 🧸";
-const { title } = Astro.props;
+const { meta } = Astro.props;
---
@@ -13,7 +14,14 @@ const { title } = Astro.props;
- {appTitle} {title && `| ${title}`}
+ {appTitle} {meta.title && `| ${meta.title}`}
+
+
+
+
+
+
+
@@ -30,28 +38,12 @@ const { title } = Astro.props;
diff --git a/src/pages/index.astro b/src/pages/index.astro
index 87ab057..83ef006 100644
--- a/src/pages/index.astro
+++ b/src/pages/index.astro
@@ -30,13 +30,19 @@ if (url === '') {
article = {
title: "Welcome to Cozy 🧸",
content: "Enter a URL above to get started.
",
+ url: '/'
};
skipSave = true;
}
---
-
+
-
-
+
+ {
+ url
+ ?
+ :
+
+ }