Skip to content

Commit

Permalink
Use metascraper-amazon
Browse files Browse the repository at this point in the history
  • Loading branch information
otoyo committed Aug 22, 2023
1 parent b8a878f commit bbc5cea
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions src/components/notion-blocks/Bookmark.astro
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import createMetascraper from 'metascraper'
import metascraperDescription from 'metascraper-description'
import metascraperImage from 'metascraper-image'
import metascraperTitle from 'metascraper-title'
import metascraperAmazon from 'metascraper-amazon'
import * as interfaces from '../../lib/interfaces.ts'
export interface Props {
Expand All @@ -13,16 +14,26 @@ export interface Props {
const { block, urlMap } = Astro.props
const urlString = (block.Bookmark || block.LinkPreview || block.Embed).Url
const metascraper = createMetascraper([
metascraperDescription(),
metascraperImage(),
metascraperTitle(),
])
let url: URL
let metadata: Record<string, string>
try {
url = new URL(urlString)
let rules = []
if (
url.hostname === 'amazon.com' ||
url.hostname === 'www.amazon.com' ||
url.hostname === 'amazon.co.jp' ||
url.hostname === 'www.amazon.co.jp' ||
url.hostname === 'amzn.to'
) {
rules = [metascraperAmazon()]
} else {
rules = [metascraperDescription(), metascraperImage(), metascraperTitle()]
}
const metascraper = createMetascraper(rules)
const html = urlMap[urlString]
if (html) {
metadata = await metascraper({ html, url })
Expand Down

0 comments on commit bbc5cea

Please sign in to comment.