@netsells/nuxt-meta-builder
Advanced tools
Comparing version 1.1.1 to 1.1.2
@@ -8,10 +8,20 @@ "use strict"; | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } | ||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } | ||
/** | ||
* Generate the vue-meta meta data | ||
*/ | ||
class Meta { | ||
var Meta = | ||
/*#__PURE__*/ | ||
function () { | ||
/** | ||
* Construct our class and setup our class variables | ||
*/ | ||
constructor() { | ||
function Meta() { | ||
_classCallCheck(this, Meta); | ||
this.meta = []; | ||
@@ -29,95 +39,109 @@ this.title = ''; | ||
setDescription(val) { | ||
this.addMeta(['description', 'og:description'], this.limitLetters(val)); | ||
return this; | ||
} | ||
/** | ||
* Add a meta item | ||
* | ||
* @param {String|Array} hid | ||
* @param {String} content | ||
* | ||
* @return {Meta} | ||
*/ | ||
_createClass(Meta, [{ | ||
key: "setDescription", | ||
value: function setDescription(val) { | ||
this.addMeta(['description', 'og:description'], this.limitLetters(val)); | ||
return this; | ||
} | ||
/** | ||
* Add a meta item | ||
* | ||
* @param {String|Array} hid | ||
* @param {String} content | ||
* | ||
* @return {Meta} | ||
*/ | ||
}, { | ||
key: "addMeta", | ||
value: function addMeta(hid, content) { | ||
var _this = this; | ||
addMeta(hid, content) { | ||
if (typeof hid === 'string') { | ||
hid = [hid]; | ||
} | ||
if (typeof hid === 'string') { | ||
hid = [hid]; | ||
} | ||
hid.forEach(hid => { | ||
this.meta.push({ | ||
hid, | ||
name: hid, | ||
content | ||
hid.forEach(function (hid) { | ||
_this.meta.push({ | ||
hid: hid, | ||
name: hid, | ||
content: content | ||
}); | ||
}); | ||
}); | ||
return this; | ||
} | ||
/** | ||
* Set the page title | ||
* | ||
* @param {String} val | ||
* @param {Boolean} raw | ||
* | ||
* @return {Meta} | ||
*/ | ||
return this; | ||
} | ||
/** | ||
* Set the page title | ||
* | ||
* @param {String} val | ||
* @param {Boolean} raw | ||
* | ||
* @return {Meta} | ||
*/ | ||
}, { | ||
key: "setTitle", | ||
value: function setTitle(val) { | ||
var raw = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; | ||
var title = raw ? val : this.limitWords(val); | ||
this.title = title; | ||
this.addMeta(['title', 'og:title'], title); | ||
return this; | ||
} | ||
/** | ||
* Limit the amount of words | ||
* | ||
* @param {String} val | ||
* @param {Number} count | ||
* | ||
* @return {String} | ||
*/ | ||
setTitle(val, raw = false) { | ||
const title = raw ? val : this.limitWords(val); | ||
this.title = title; | ||
this.addMeta(['title', 'og:title'], title); | ||
return this; | ||
} | ||
/** | ||
* Limit the amount of words | ||
* | ||
* @param {String} val | ||
* @param {Number} count | ||
* | ||
* @return {String} | ||
*/ | ||
}, { | ||
key: "limitWords", | ||
value: function limitWords(val) { | ||
var count = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 5; | ||
var words = (val || '').split(' '); | ||
var limited = words.concat().splice(0, count); | ||
var ellipsis = words.length !== limited.length ? '…' : ''; | ||
return "".concat(limited.join(' ')).concat(ellipsis); | ||
} | ||
/** | ||
* Limit the amount of letters | ||
* | ||
* @param {String} val | ||
* @param {Number} count | ||
* | ||
* @return {String} | ||
*/ | ||
}, { | ||
key: "limitLetters", | ||
value: function limitLetters(val) { | ||
var count = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 155; | ||
var letters = (val || '').split(''); | ||
var limited = letters.concat().splice(0, count); | ||
var ellipsis = letters.length !== limited.length ? '…' : ''; | ||
return "".concat(limited.join('')).concat(ellipsis); | ||
} | ||
/** | ||
* Generate the meta object | ||
* | ||
* @return {{title: string, meta: Array}} | ||
*/ | ||
limitWords(val, count = 5) { | ||
const words = (val || '').split(' '); | ||
const limited = words.concat().splice(0, count); | ||
const ellipsis = words.length !== limited.length ? '…' : ''; | ||
return `${limited.join(' ')}${ellipsis}`; | ||
} | ||
/** | ||
* Limit the amount of letters | ||
* | ||
* @param {String} val | ||
* @param {Number} count | ||
* | ||
* @return {String} | ||
*/ | ||
}, { | ||
key: "make", | ||
value: function make() { | ||
return { | ||
title: this.title, | ||
meta: this.meta | ||
}; | ||
} | ||
}]); | ||
return Meta; | ||
}(); | ||
limitLetters(val, count = 155) { | ||
const letters = (val || '').split(''); | ||
const limited = letters.concat().splice(0, count); | ||
const ellipsis = letters.length !== limited.length ? '…' : ''; | ||
return `${limited.join('')}${ellipsis}`; | ||
} | ||
/** | ||
* Generate the meta object | ||
* | ||
* @return {{title: string, meta: Array}} | ||
*/ | ||
make() { | ||
return { | ||
title: this.title, | ||
meta: this.meta | ||
}; | ||
} | ||
} | ||
var _default = Meta; | ||
exports.default = _default; |
{ | ||
"name": "@netsells/nuxt-meta-builder", | ||
"version": "1.1.1", | ||
"version": "1.1.2", | ||
"description": "meta builder class so that you can build the meta object up in a more fluent way", | ||
@@ -24,3 +24,3 @@ "homepage": "https://github.com/netsells/nuxt-meta-builder", | ||
"@babel/plugin-transform-modules-commonjs": "^7.2.0", | ||
"@babel/preset-env": "^7.0.0", | ||
"@babel/preset-env": "^7.3.1", | ||
"@netsells/eslint-config": "^1.8.0", | ||
@@ -71,3 +71,4 @@ "babel-core": "^7.0.0-bridge.0", | ||
"test": "jest", | ||
"build": "babel -d ./dist ./lib/index.js" | ||
"build": "babel -d ./dist ./lib/index.js", | ||
"prepublishOnly": "npm run build" | ||
}, | ||
@@ -77,3 +78,4 @@ "jest": { | ||
}, | ||
"license": "MIT" | ||
"license": "MIT", | ||
"browserslist": "last 2 versions, IE 11" | ||
} |
13697
291