├── .npmignore ├── lib ├── twitter.js ├── utils.js ├── router.js ├── ogp.js ├── oembed.js ├── tags.js └── index.js ├── .travis.yml ├── .gitignore ├── package.json ├── LICENSE ├── bench.js ├── test ├── tags.js ├── twitter.js ├── oembed.js ├── ogp.js └── index.js ├── README.md └── providers.json /.npmignore: -------------------------------------------------------------------------------- 1 | * 2 | !lib/** 3 | !.npmignore 4 | !providers.json 5 | -------------------------------------------------------------------------------- /lib/twitter.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tkh44/metaphor/master/lib/twitter.js -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | 3 | node_js: 4 | - "4" 5 | - "6" 6 | - "node" 7 | 8 | sudo: false 9 | 10 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | npm-debug.log 2 | dump.rdb 3 | node_modules 4 | npm-shrinkwrap.json 5 | .idea 6 | .DS_Store 7 | */.DS_Store 8 | */*/.DS_Store 9 | ._* 10 | */._* 11 | */*/._* 12 | coverage.* 13 | config.json 14 | vault.json 15 | -------------------------------------------------------------------------------- /lib/utils.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | // Load modules 4 | 5 | 6 | // Declare internals 7 | 8 | const internals = {}; 9 | 10 | 11 | exports.parse = function (payload) { 12 | 13 | try { 14 | return JSON.parse(payload.toString()); 15 | } 16 | catch (err) { 17 | return null; 18 | } 19 | }; 20 | 21 | 22 | exports.copy = function (from, to, keys, source) { 23 | 24 | to = to || {}; 25 | let used = false; 26 | keys.forEach((key) => { 27 | 28 | if (from[key]) { 29 | to[key] = from[key]; 30 | used = true; 31 | } 32 | }); 33 | 34 | if (used && 35 | source) { 36 | 37 | to.sources.push(source); 38 | } 39 | 40 | return to; 41 | }; 42 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "metaphor", 3 | "description": "Open Graph, Twitter Card, and oEmbed Metadata Collector", 4 | "version": "3.5.3", 5 | "repository": "git://github.com/hueniverse/metaphor", 6 | "main": "lib/index.js", 7 | "keywords": [ 8 | "oembed", 9 | "ogp", 10 | "open graph", 11 | "twitter card", 12 | "description", 13 | "embed" 14 | ], 15 | "engines": { 16 | "node": ">=4.x.x" 17 | }, 18 | "dependencies": { 19 | "content": "3.x.x", 20 | "hoek": "4.x.x", 21 | "htmlparser2": "3.x.x", 22 | "items": "2.x.x", 23 | "joi": "9.x.x", 24 | "wreck": "8.x.x" 25 | }, 26 | "devDependencies": { 27 | "code": "3.x.x", 28 | "lab": "10.x.x" 29 | }, 30 | "scripts": { 31 | "test": "node node_modules/lab/bin/lab -a code -t 100 -L -m 15000", 32 | "test-cov-html": "node node_modules/lab/bin/lab -a code -r html -o coverage.html -m 15000" 33 | }, 34 | "license": "BSD-3-Clause" 35 | } 36 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2016, Eran Hammer and Project contributors 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | * Redistributions of source code must retain the above copyright 7 | notice, this list of conditions and the following disclaimer. 8 | * Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | * The names of any contributors may not be used to endorse or promote 12 | products derived from this software without specific prior written 13 | permission. 14 | 15 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 16 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS AND CONTRIBUTORS BE LIABLE FOR ANY 19 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | 26 | * * * 27 | 28 | The complete list of contributors can be found at: https://github.com/hueniverse/metaphor/graphs/contributors 29 | -------------------------------------------------------------------------------- /bench.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const Bench = require('bench'); 4 | const Metaphor = require('.'); 5 | const Wreck = require('wreck'); 6 | 7 | 8 | const parse = function (document) { 9 | 10 | // Grab the head 11 | 12 | const head = document.match(/
]*>([\s\S]*)<\/head\s*>/); 13 | if (!head) { 14 | return []; 15 | } 16 | 17 | // Remove scripts 18 | 19 | const scripts = head[1].split(''); // 'something' -> [' 35 | 36 | 37 | 38 | 39 | 40 | 41 |