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.

51 lines
1.2KB

  1. class Teaser {
  2. constructor(date, title, urlToImage, description, url) {
  3. this.publishedAt = publishedAt;
  4. this.title = title;
  5. this.urlToImage = urlToImage;
  6. this.description = description;
  7. this.url = url;
  8. }
  9. }
  10. /**
  11. *
  12. * @param {Teaser} teaser
  13. */
  14. var getTeaserTemplate = function (teaser) {
  15. const publishedAt = formateDate(teaser.publishedAt);
  16. return `
  17. <div class="teaser">
  18. <div class="teaser-header">
  19. <div class="teaser-date" name="date">${publishedAt}</div>
  20. <div class="teaser-title" name="title">${teaser.title}</div>
  21. <div class="teaser-img" name="urlToImage">
  22. <img src="${teaser.urlToImage}">
  23. </div>
  24. </div>
  25. <div class="teaser-content" name="description">
  26. ${teaser.description} ...
  27. <a class="teaser-link" href="${teaser.url}" >more</a>
  28. </div>
  29. </div>
  30. `;
  31. };
  32. var formateDate = function (dateString) {
  33. const date = new Date(dateString);
  34. const dateTimeFormat = new Intl.DateTimeFormat("de", {
  35. year: "numeric",
  36. month: "2-digit",
  37. day: "2-digit",
  38. });
  39. const [
  40. { value: day },
  41. ,
  42. { value: month },
  43. ,
  44. { value: year },
  45. ] = dateTimeFormat.formatToParts(date);
  46. return `${day}.${month}.${year}`;
  47. };
  48. export { Teaser, getTeaserTemplate };