diff --git a/app/src/components/bookcard.js b/app/src/components/bookcard.js deleted file mode 100644 index fe9dad1c..00000000 --- a/app/src/components/bookcard.js +++ /dev/null @@ -1,95 +0,0 @@ -import PropTypes from 'prop-types'; -import React, { useState } from 'react'; -import StarRatings from 'react-star-ratings'; -import { Card, Row, Col } from 'react-bootstrap'; - -import AmazonURL from '../components/amazonurl'; -import Bookmark from '../components/bookmark'; -import GoodReadsImage from '../components/goodreadsimage'; - -const truncateContent = (content) => { - if (!content) { - return ''; - } - return content.length > 350 ? content.substring(0, 350) + '...' : content; -}; - -const showFullText = (content) => { - if (!content) { - return ''; - } - return content; -}; - -const BookCard = ({ book }) => { - const [ show, toggleShow ] = useState(false); - return ( - - - - - - - - {book.title} - - - {book.author} {book.year ? book.year : null} - - -
-
- {book.amazon_url ? : null} -
-
- - - -
- -
-
-

- {!show && truncateContent(book.description)} - {show && showFullText(book.description)} -

- {!show && book.description.length>350 &&( - - )} - {show && ( - - )} -
- -
-
- ); -}; - -BookCard.propTypes = { - siteTitle: PropTypes.object -}; - -BookCard.defaultProps = { - book: {} -}; - -export default BookCard; diff --git a/app/src/components/bookcard.jsx b/app/src/components/bookcard.jsx new file mode 100644 index 00000000..b232e393 --- /dev/null +++ b/app/src/components/bookcard.jsx @@ -0,0 +1,178 @@ +import PropTypes from "prop-types" +import React, { useState } from "react" +import StarRatings from "react-star-ratings" +import { Card, Row, Col } from "react-bootstrap" + +import AmazonURL from "./amazonurl" +import Bookmark from "./bookmark" +import GoodReadsImage from "./goodreadsimage" + +const truncateContent = content => { + if (!content) { + return "" + } + return content.length > 350 ? content.substring(0, 350) + "..." : content +} + +const showFullText = content => { + if (!content) { + return "" + } + return content +} + +const BookCard = ({ book }) => { + const [show, toggleShow] = useState(false) + + const bookJsonLd = { + "@context": "https://schema.org", + "@type": "Book", + name: book.title, + author: { + "@type": "Person", + name: book.author, + }, + datePublished: book.year ? String(book.year) : undefined, + image: book.image_url, + description: book.description, + aggregateRating: book.rating + ? { + "@type": "AggregateRating", + ratingValue: String(book.rating), + bestRating: "5", + worstRating: "1", + ratingCount: book.ratingCount ? Number(book.ratingCount) : 1, + reviewCount: book.reviewCount ? Number(book.reviewCount) : 1, + } + : undefined, + sameAs: book.url, + offers: book.amazon_url + ? { + "@type": "Offer", + url: book.amazon_url, + availability: "https://schema.org/InStock", + } + : undefined, + } + + return ( + <> + + + + + + + + {book.title} + + + {book.author} {book.year ? book.year : null} + + +
+
+ {book.amazon_url ? : null} +
+
+ + + +
+ +
+
+

+ {!show && truncateContent(book.description)} + {show && showFullText(book.description)} +

+ {!show && book.description.length > 350 && ( + + )} + {show && ( + + )} +
+ +
+
+ {/* eslint-disable-next-line react/no-danger */} +