summaryrefslogtreecommitdiff
path: root/src/build/article.mjs
blob: 1a7b09b76f65693071c20f7f088054131af78d2d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// Set of functions to handle articles

function getArticleYear(article) {
  if (article.metaData.pubDate.getFullYear) {
    return article.metaData.pubDate.getFullYear();
  }

  if (article.metaData.pubDate.getUTCFullYear) {
    return article.metaData.pubDate.getUTCFullYear();
  }

  return 0;
}

function getArticleDate(article) {
  if (article.metaData.pubDate.getDate) {
    return article.metaData.pubDate.getFullYear() * 100 + article.metaData.pubDate.getDate();
  }

  if (article.metaData.pubDate.getUTCDate) {
    return article.metaData.pubDate.getUTCFullYear() * 100 + article.metaData.pubDate.getDate();
  }

  return 0;
}

function cmpArticles(a, b) {
  return getArticleDate(b) - getArticleDate(a);
}

export {getArticleDate, getArticleYear, cmpArticles};