mirror of
https://github.com/tenrok/vue-meta.git
synced 2026-06-25 08:50:34 +03:00
refactor: rename inBody to body
This commit is contained in:
@@ -193,7 +193,7 @@ app.get('*', (req, res) => {
|
|||||||
const context = { url: req.url }
|
const context = { url: req.url }
|
||||||
renderer.renderToString(context, (error, html) => {
|
renderer.renderToString(context, (error, html) => {
|
||||||
if (error) return res.send(error.stack)
|
if (error) return res.send(error.stack)
|
||||||
const bodyOpt = { inBody: true }
|
const bodyOpt = { body: true }
|
||||||
const {
|
const {
|
||||||
title, htmlAttrs, bodyAttrs, link, style, script, noscript, meta
|
title, htmlAttrs, bodyAttrs, link, style, script, noscript, meta
|
||||||
} = context.meta.inject()
|
} = context.meta.inject()
|
||||||
@@ -230,7 +230,7 @@ app.get('*', (req, res) => {
|
|||||||
const context = { url: req.url }
|
const context = { url: req.url }
|
||||||
const renderStream = renderer.renderToStream(context)
|
const renderStream = renderer.renderToStream(context)
|
||||||
renderStream.once('data', () => {
|
renderStream.once('data', () => {
|
||||||
const bodyOpt = { inBody: true }
|
const bodyOpt = { body: true }
|
||||||
const {
|
const {
|
||||||
title, htmlAttrs, bodyAttrs, link, style, script, noscript, meta
|
title, htmlAttrs, bodyAttrs, link, style, script, noscript, meta
|
||||||
} = context.meta.inject()
|
} = context.meta.inject()
|
||||||
@@ -501,13 +501,13 @@ Each item in the array maps to a newly-created `<script>` element, where object
|
|||||||
<script type="application/ld+json">{ "@context": "http://schema.org" }</script>
|
<script type="application/ld+json">{ "@context": "http://schema.org" }</script>
|
||||||
```
|
```
|
||||||
|
|
||||||
If your browser doesn't support `defer` or any other reason, you want to put `<script>` before `</body>`, use `inBody`.
|
If your browser doesn't support `defer` or any other reason, you want to put `<script>` before `</body>`, use `body`.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
{
|
{
|
||||||
metaInfo: {
|
metaInfo: {
|
||||||
script: [
|
script: [
|
||||||
{ innerHTML: 'console.log("I am in body");', type: 'text/javascript', inBody: true }
|
{ innerHTML: 'console.log("I am in body");', type: 'text/javascript', body: true }
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ export default function _updateTags (options = {}) {
|
|||||||
|
|
||||||
oldTags.forEach((tag) => tag.parentNode.removeChild(tag))
|
oldTags.forEach((tag) => tag.parentNode.removeChild(tag))
|
||||||
newTags.forEach((tag) => {
|
newTags.forEach((tag) => {
|
||||||
if (tag.inBody === true) {
|
if (tag.body === true) {
|
||||||
bodyTag.appendChild(tag)
|
bodyTag.appendChild(tag)
|
||||||
} else {
|
} else {
|
||||||
headTag.appendChild(tag)
|
headTag.appendChild(tag)
|
||||||
|
|||||||
@@ -10,10 +10,10 @@ export default function _tagGenerator (options = {}) {
|
|||||||
*/
|
*/
|
||||||
return function tagGenerator (type, tags) {
|
return function tagGenerator (type, tags) {
|
||||||
return {
|
return {
|
||||||
text ({inBody = false} = {}) {
|
text ({body = false} = {}) {
|
||||||
// build a string containing all tags of this type
|
// build a string containing all tags of this type
|
||||||
return tags.reduce((tagsStr, tag) => {
|
return tags.reduce((tagsStr, tag) => {
|
||||||
if (!!tag.inBody !== inBody) return tagsStr
|
if (!!tag.body !== body) return tagsStr
|
||||||
// build a string containing all attributes of this tag
|
// build a string containing all attributes of this tag
|
||||||
const attrs = Object.keys(tag).reduce((attrsStr, attr) => {
|
const attrs = Object.keys(tag).reduce((attrsStr, attr) => {
|
||||||
switch (attr) {
|
switch (attr) {
|
||||||
|
|||||||
Reference in New Issue
Block a user