Overwrite ManifestsMeta Data - vuejs2

I have a Manifest with stuff like name etc. which also instantly brings out meta tags for my page. Now I wanna use Meta Tags on my individual Pages, the problem is that the Manifest Meta Tags dont get overwritten which leads to them having higher priority for sites like Facebook etc.
Example Manifest:
manifest: {
theme_color: '#1a1a1a',
name: 'Stackoverflow',
short_name: 'SO',
description: 'Questions and Answers',
lang: 'de'
},
Example change in the Page:
head () {
return {
meta: [
{ name: 'og:url', content: 'www.notstackoverflow.com' },
{ name: 'og:type', content: 'article' },
{ name: 'og:title', content: this.post.titel },
{ name: 'og:description', content: this.post.subtitel },
]
}
},
The problem is that it still uses the title and description from the manifest instead of the page. It only adds the ones from the page after the manifest ones if I go on View Source.
(Nuxt + PWA Module)

you must add the hid property for each meta:
head () {
return {
meta: [
{ hid: 'og:url', name: 'og:url', content: 'www.notstackoverflow.com' },
{ hid: 'og:type', name: 'og:type', content: 'article' },
{ hid: 'og:title', name: 'og:title', content: this.post.titel },
{ hid: 'og:description', name: 'og:description', content: this.post.subtitel },
]
}
},
see https://nuxtjs.org/faq/duplicated-meta-tags
To avoid any duplication when used in child component, please give a unique identifier with the "hid" key.

Related

replace the page meta and link with global meta on nuxt

Why doesn't the local configuration for meta title and description override the global configuration
The problem is that when I change the meta tags and links on the page, it removes the meta tags that are global and replaces the new meta tags. I want these meta and links to be added to the global meta and links.
In the meta tag and global links that I have, I have a part that makes the logo part of the site correct when adding a bookmark in Safari, but when I add the meta tag to my page, the photo is no longer loaded, and I think the problem is from It is that Next replaces the meta tags that are created on each page instead of the global meta tags
Code
**this is my nuxt config code**
head: {
title: 'Flyver',
htmlAttrs: {
lang: 'en',
},
meta: [
.........
{ charset: 'utf-8' },
{
name: 'viewport',
hid: 'viewport',
content:
'width=device-width,initial-scale=1,shrink-to-fit=no,maximum-scale=5,viewport-fit=cover',
},
{ hid: 'description', name: 'description', content: '' },
{ name: 'format-detection', content: 'telephone=no' },
{
hid: 'apple-mobile-web-app-status-bar-style',
name: 'apple-mobile-web-app-status-bar-style',
content: 'black-translucent',
},
.........
],
link: [
.........
{
hid: 'apple-touch-icon',
rel: 'apple-touch-icon',
href: '/android-chrome-180x180.png?v=sf54fgh123',
type: 'image/png',
sizes: '180x180',
},
{
hid: 'apple-touch-icon1',
rel: 'apple-touch-icon',
href: '/apple-touch-icon.png?v=sf54fgh123',
type: 'image/png',
sizes: '120x120',
},
.........
},
this is my index page**
async fetch() {
........
this.headValue = {
title: this.pageData?.value?.title,
link: [
{
rel: 'canonical',
href: `https://flyver.ir`,
},
],
meta: [
{
name: 'description',
content: this.pageData?.value?.description,
},
...this.pageData?.metaTags,
],
};
..........
},
head() {
return this.headValue;
},
What is Expected?
I expect the meta tags that are created per page to be added to the global meta tags
What is actually happening?
Replaces new meta tags with global meta tags

How to get config head setting to set page og:title in Nuxt2 (vue.js)?

I am using Nuxt.js to build my project.
I have set the head in nuxt.config.js and want to get the settings in the page.
// nuxt.config.js
export default {
...
head: {
title: 'SITE NAME',
titleTemplate: '%s | SITE NAME',
meta: [
{ charset: 'utf-8' },
{ 'http-equiv': 'X-UA-Compatible', content: 'IE=edge' },
{ name: 'viewport', content: 'width=device-width, initial-scale=1' },
{ hid: 'description', name: 'description', content: 'SITE DESCRIPTION' },
{ hid: 'itemprop-name', itemprop: 'name', content: 'SITE NAME' },
{ hid: 'itemprop-description', itemprop: 'description', content: 'SITE DESCRIPTION' },
{ hid: 'itemprop-image', itemprop: 'image', content: process.env.BASE_URL + '/assets/img/og_img.png' },
{ hid: 'og:site_name', property: 'og:site_name', content: 'SITE NAME' },
{ hid: 'og:title', property: 'og:title', content: 'SITE NAME' },
{ hid: 'og:description', property: 'og:description', content: 'SITE DESCRIPTION' },
{ hid: 'og:url', property: 'og:url', content: process.env.BASE_URL },
{ hid: 'og:image', property: 'og:image', content: process.env.BASE_URL + '/assets/img/og_img.png' },
{ hid: 'og:image:width', property: 'og:image:width', content: '1200' },
{ hid: 'og:image:height', property: 'og:image:height', content: '630' },
{ hid: 'og:type', property: 'og:type', content: 'website' },
{ hid: 'twitter:card', name: 'twitter:card', content: 'summary_large_image' },
{ hid: 'twitter:title', name: 'twitter:title', content: 'SITE NAME' },
{ hid: 'twitter:description', name: 'twitter:description', content: 'SITE DESCRIPTION' },
{ hid: 'twitter:image', name: 'twitter:image', content: process.env.BASE_URL + '/assets/img/og_img.png' }
],
},
}
// about.vue (page.vue)
export default {
data () {
return {
pageTitle: 'PAGE TITLE',
description: 'PAGE DESCRIPTION',
}
},
head () {
return {
title: this.pageTitle,
meta: [
{ hid: 'description', name: 'description', content: this.description },
{ hid: 'itemprop-name', itemprop: 'name', content: `${this.pageTitle} | SITE NAME` },
{ hid: 'itemprop-description', itemprop: 'description', content: this.description },
{ hid: 'og:title', property: 'og:title', content: `${this.pageTitle} | SITE NAME` },
{ hid: 'og:description', property: 'og:description', content: this.description },
{ hid: 'twitter:title', name: 'twitter:title', content: `${this.pageTitle} | SITE NAME` },
{ hid: 'twitter:description', name: 'twitter:description', content: this.description }
]
}
}
}
I try to use this.title, this.$config, this.$route.meta, all of them are wrong.
How can I get the nuxt.config.js settings in the page?
Nuxt version: 2.14.5
Node version: 14.16.1
There is no declarative way to get all Nuxt configs that exist in the nuxt.config.js file.
head property in the nuxt.config.js is for adding general head elements to all your pages.
If you want to store a global configuration throughout the project for example the SITE NAME, you need to use publicRuntimeConfig
publicRuntimeConfig: {
siteName: 'SITE NAME'
}
Then you can use it in any component by this.$config.siteName
For more resources.
https://nuxtjs.org/docs/directory-structure/nuxt-config/#publicruntimeconfig

Vue/Nuxt - Meta tags not working correctly

I have followed the meta tag guidelines for my application and used the Facebook, LinkedIn & Twitter validators but its not working as expected.
Facebook is showing the correct tags but throwing the warning The 'og:image' property should be explicitly provided, even if a value can be inferred from other tags.
LinkedIn is not reading the og:image or og:type correctly.
Twitter is not showing the twitter:image.
Is there a problem within my code or maybe an error on the validator scraping the site?
meta: [
{ charset: 'utf-8' },
{ name: 'viewport', content: 'width=device-width, initial-scale=1' },
{ name: 'format-detection', content: 'telephone=no' },
{ name: 'msapplication-TileColor', content: "#da532c" },
{ name: 'theme-color', content: "#0a192f" },
{
hid: 'og:title',
name: 'og:title',
content: 'Thomas Bell - Developer',
},
{
hid: 'description',
name: 'description',
content:
'A self taught developer who loves to code and problem solve. I have a passion for learning and building useful tools to help people while promoting conservation for the planet. Check out my portfolio and get in touch!',
},
{
hid: 'og:description',
name: 'og:description',
content:
'A self taught developer who loves to code and problem solve. I have a passion for learning and building useful tools to help people while promoting conservation for the planet. Check out my portfolio and get in touch!',
},
{
hid: 'og:url',
name: 'og:url',
content: 'https://thomasbell.dev/',
},
{ hid: 'og:locale', name: 'og:locale', content: 'en_US' },
{ hid: 'og:type', name: 'og:type', content: 'website' },
{
hid: 'og:site_name',
name: 'og:site_name',
content: 'Thomas Bell - Web Developer',
},
{
hid: 'og:image',
name: 'og:image',
itemprop: 'image',
content: 'https://thomasbell.dev/images/portfolio.png',
},
{ hid: "og:image:width", name: "og:image:width", content: "1200" },
{ hid: "og:image:height", name: "og:image:height", content: "630" },
{
hid: 'twitter:card',
name: 'twitter:card',
content: 'summary_large_image',
},
{
hid: 'twitter:description',
name: 'twitter:description',
content:
'A self taught developer who loves to code and problem solve. I have a passion for learning and building useful tools to help people while promoting conservation for the planet. Check out my portfolio and get in touch!',
},
{
hid: 'twitter:title',
name: 'twitter:title',
title: 'Thomas Bell - Developer',
},
{
hid: 'twitter:image',
name: 'twitter:image',
content: 'https://thomasbell.dev/images/portfolio.png',
},
{
hid: 'twitter:site',
name: 'twitter:site',
content: '#tombell_95',
},
{
hid: "twitter:creator",
name: "twitter:creator",
content: "#tombell_95",
},
],

Why are my Nuxt/vue pages getting blocked by robot.txt?

This is not a question about best practice within SEO but a question about how to setup config.js and script sections correctly in VUE
I have build my site with Vue/Nuxt and what have earlier been a walk in the park for me with angular, are now causing errors.
My overall problem is that I am not sure if I have build my script section right as my pages are not getting indexed by Google. In my nuxt.config.js file I have build my sitemap, robot.txt and some general meta-tags. For every page I have build dynamic meta tags in their script section.
Google Search Console is giving 3 type of errors.
Some pages are blocked by my robot.txt
Some pages is said to be dublicated rel-canonical
When inspecting my site it cant fint pages without typing in '/' at the end of the URL. This is also seen when using Screaming Frog SEO tool.
My assumption is that I am missing some form of a redirect that makes the crawler index pages ending with '/' as those are getting indexed fine in Search Console?
Nuxt.config.js file (Sections, not all content is showed)
head: {
title: 'NorthArc',
meta: [
{ charset: 'utf-8' },
{ name: 'viewport', content: 'width=device-width, initial-scale=1' },
{ name: 'language', content: 'da_DK' },
{ name: 'robots', content: 'index, follow' },
{ name: 'og:type', content: 'website' },
],
link: [
{ rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' },
]
},
sitemap: {
path: '/sitemap.xml',
hostname: 'https://northarc.dk/',
routes: [
{
url: '/',
changefreq: 'monthly',
priority: 1,
},
{
url: '/team/',
changefreq: 'monthly',
priority: 1,
},
{
url: '/groen-planlaegning/',
changefreq: 'monthly',
priority: 1,
},
{
url: '/strategisk-samarbejde/',
changefreq: 'monthly',
priority: 1,
},
{
url: '/blog/',
changefreq: 'monthly',
priority: 1,
},
{
url: '/blog/er-ruteplanlaegning-svaert/',
changefreq: 'monthly',
priority: 1,
},
{
url: '/blog/automatisk-ruteplanlaegning/',
changefreq: 'monthly',
priority: 1,
},
{
url: '/faq/',
changefreq: 'monthly',
priority: 1,
},
{
url: '/contact/',
changefreq: 'monthly',
priority: 1,
},
{
url: '/policies/',
changefreq: 'monthly',
priority: 1,
}
]
},
robots: {
UserAgent: 'Googlebot',
Disallow: ['/roi', '/pricing'],
Sitemap: 'https://northarc.dk/sitemap.xml',
},
Script section from a page that is said to be blocked bt robot.txt and has dublicated rel-canonical.
<script>
export default {
name: 'home',
head() {
return {
title: 'test',
meta: [
{
hid: 'description',
name: 'description',
content: 'test',
},
{ hid: 'robots', name: 'robots', content: 'index, follow' },
{hid: 'og-title', property: 'og:title', content: 'Fjern spildtid på vejen og minimere antal kørte kilometer'},
{hid: 'og-url', property: 'og:url', content: 'https://northarc.dk/groen-planlaegning'},
{hid: 'og-description', property: 'og:description', content: 'test'},
{hid: 'og-image', property: 'og:image', content: '/Applications/Northarc_landing/assets/Preview_sløret.jpg'},
],
link: [
{
rel: 'canonical',
href: 'https://northarc.dk/groen-planlaegning/'
}
]
}
}
};
</script>
Notes: (change-log)
I have tried to add a '/' to all sites URL in my sitemap and at the rel-canonical for the pages example showed above.
I have tried to change the user of robot.txt to googlebot to disallow two pages. Before the user was set to '*' where it still blocked some pages.
By default Nuxt allows each route without or with a trailing slash, example:
https://northarc.dk/blog
https://northarc.dk/blog/
It can be detect as duplicate content by crawlers.
So you can define which is the main URL with the "canonical" header.
But if you want keep URLs only with a trailing slash at end, you have to allow only route with a trailing slash by the router configuration:
// nuxt.config.js
router: {
trailingSlash: true
}
See docs https://nuxtjs.org/docs/2.x/configuration-glossary/configuration-router#trailingslash
in addition,
you don't need to hardcoded all your routes in the sitemap-module config, it's automatic for all static routes, eg.:
// nuxt.config.js
sitemap: {
hostname: 'https://northarc.dk',
defaults: {
changefreq: 'monthly',
priority: 1,
trailingSlash: true
},
exclude: ['roi', 'pricing'],
trailingSlash: true // if necessary
},

Nuxt.js SEO Practises

I am looking for ways to refactor this:
nuxt.config.js
const headConfig = require('./config/head')
const modulesConfig = require('./config/modules')
const config = {
head: headConfig,
(...)
}
module.exports = Object.assign({}, config, modulesConfig)
config/head.js
module.exports = {
meta: [
{charset: 'utf-8'},
{name: 'viewport', content: 'width=device-width, initial-scale=1'},
{name: 'fb:app_id', content: 'xxxx'},
{hid: 'og:url', name: 'og:url', content: 'xxxx'},
{hid: 'og:type', name: 'og:type', content: 'website'},
{hid: 'og:image', name: 'og:image', content: 'xxxx'},
{hid: 'og:site_name', name: 'og:site_name', content: 'xxxx'},
{hid: 'keywords', name: 'keywords', content: 'xxxx'}
]
}
An example of what I'd like to be able to do is to automatically set the 'og:url' to the url of the page. There is no need to repeat that every time.
At the moment I include this in each page of my Nuxt.js app:
{
hid: 'og:url',
property: 'og:url',
content: 'https://website.com' + this.$route.fullPath
},
I am sure there is a better way to automatically set that somewhere :/
Probably your best bet would be to create a global Mixin:
https://v2.vuejs.org/v2/guide/mixins.html#Global-Mixin
This should allow you to create a head mixin that will be auto-imported into every component, so you could define that og:url once and have it auto-injected everywhere.
Here's an example of how you'd register it as a plugin with Nuxt:
/plugins/headMixin.js
import Vue from 'vue'
export default ({ route }) => {
Vue.mixin({
head() {
return {
meta: [
{
hid: `og:url`,
property: 'og:url',
content: 'https://www.yoursite.com' + route.fullPath
}
]
}
}
})
}
in nuxt.config.js:
plugins: [
'~/plugins/headMixin.js'
]
this is my way
in nuxt.config.js:
head: {
title: 'default title',
meta: [
{ charset: 'utf-8' },
{ name: 'viewport', content: 'width=device-width, initial-scale=1' },
{
hid: 'description',
name: 'description',
content: 'default description'
}
],
link: [
{ rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }
]
},
in default.vue
export default {
head() {
return {
title: `Company - ${this.$route.meta.title}`,
meta: [
{
hid: 'description',
name: 'description',
content: this.$route.meta.description
}
],
}
},
and if you use #nuxtjs/router in router.js
routes: [
{
path: '/page',
name: 'some',
meta: {
title: 'Best seo title',
description: 'Best seo description'
},
component: someComponent,
},
All the data you write in routes. Everything works perfectly.