vuepress-plugin-autometa
Advanced tools
Comparing version 0.1.6 to 0.1.7
77
index.js
@@ -37,3 +37,3 @@ 'use strict'; | ||
image : true, // regular meta image used by search engines | ||
twitter : true, | ||
twitter : true, // twitter card | ||
og : true, // open graph: facebook, pinterest, google+ | ||
@@ -200,2 +200,49 @@ schema : true, // schema.org for google | ||
/** | ||
* check if string is a valid url | ||
* | ||
* @param {string} maybe_url | ||
* @return {bool} | ||
*/ | ||
PLUGIN.is_url = ( maybe_url ) => | ||
{ | ||
if ( ! maybe_url || typeof maybe_url !== 'string' ) | ||
{ | ||
return false; | ||
} | ||
// --------------------------------------------------------------------------- | ||
const re_protocol_and_domain = /^(?:\w+:)?\/\/(\S+)$/; | ||
const match = maybe_url.match( re_protocol_and_domain ); | ||
if ( ! match ) | ||
{ | ||
return false; | ||
} | ||
// --------------------------------------------------------------------------- | ||
const all_after_protocol = match[1]; | ||
if ( ! all_after_protocol ) | ||
{ | ||
return false; | ||
} | ||
// --------------------------------------------------------------------------- | ||
const re_domain_localhost = /^localhost[\:?\d]*(?:[^\:?\d]\S*)?$/ | ||
const re_domain_non_localhost = /^[^\s\.]+\.\S{2,}$/; | ||
return ( re_domain_localhost.test( all_after_protocol ) | ||
|| re_domain_non_localhost.test( all_after_protocol ) ); | ||
} | ||
// PLUGIN.is_url() | ||
/** | ||
* @return {string} | ||
@@ -432,4 +479,30 @@ */ | ||
return out.trim(); | ||
out = out.trim(); | ||
if ( ! out ) | ||
{ | ||
return; | ||
} | ||
// --------------------------------------------------------------------------- | ||
// support for image url as relative path | ||
if ( PLUGIN.is_url( out ) ) | ||
{ | ||
return out; | ||
} | ||
else | ||
{ | ||
// only return it if we have a base url, | ||
// otherwise it's meaningless to add it | ||
if ( options.canonical_base ) | ||
{ | ||
out = PATH.join( options.canonical_base, out ); | ||
return out; | ||
} | ||
} | ||
}; | ||
@@ -436,0 +509,0 @@ // PLUGIN.get_default_image_url() |
{ | ||
"name": "vuepress-plugin-autometa", | ||
"version": "0.1.6", | ||
"version": "0.1.7", | ||
"description": "Auto meta tags plugin for VuePress", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -12,3 +12,3 @@ # VuePress Plugin Auto Meta | ||
This is a Plug-and-Forget VuePress plugin that will auto generate the meta tags | ||
of VuePress pages or posts. | ||
for VuePress pages or posts. | ||
@@ -74,3 +74,3 @@ | ||
image : true, // regular meta image used by search engines | ||
twitter: true, | ||
twitter: true, // twitter card | ||
og : true, // open graph: facebook, pinterest, google+ | ||
@@ -77,0 +77,0 @@ schema : true, // schema.org for google |
27181
628