From bbc5cea24557fe8785248f87354dfeb9d97570c0 Mon Sep 17 00:00:00 2001 From: otoyo Date: Tue, 22 Aug 2023 20:15:52 +0900 Subject: [PATCH] Use metascraper-amazon --- src/components/notion-blocks/Bookmark.astro | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/components/notion-blocks/Bookmark.astro b/src/components/notion-blocks/Bookmark.astro index 09b8c6bbd..0457d6b55 100644 --- a/src/components/notion-blocks/Bookmark.astro +++ b/src/components/notion-blocks/Bookmark.astro @@ -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 { @@ -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 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 })