metascraper-date 5.33.7 → 5.34.1

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 +42 -29
  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,41 +4,54 @@ 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
- 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
- toDate($ => $('meta[name*="dcterms.date" i]').attr('content')),
27
- toDate($ => $('[property*="dc:date" i]').attr('content')),
28
- toDate($ => $('[property*="dc:created" i]').attr('content')),
29
13
  toDate($ => $filter($, $('[class*="byline" i]'))),
30
- toDate($ => $filter($, $('[class*="dateline" i]'))),
31
- toDate($ => $filter($, $('[id*="metadata" i]'))),
32
- toDate($ => $filter($, $('[class*="metadata" i]'))), // twitter, move into a bundle of rules
33
14
  toDate($ => $filter($, $('[id*="date" i]'))),
34
15
  toDate($ => $filter($, $('[class*="date" i]'))),
35
- toDate($ => $filter($, $('[id*="publish" i]'))),
36
- toDate($ => $filter($, $('[class*="publish" i]'))),
37
- toDate($ => $filter($, $('[id*="post-timestamp" i]'))),
38
- toDate($ => $filter($, $('[class*="post-timestamp" i]'))),
39
- toDate($ => $filter($, $('[id*="post-meta" i]'))),
40
- toDate($ => $filter($, $('[class*="post-meta" i]'))),
41
- toDate($ => $filter($, $('[id*="time" i]'))),
42
16
  toDate($ => $filter($, $('[class*="time" i]')))
43
17
  ]
44
- })
18
+ }
19
+
20
+ const datePublishedRules = () => {
21
+ return [
22
+ toDate($jsonld('datePublished')),
23
+ toDate($jsonld('dateCreated')),
24
+ toDate($ => $('meta[property*="published_time" i]').attr('content')),
25
+ toDate($ => $('[itemprop="datepublished" i]').attr('content')),
26
+ toDate($ => $filter($, $('[class*="publish" i]')))
27
+ ]
28
+ }
29
+
30
+ const dateModifiedRules = () => {
31
+ return [
32
+ toDate($jsonld('dateModified')),
33
+ toDate($ => $('meta[property*="modified_time" i]').attr('content')),
34
+ toDate($ => $('[itemprop*="datemodified" i]').attr('content'))
35
+ ]
36
+ }
37
+
38
+ module.exports = (
39
+ { datePublished, dateModified } = {
40
+ datePublished: false,
41
+ dateModified: false
42
+ }
43
+ ) => {
44
+ const result = {
45
+ date: dateModifiedRules().concat(datePublishedRules(), dateRules())
46
+ }
47
+
48
+ if (datePublished) {
49
+ result.datePublished = datePublishedRules()
50
+ }
51
+
52
+ if (dateModified) {
53
+ result.dateModified = dateModifiedRules()
54
+ }
55
+
56
+ return result
57
+ }
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.7",
5
+ "version": "5.34.1",
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.7"
25
+ "@metascraper/helpers": "^5.34.1"
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": "fbf546c9620b84799941aa8a16ce310e13451032"
37
+ "gitHead": "0fd49e8a8f9e73f03df8e41486b8ff5ba72d5484"
38
38
  }