You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

LatestArticles.jsx 2.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import React from 'react';
  2. import { strapiApiBuilder } from './../utils/strapiApiBuilder';
  3. import useFetchCollections from './../hooks/useFetchCollections';
  4. import { formatDate } from './../utils/formatDate';
  5. const api_url = process.env.REACT_APP_API_URL;
  6. const strapiPopulate = ['AuthorImage', 'ArticleImage', 'article_category'];
  7. const LatestArticles = () => {
  8. const strapi = strapiApiBuilder(
  9. 'articles',
  10. strapiPopulate,
  11. '&sort[0]=Date:DESC&pagination[pageSize]=3',
  12. );
  13. const [{ data, isLoading, isError }, doFetch] = useFetchCollections(strapi);
  14. return (
  15. <div className="col-span-1 md:col-span-2 flex flex-col gap-4">
  16. <h4 className="text-n-subhead font-semibold text-dark-gray mb-8">
  17. Latest Blog Posts
  18. </h4>
  19. {data &&
  20. data.length > 0 &&
  21. data.map((element, index) => (
  22. <a
  23. key={index}
  24. className={'card box flex flex-col items-center justify-between gap-[24px]'}
  25. href={`/articles/${element.attributes.Slug}`}
  26. >
  27. <div className="flex flex-col gap-[4px]">
  28. {element.attributes.AuthorTitle && (
  29. <div className="flex gap-2">
  30. <img
  31. className="max-h-[36px] object-fit rounded-full"
  32. src={api_url + element.attributes.AuthorImage.data.attributes.url}
  33. alt={
  34. api_url +
  35. element.attributes.AuthorImage.data.attributes.alternativeText
  36. }
  37. />
  38. <div className="flex flex-col items-start">
  39. <p className="paragraph">{element.attributes.Author}</p>
  40. <p className="text-small-subhead text-gray-400 leading-normal">
  41. {element.attributes.AuthorTitle}
  42. </p>
  43. </div>
  44. </div>
  45. )}
  46. <div className="text-left flex flex-col gap-[8px]">
  47. <h2 className="n-paragraph-title text-dark-gray leading-normal">
  48. {element.attributes.ArticleTitle}
  49. </h2>
  50. </div>
  51. </div>
  52. <img
  53. src={api_url + element.attributes.ArticleImage.data.attributes.url}
  54. alt={
  55. api_url + element.attributes.ArticleImage.data.attributes.alternativeText
  56. }
  57. />
  58. </a>
  59. ))}
  60. </div>
  61. );
  62. };
  63. export default LatestArticles;