app: Include amazon links.
This commit is contained in:
@@ -28,6 +28,7 @@ exports.createPages = async function ({ actions, graphql }) {
|
||||
category
|
||||
image_url
|
||||
description
|
||||
amazon_url
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
13
app/src/components/amazonurl.js
Normal file
13
app/src/components/amazonurl.js
Normal file
@@ -0,0 +1,13 @@
|
||||
import React from "react";
|
||||
|
||||
const getTaggetURL = (book) => {
|
||||
return book.amazon_url + "?tag=vishnuks-20";
|
||||
}
|
||||
|
||||
export default ({ book }) => {
|
||||
return (
|
||||
<a href={getTaggetURL(book)} target="_blank">
|
||||
<img style={{ "width": "30px" }} src="https://img.icons8.com/color/48/000000/amazon.png"/>
|
||||
</a>
|
||||
)
|
||||
}
|
||||
@@ -3,20 +3,21 @@ import React from "react"
|
||||
import StarRatings from "react-star-ratings"
|
||||
import { Card, Row, Col } from "react-bootstrap"
|
||||
|
||||
import AmazonURL from "../components/amazonurl"
|
||||
|
||||
const truncateContent = (content) => {
|
||||
if (!content) {
|
||||
return ""
|
||||
}
|
||||
return content.length > 600 ? content.substring(0, 600) + "..." : content
|
||||
return content.length > 350 ? content.substring(0, 350) + "..." : content
|
||||
};
|
||||
|
||||
|
||||
const BookCard = ({ book }) => (
|
||||
<Card style={{ width: "44rem", height: "24rem", marginBottom: "15px" }}>
|
||||
<Card style={{ width: "44rem", height: "21rem", marginBottom: "15px" }}>
|
||||
<Row>
|
||||
<Col xs={3}>
|
||||
<Card.Img
|
||||
style={{ height: "12rem", width: "8rem", paddingLeft: "25px", paddingRight: "-15px", paddingTop: "30px"}}
|
||||
style={{ height: "12rem", width: "8rem", paddingLeft: "25px", paddingRight: "-15px", paddingTop: "30px" }}
|
||||
src={book.image_url}
|
||||
/>
|
||||
</Col>
|
||||
@@ -24,18 +25,20 @@ const BookCard = ({ book }) => (
|
||||
<Card.Body>
|
||||
<Card.Title>{book.title}</Card.Title>
|
||||
<Card.Subtitle className="mb-2 text-muted">
|
||||
<StarRatings
|
||||
rating={parseFloat(book.rating)}
|
||||
numberOfStars={5}
|
||||
starDimension="18px"
|
||||
starSpacing="1px"
|
||||
starRatedColor="#fa604a"
|
||||
/>
|
||||
<br />
|
||||
{book.author}
|
||||
<StarRatings
|
||||
rating={parseFloat(book.rating)}
|
||||
numberOfStars={5}
|
||||
starDimension="18px"
|
||||
starSpacing="1px"
|
||||
starRatedColor="#fa604a"
|
||||
/>
|
||||
<br />
|
||||
{book.author} <b>{book.year ? book.year: null}</b>
|
||||
<br />
|
||||
{book.amazon_url ? <AmazonURL book={book} />: null}
|
||||
</Card.Subtitle>
|
||||
<p>
|
||||
{truncateContent(book.description)}
|
||||
{truncateContent(book.description)}
|
||||
</p>
|
||||
</Card.Body>
|
||||
</Col>
|
||||
|
||||
@@ -6,9 +6,12 @@ import BookCard from "../components/bookcard"
|
||||
|
||||
export default ({ data, limit }) => {
|
||||
return data.allBooksJson.edges.map(function(x, index) {
|
||||
console.log(index, limit)
|
||||
const book = x.node;
|
||||
if (!limit || index < limit) {
|
||||
return <BookCard book={x.node} key={x.node.id} />
|
||||
if(!book.description || book.description.length < 10) {
|
||||
return null;
|
||||
}
|
||||
return <BookCard book={book} key={book.id} />
|
||||
} else {
|
||||
return null
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
BIN
app/src/images/amazon.png
Normal file
BIN
app/src/images/amazon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.4 KiB |
@@ -59,6 +59,7 @@ export const query = graphql`
|
||||
category
|
||||
description
|
||||
image_url
|
||||
amazon_url
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user