mirror of
https://github.com/Tony0410/readlater.git
synced 2026-05-24 22:01:41 +08:00
Add article publish date to list and reader views
Extract publication dates from HTML meta tags when saving articles and display them prominently in the article list and reader header. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -33,6 +33,7 @@ export interface ExtractedArticle {
|
||||
textContent: string;
|
||||
leadImage: string | null;
|
||||
wordCount: number;
|
||||
publishedAt: Date | null;
|
||||
}
|
||||
|
||||
export async function extractArticle(url: string): Promise<ExtractedArticle> {
|
||||
@@ -86,6 +87,34 @@ export async function extractArticle(url: string): Promise<ExtractedArticle> {
|
||||
leadImage = ogImage.getAttribute("content");
|
||||
}
|
||||
|
||||
// Try to find publish date from various meta tags
|
||||
let publishedAt: Date | null = null;
|
||||
const dateSelectors = [
|
||||
'meta[property="article:published_time"]',
|
||||
'meta[name="article:published_time"]',
|
||||
'meta[property="og:published_time"]',
|
||||
'meta[name="pubdate"]',
|
||||
'meta[name="publishdate"]',
|
||||
'meta[name="date"]',
|
||||
'meta[itemprop="datePublished"]',
|
||||
'time[datetime]',
|
||||
'time[pubdate]',
|
||||
];
|
||||
|
||||
for (const selector of dateSelectors) {
|
||||
const el = document.querySelector(selector);
|
||||
if (el) {
|
||||
const dateStr = el.getAttribute("content") || el.getAttribute("datetime");
|
||||
if (dateStr) {
|
||||
const parsed = new Date(dateStr);
|
||||
if (!isNaN(parsed.getTime())) {
|
||||
publishedAt = parsed;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const textContent = article.textContent || "";
|
||||
const content = article.content || "";
|
||||
|
||||
@@ -101,6 +130,7 @@ export async function extractArticle(url: string): Promise<ExtractedArticle> {
|
||||
textContent,
|
||||
leadImage,
|
||||
wordCount,
|
||||
publishedAt,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -132,6 +162,34 @@ export async function extractFromHtml(
|
||||
leadImage = ogImage.getAttribute("content");
|
||||
}
|
||||
|
||||
// Try to find publish date from various meta tags
|
||||
let publishedAt: Date | null = null;
|
||||
const dateSelectors = [
|
||||
'meta[property="article:published_time"]',
|
||||
'meta[name="article:published_time"]',
|
||||
'meta[property="og:published_time"]',
|
||||
'meta[name="pubdate"]',
|
||||
'meta[name="publishdate"]',
|
||||
'meta[name="date"]',
|
||||
'meta[itemprop="datePublished"]',
|
||||
'time[datetime]',
|
||||
'time[pubdate]',
|
||||
];
|
||||
|
||||
for (const selector of dateSelectors) {
|
||||
const el = document.querySelector(selector);
|
||||
if (el) {
|
||||
const dateStr = el.getAttribute("content") || el.getAttribute("datetime");
|
||||
if (dateStr) {
|
||||
const parsed = new Date(dateStr);
|
||||
if (!isNaN(parsed.getTime())) {
|
||||
publishedAt = parsed;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const textContent = article.textContent || "";
|
||||
const content = article.content || "";
|
||||
|
||||
@@ -147,5 +205,6 @@ export async function extractFromHtml(
|
||||
textContent,
|
||||
leadImage,
|
||||
wordCount,
|
||||
publishedAt,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user