metascraper-date 5.33.5 → 5.34.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +19 -0
  2. package/index.js +44 -18
  3. package/package.json +3 -3
package/README.md CHANGED
@@ -13,6 +13,25 @@
13
13
  ```bash
14
14
  $ npm install metascraper-date --save
15
15
  ```
16
+ ## API
17
+
18
+ ### metascraper-date([options])
19
+
20
+ #### options
21
+
22
+ ##### datePublished
23
+
24
+ Type: `boolean`<br>
25
+ Default: `false`
26
+
27
+ Whether to return `datePublished` alongside date.
28
+
29
+ ##### dateModified
30
+
31
+ Type: `boolean`<br>
32
+ Default: `false`
33
+
34
+ Whether to return `dateModified` alongside date.
16
35
 
17
36
  ## License
18
37
 
package/index.js CHANGED
@@ -4,36 +4,21 @@ const { date, $filter, $jsonld, toRule } = require('@metascraper/helpers')
4
4
 
5
5
  const toDate = toRule(date)
6
6
 
7
- module.exports = () => ({
8
- date: [
9
- toDate($jsonld('dateModified')),
10
- toDate($jsonld('datePublished')),
11
- toDate($jsonld('dateCreated')),
12
- toDate($ => $('meta[property*="updated_time" i]').attr('content')),
13
- toDate($ => $('meta[property*="modified_time" i]').attr('content')),
14
- toDate($ => $('meta[property*="published_time" i]').attr('content')),
15
- toDate($ => $('meta[property*="release_date" i]').attr('content')),
7
+ const dateRules = () => {
8
+ return [
16
9
  toDate($ => $('meta[name="date" i]').attr('content')),
17
- toDate($ => $('[itemprop*="datemodified" i]').attr('content')),
18
- toDate($ => $('[itemprop="datepublished" i]').attr('content')),
19
10
  toDate($ => $('[itemprop*="date" i]').attr('content')),
20
11
  toDate($ => $('time[itemprop*="date" i]').attr('datetime')),
21
12
  toDate($ => $('time[datetime]').attr('datetime')),
22
- toDate($ => $('time[datetime][pubdate]').attr('datetime')),
23
13
  toDate($ => $('meta[name*="dc.date" i]').attr('content')),
24
- toDate($ => $('meta[name*="dc.date.issued" i]').attr('content')),
25
- toDate($ => $('meta[name*="dc.date.created" i]').attr('content')),
26
14
  toDate($ => $('meta[name*="dcterms.date" i]').attr('content')),
27
15
  toDate($ => $('[property*="dc:date" i]').attr('content')),
28
- toDate($ => $('[property*="dc:created" i]').attr('content')),
29
16
  toDate($ => $filter($, $('[class*="byline" i]'))),
30
17
  toDate($ => $filter($, $('[class*="dateline" i]'))),
31
18
  toDate($ => $filter($, $('[id*="metadata" i]'))),
32
19
  toDate($ => $filter($, $('[class*="metadata" i]'))), // twitter, move into a bundle of rules
33
20
  toDate($ => $filter($, $('[id*="date" i]'))),
34
21
  toDate($ => $filter($, $('[class*="date" i]'))),
35
- toDate($ => $filter($, $('[id*="publish" i]'))),
36
- toDate($ => $filter($, $('[class*="publish" i]'))),
37
22
  toDate($ => $filter($, $('[id*="post-timestamp" i]'))),
38
23
  toDate($ => $filter($, $('[class*="post-timestamp" i]'))),
39
24
  toDate($ => $filter($, $('[id*="post-meta" i]'))),
@@ -41,4 +26,45 @@ module.exports = () => ({
41
26
  toDate($ => $filter($, $('[id*="time" i]'))),
42
27
  toDate($ => $filter($, $('[class*="time" i]')))
43
28
  ]
44
- })
29
+ }
30
+
31
+ const datePublishedRules = () => {
32
+ return [
33
+ toDate($jsonld('datePublished')),
34
+ toDate($jsonld('dateCreated')),
35
+ toDate($ => $('meta[property*="published_time" i]').attr('content')),
36
+ toDate($ => $('meta[property*="release_date" i]').attr('content')),
37
+ toDate($ => $('[itemprop="datepublished" i]').attr('content')),
38
+ toDate($ => $('time[datetime][pubdate]').attr('datetime')),
39
+ toDate($ => $('meta[name*="dc.date.issued" i]').attr('content')),
40
+ toDate($ => $('meta[name*="dc.date.created" i]').attr('content')),
41
+ toDate($ => $('[property*="dc:created" i]').attr('content')),
42
+ toDate($ => $filter($, $('[id*="publish" i]'))),
43
+ toDate($ => $filter($, $('[class*="publish" i]')))
44
+ ]
45
+ }
46
+
47
+ const dateModifiedRules = () => {
48
+ return [
49
+ toDate($jsonld('dateModified')),
50
+ toDate($ => $('meta[property*="updated_time" i]').attr('content')),
51
+ toDate($ => $('meta[property*="modified_time" i]').attr('content')),
52
+ toDate($ => $('[itemprop*="datemodified" i]').attr('content'))
53
+ ]
54
+ }
55
+
56
+ module.exports = ({ datePublished, dateModified } = { datePublished: false, dateModified: false }) => {
57
+ const result = {
58
+ date: dateModifiedRules().concat(datePublishedRules(), dateRules())
59
+ }
60
+
61
+ if (datePublished) {
62
+ result.datePublished = datePublishedRules()
63
+ }
64
+
65
+ if (dateModified) {
66
+ result.dateModified = dateModifiedRules()
67
+ }
68
+
69
+ return result
70
+ }
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "metascraper-date",
3
3
  "description": "Get date property from HTML markup",
4
4
  "homepage": "https://nicedoc.io/microlinkhq/metascraper/packages/metascraper-date",
5
- "version": "5.33.5",
5
+ "version": "5.34.0",
6
6
  "main": "index.js",
7
7
  "author": {
8
8
  "email": "hello@microlink.io",
@@ -22,7 +22,7 @@
22
22
  "metascraper"
23
23
  ],
24
24
  "dependencies": {
25
- "@metascraper/helpers": "^5.33.5"
25
+ "@metascraper/helpers": "^5.33.7"
26
26
  },
27
27
  "engines": {
28
28
  "node": ">= 12"
@@ -34,5 +34,5 @@
34
34
  "test": "exit 0"
35
35
  },
36
36
  "license": "MIT",
37
- "gitHead": "6cd369d2522c238f72b411e67b7399ebf8808b1c"
37
+ "gitHead": "28a9f7b05f8f8a2d1551837035dbcffae8f9eaf4"
38
38
  }