问题描述
我有一个使用 Nuxt 创建并托管在 Netlify 上的静态博客站点。对于内容,我在 Nuxt 中使用 Markdown 文件和新的 Content module。我使用 Nuxt 和静态内容,以及 vue-meta 用于 SEO 目的,但几个月后,我的覆盖率报告显示多个错误,我无法在 Google 中返回任何页面,即使在搜索网站名称时也是如此或网站上使用的特定文本字符串。
这是我的设置:
<script>
export default {
name: 'Posts',head() {
return {
title: 'Blog Posts',Meta: [
{
hid: 'description',name: 'description',content: 'Example Site blog index'
},{
hid: 'link',name: 'link',content: 'https://example.com/blog'
}
]
}
},async asyncData({ $content,params }) {
const posts = await $content('posts',params.slug)
.only(['title','description','publishDate','slug'])
.sortBy('publishDate','desc')
.fetch()
return {
posts
}
},};
</script>
- 在我的
/blog/_slug/index.vue
页面中,我正在做几乎相同的事情。
export default {
name: 'Post',computed: {
pageConfig() {
return {
identifier: this.post.slug
}
}
},head() {
return {
title: this.post.title,content: this.post.description
},{
property: "og:site_name",hid: "og:site_name",vmid: "og:site_name",content: "My Site Name"
},{
property: "og:title",hid: "og-title",vmid: "og-title",content: this.post.title
},{
property: "og:description",hid: "og-description",vmid: "og-description",{
property: "og:type",hid: "og-type",vmid: "og-type",content: "article"
},{
property: "og:url",hid: "og-url",vmid: "og-url",content: 'https://example.com/blog/' + this.post.slug
},{
hid: "link",name: "link",],link: [
{
rel: 'canonical',href: 'https://example.com/blog/' + this.post.slug
}
]
}
},params }) {
const post = await $content('posts',params.slug).fetch()
return {
post
}
},}
- 我正在使用它在
nuxt.config.js
中生成我的站点地图
sitemap: {
path: '/sitemap.xml',hostname: process.env.BASE_URL,gzip: true,routes: async () => {
let routes = []
const { $content } = require('@nuxt/content')
let posts = await $content('posts').fetch()
for (const post of posts) {
routes.push(`blog/${post.slug}`)
}
return routes
},}
这会在 /sitemap.xml
生成一个具有以下结构的站点地图
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:news="http://www.google.com/schemas/sitemap-news/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:mobile="http://www.google.com/schemas/sitemap-mobile/1.0" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" xmlns:video="http://www.google.com/schemas/sitemap-video/1.1">
<url>
<loc>https://example.com/blog/blog-post-1</loc>
</url>
<url>
<loc>https://example.com/blog/blog-post-2</loc>
</url>
<url>
<loc>https://example.com/blog/blog-post-3</loc>
</url>
</urlset>
- 我向 Google 提交了我的站点地图。
当我在 Google Search Console 中查看我的覆盖率报告时,我有两个主要问题:
- 在
Not Found (404)
下列出了大量帖子,网址为https://example.com/blog/blog/my-blog-post
(网址中有两个/blog
)。我注意到有时在部署到 Netlify 后单击帖子时会发生这种情况。我查看了代码,但找不到在 URL 中添加额外/blog
的位置。 -
Alternate page with proper canonical tag
下的一个同样大的数字。在我将规范标签放入我的/_slug/index/vue
标头之前,我收到了关于缺少规范标签的错误,现在我将其放入,而是出现此错误。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)