-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #43 from danmademe/warnings_and_structured_data
Warnings and structured data
- Loading branch information
Showing
15 changed files
with
360 additions
and
185 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
{ | ||
"presets": ["es2015"], | ||
"plugins": [ | ||
"add-module-exports" | ||
"add-module-exports", | ||
"transform-flow-strip-types" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,3 @@ root = true | |
indent_style = space | ||
indent_size = 4 | ||
charset = utf-8 | ||
|
||
[*.md] | ||
trim_trailing_whitespace = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,11 @@ | |
"semi": [ | ||
"error", | ||
"always" | ||
], | ||
"no-console": [ | ||
"error", { | ||
"allow": ["warn", "error"] | ||
} | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,8 +2,6 @@ language: node_js | |
node_js: | ||
- v7 | ||
- v6 | ||
- v5 | ||
- v4 | ||
deploy: | ||
skip_cleanup: true | ||
provider: npm | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
// @flow | ||
const metaWarning = 'Deprecation Warning: Please update your meta object. Check github project for more information. \nhttps://github.com/danmademe/express-vue'; | ||
//Checks Vue Object to check if a meta object is inside head | ||
//Returns Boolean | ||
function checkMetaInsideHead(vueObject: Object): boolean { | ||
let isMetaInsideHead: boolean = false; | ||
if (vueObject.meta && vueObject.meta.head) { | ||
isMetaInsideHead = false; | ||
} else if(vueObject.head && vueObject.head.meta) { | ||
isMetaInsideHead = true; | ||
} | ||
return isMetaInsideHead; | ||
} | ||
|
||
//Support for legacy v3.7.2 and lower | ||
// vue: { | ||
// meta: { | ||
// title: 'Page Title', | ||
// head: [ | ||
// { property:'og:title', content: 'Page Title'}, | ||
// { name:'twitter:title', content: 'Page Title'}, | ||
// ] | ||
// } | ||
// } | ||
function legacyMetaTags(metaTags: string, vueObject: Object): string { | ||
console.warn(metaWarning); | ||
if (vueObject.meta && vueObject.meta.head) { | ||
for (let metaItem of vueObject.meta.head) { | ||
if (metaItem.name) { | ||
metaTags += `<meta name=\"${metaItem.name}\" content=\"${metaItem.content}\" />`; | ||
} else if (metaItem.property) { | ||
metaTags += `<meta property=\"${metaItem.property}\" content=\"${metaItem.content}\" />`; | ||
} else if (metaItem.script) { | ||
const charset = metaItem.charset || 'utf-8'; | ||
metaTags += `<script src=\"${metaItem.script}\" charset=\"${charset}\"></script>`; | ||
} else if (metaItem.style) { | ||
const type = metaItem.type || 'text/css'; | ||
const rel = metaItem.rel || 'stylesheet'; | ||
metaTags += `<link rel=\"${rel}\" type=\"${type}\" href=\"${metaItem.style}\">`; | ||
} | ||
} | ||
} | ||
return metaTags; | ||
} | ||
|
||
//For v3.7.3 and greater | ||
// vue: { | ||
// head: { | ||
// title: 'Page Title', | ||
// meta: [ | ||
// { property:'og:title', content: 'Page Title'}, | ||
// { name:'twitter:title', content: 'Page Title'}, | ||
// ] | ||
// } | ||
// } | ||
function createMetaTags(metaTags: string, vueObject: Object): string { | ||
if (vueObject.head && vueObject.head.meta) { | ||
for (let metaItem of vueObject.head.meta) { | ||
if (metaItem.name) { | ||
metaTags += `<meta name=\"${metaItem.name}\" content=\"${metaItem.content}\" />`; | ||
} else if (metaItem.property) { | ||
metaTags += `<meta property=\"${metaItem.property}\" content=\"${metaItem.content}\" />`; | ||
} else if (metaItem.script) { | ||
const charset = metaItem.charset || 'utf-8'; | ||
metaTags += `<script src=\"${metaItem.script}\" charset=\"${charset}\"></script>`; | ||
} else if (metaItem.style) { | ||
const type = metaItem.type || 'text/css'; | ||
const rel = metaItem.rel || 'stylesheet'; | ||
metaTags += `<link rel=\"${rel}\" type=\"${type}\" href=\"${metaItem.style}\">`; | ||
} | ||
} | ||
} | ||
return metaTags; | ||
} | ||
|
||
function headUtil(vueObject: Object) { | ||
let metaTags = ''; | ||
let title = ''; | ||
let structuredData = ''; | ||
const hasNewHeadBlock = checkMetaInsideHead(vueObject); | ||
|
||
if (vueObject.head && hasNewHeadBlock) { | ||
metaTags = createMetaTags(metaTags, vueObject); | ||
} else if (vueObject.meta && !hasNewHeadBlock) { | ||
metaTags = legacyMetaTags(metaTags, vueObject); | ||
} | ||
|
||
if (vueObject.meta && vueObject.meta.title) { | ||
console.warn(metaWarning); | ||
title = `<title>${vueObject.meta.title}</title>`; | ||
} else if (vueObject.head && vueObject.head.title) { | ||
title = `<title>${vueObject.head.title}</title>`; | ||
} | ||
|
||
if (vueObject.head && vueObject.head.structuredData) { | ||
structuredData = `<script type="application/ld+json">${JSON.stringify(vueObject.head.structuredData)}</script>`; | ||
} | ||
|
||
return title + metaTags + structuredData + '</head>'; | ||
} | ||
|
||
export default headUtil; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.