Fetch title and author from page metadate if possible

This commit is contained in:
Jackson Harper 2022-03-03 15:20:58 -08:00
parent b17f22949c
commit c2e08d0e8f
2 changed files with 19 additions and 3 deletions

View file

@ -50,8 +50,9 @@ export const saveEmail = async (
originalHtml: input.originalContent,
content: content,
description: metadata?.description || parseResult.parsedContent?.excerpt,
title: parseResult.parsedContent?.title || title,
author: parseResult.parsedContent?.byline || input.author,
title: metadata?.title || parseResult.parsedContent?.title || title,
author:
metadata?.author || parseResult.parsedContent?.byline || input.author,
url: normalizeUrl(parseResult.canonicalUrl || url, {
stripHash: true,
stripWWW: false,

View file

@ -346,6 +346,8 @@ const getJSONLdLinkMetadata = async (
}
type Metadata = {
title?: string
author?: string
description: string
previewImage: string
}
@ -368,7 +370,20 @@ export const parseMetadata = async (
.querySelector("head meta[property='og:image']")
?.getAttribute('content') || ''
return { description: description, previewImage: previewImage }
const title =
window.document
.querySelector("head meta[property='og:title']")
?.getAttribute('content') || undefined
const author =
window.document
.querySelector("head meta[property='author']")
?.getAttribute('content') || undefined
// TODO: we should be able to apply the JSONLD metadata
// here too
return { title, author, description, previewImage }
} catch (e) {
console.log('failed to got:', url, e)
return undefined