Skip to content

Commit

Permalink
Add language property
Browse files Browse the repository at this point in the history
Closes #45
  • Loading branch information
Kikobeats committed Dec 28, 2017
1 parent d63d5aa commit 656bb97
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 1 deletion.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ Here is a list of the metadata that **metascraper** collects by default:

- **`image`** — eg. `https://assets.entrepreneur.com/content/3x2/1300/20160504155601-GettyImages-174457162.jpeg`<br/>
An image URL that best represents the article.

- **`lang`** — eg. `en`<br/>
An [ISO 639-1](https://en.wikipedia.org/wiki/ISO_639-1) representation of the url content language.

- **`logo`** — eg. `https://entrepreneur.com/favicon180x180.png`<br/>
An image URL that best represents the publisher brand.
Expand Down
4 changes: 4 additions & 0 deletions packages/metascraper-lang/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
unsafe-perm=true
save-prefix=~
shrinkwrap=false
save=false
19 changes: 19 additions & 0 deletions packages/metascraper-lang/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# metascraper-lang

[![npm](https://img.shields.io/npm/v/metascraper-lang.svg?style=flat-square)](https://www.npmjs.com/package/metascraper-lang)
[![Dependency Status](https://david-dm.org/microlinkhq/metascraper.svg?path=packages/metascraper-lang&style=flat-square)](https://david-dm.org/microlinkhq/metascraper?path=packages/metascraper-lang)

> Get lang property from HTML markup.
## Install

```bash
$ npm install metascraper-lang --save
```

## License

**metascraper-lang** © [microlink.io](https://microlink.io), Released under the [MIT](https://github.com/microlinkhq/metascraper-lang/blob/master/LICENSE.md) License.<br>
Authored and maintained by microlink.io with help from [contributors](https://github.com/microlinkhq/metascraper-lang/contributors).

> [microlink.io](https://microlink.io) · GitHub [@microlink.io](https://github.com/microlinkhq) · Twitter [@microlinkhq](https://twitter.com/microlinkhq)
15 changes: 15 additions & 0 deletions packages/metascraper-lang/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
'use strict'

const { isString, toLower } = require('lodash')

const wrap = rule => ({ htmlDom }) => {
const value = rule(htmlDom)
return isString(value) && toLower(value.substring(0, 2))
}

module.exports = () => ({
lang: [
wrap($ => $('meta[property="og:locale"]').attr('content')),
wrap($ => $('html').attr('lang'))
]
})
34 changes: 34 additions & 0 deletions packages/metascraper-lang/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"name": "metascraper-lang",
"description": "Get lang property from HTML markup",
"homepage": "https://metascraper.js.org",
"version": "0.0.0",
"main": "index.js",
"author": {
"email": "[email protected]",
"name": "Ian Storm Taylor"
},
"repository": {
"type": "git",
"url": "https://github.com/microlinkhq/metascraper/tree/master/packages/metascraper-lang"
},
"bugs": {
"url": "https://github.com/microlinkhq/metascraper/issues"
},
"dependencies": {
"lodash": "~4.17.4"
},
"devDependencies": {
"standard": "latest"
},
"engines": {
"node": ">= 8"
},
"files": [
"index.js"
],
"scripts": {
"test": "exit 0"
},
"license": "MIT"
}
1 change: 1 addition & 0 deletions packages/metascraper/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
"metascraper-date": "^3.3.0",
"metascraper-description": "^3.3.0",
"metascraper-image": "^3.3.0",
"metascraper-lang": "^0.0.0",
"metascraper-logo": "^3.3.0",
"metascraper-publisher": "^3.3.0",
"metascraper-title": "^3.3.0",
Expand Down
3 changes: 2 additions & 1 deletion packages/metascraper/src/load-rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ const DEFAULT_RULES = [
'metascraper-logo',
'metascraper-publisher',
'metascraper-title',
'metascraper-url'
'metascraper-url',
'metascraper-lang'
]

let singletonConfig
Expand Down

0 comments on commit 656bb97

Please sign in to comment.