SEO mistakes I've made and how I fixed them
我犯过的 SEO 错误以及如何修复它们
October 13, 2020 / 15 min read
2020 年 10 月 13 日 /阅读 15 分钟
最后更新时间:2021 年 6 月 14 日
From 0 to 90k impressions in about a year, following Search Engine Optimization good practices was key to help to grow my blog and my audience. However, when I started it, I made terrible mistakes that some SEO literate people could almost qualify as self-sabotage.
大约一年内,展示次数从 0 增加到 9 万,遵循搜索引擎优化良好实践是帮助扩大我的博客和受众的关键。然而,当我开始时,我犯了一些可怕的错误,一些有 SEO 知识的人几乎可以称之为自我破坏。
Thus, I want to dedicate this blog post to look back at 3 issues that caused me, and many others, countless headaches when dealing with SEO and Gatsby and the steps I took to fix them. I hope that this will help to fix some issues you might currently have on your awesome blog or portfolio without even being aware of them, kick-off your audience growth, and get discovered online 🚀.
因此,我想在这篇博文中回顾一下在处理 SEO 和 Gatsby 时给我和其他许多人带来无数头痛的 3 个问题,以及我为解决这些问题所采取的步骤。我希望这将有助于解决您目前在精彩博客或作品集上可能存在的一些问题,甚至您自己都没有意识到,从而启动您的受众增长,并在网上被发现🚀。
为什么SEO如此重要?
Why SEO is so important?You might know very little about what SEO does behind the scenes. To me, at least, it looked like an obscure, inconsistent, pseudo-science that only marketing people could understand (spoiler alert, it still kind of is).
However, after getting @monicalent's awesome course bloggingfordevs, it made the inner workings and good practices related to SEO a bit clearer to me. To quote her from her first newsletter
您可能对 SEO 幕后的作用知之甚少。至少对我来说,它看起来像是一门晦涩难懂、不一致的伪科学,只有营销人员才能理解(剧透警告,它仍然是这样)。然而,在学习了 @monicalent 的精彩课程 bloggingfordevs 之后,它让我对 SEO 相关的内部运作和良好实践有了更清晰的了解。引用她的第一份时事通讯
SEO is a way of making sure that search engines can understand what your page is about, that it contains quality up-to-date information from an authoritative source, and will answer the question that the searcher had in mind.
SEO 是一种确保搜索引擎能够理解您的页面的内容、包含来自权威来源的优质最新信息并回答搜索者想到的问题的方法。
With good SEO, search engines can know what your content is about, discover all the blog posts you've written and, if you're lucky, catapult you to the top search result for a given set of keywords. Moreover, where sharing my newest articles on Twitter and Reddit would just cause a spike in traffic for a few days, SEO helps you get a more consistent traffic on your website, and for a longer time. The latter is what I was lacking for the longest time, despite having set up my Gatsby website and SEO component properly (or at least I thought so).
通过良好的搜索引擎优化,搜索引擎可以知道您的内容是关于什么的,发现您写的所有博客文章,如果幸运的话,可以将您推到给定关键字集的最佳搜索结果中。此外,在 Twitter 和 Reddit 上分享我的最新文章只会导致几天内的流量激增,而 SEO 可以帮助您在网站上获得更稳定的流量,并且持续时间更长。尽管我已经正确设置了我的 Gatsby 网站和 SEO 组件(或者至少我是这么认为的),但后者是我长期以来所缺乏的。
Gatsby's documentation has an incredibly well-written section on how to build an SEO component to help you get started. However, that alone wasn't enough to make my blog discoverable early on, as you can see in the chart below representing the number of daily impressions I got since starting this blog:
Gatsby 的文档中有一个写得非常好的部分,介绍如何构建 SEO 组件来帮助您入门。然而,仅凭这一点还不足以让我的博客尽早被发现,正如您在下面的图表中看到的那样,该图表代表了我自开始此博客以来获得的每日印象数:
Chart representing the number of impressions per day of this blog on Google
Search from August 2019 to the October 2020 (hover to see the data)
该图表表示 2019 年 8 月至 2020 年 10 月期间此博客在 Google 搜索上的每日展示次数(将鼠标悬停即可查看数据)
For most of its first year, my blog was getting less than 50 daily impressions. Today, after fixing the issues I'm about to talk about, I get over 1000 daily impressions and it's still growing!
Of course, SEO is not the only component here, I also created more content this year and choose a better way to promote them, but it is still a significant driver to the growth you can see above.
在第一年的大部分时间里,我的博客每天的浏览量不到 50 次。今天,在解决了我要讨论的问题后,我每天获得的印象数超过 1000,而且还在不断增长!当然,搜索引擎优化并不是这里唯一的组成部分,我今年还创建了更多内容并选择了更好的方式来推广它们,但它仍然是您在上面看到的增长的重要驱动力。
Trailing slashes chaos 尾随斜线混乱
The blog you're reading this article on is built with Gatsby and hosted on Netlify. Sadly, using these two tools together without taking care of inconsistent trailing slash /
at the end of your URLs can result in some undesirable outcomes.
您正在阅读本文的博客是使用 Gatsby 构建并托管在 Netlify 上。遗憾的是,同时使用这两个工具而不注意 URL 末尾不一致的尾部斜杠 /
可能会导致一些不良结果。
One of these outcomes was that I was seeing a lot of 301
redirects logged in my analytics as readers were navigating to my articles. On my blog, a link to one of my blog posts would typically look like this: /posts/learning-in-public
but when a reader clicked on it Netlify would append a trailing slash at the end of it thus redirecting the user.
结果之一是,当读者导航到我的文章时,我在分析中看到大量 301
重定向。在我的博客上,我的一篇博客文章的链接通常如下所示: /posts/learning-in-public
,但当读者单击它时,Netlify 会在其末尾添加一个尾部斜杠,从而重定向用户。
That, my friends, is extremely bad for SEO. It impacted several unrelated areas of my website, such as:
我的朋友们,这对于 SEO 来说是极其不利的。它影响了我网站的几个不相关的区域,例如:
- Opengraph images or Twitter cards not being rendered consistently: readers would share a link sometimes with or without the trailing slash which would make it hard for some services to get the proper metadata and thus render a simple link instead of a proper preview card.
Opengraph 图像或 Twitter 卡渲染不一致:读者有时会共享带或不带尾部斜杠的链接,这将使某些服务难以获取正确的元数据,从而呈现简单的链接而不是正确的预览卡。 - Invalid URLs in sitemap: my sitemap is generated automatically at build time with a Gatsby plugin based on the URLs and pages of my website. Since I did not have trailing slashes at the end of my URLs it would generate my sitemap without them which once uploaded to Google Search Console would result in tons of warnings about invalid URLs since Google referenced the ones with the trailing slashes.
站点地图中的 URL 无效:我的站点地图是在构建时使用 Gatsby 插件根据我网站的 URL 和页面自动生成的。由于我的网址末尾没有尾部斜杠,因此它会生成没有它们的站点地图,一旦上传到 Google Search Console,就会导致大量有关无效网址的警告,因为 Google 引用了带有尾部斜杠的网址。
我是如何解决这个问题的
How I fixed thisI could have fixed this in two different ways:
我可以用两种不同的方式解决这个问题:
- Disable the "Pretty URLs" option in Netlify's asset optimization settings. (see screenshot below)
禁用 Netlify 资产优化设置中的“漂亮 URL”选项。 (见下面的截图) - Add a trailing slash to all my URLs on my blog.
在我博客上的所有 URL 中添加尾部斜杠。
As Google already referenced my blog posts with a trailing slash, I decided to go with option number 2.
由于 Google 已经引用了我的博客文章,并在后面添加了斜杠,因此我决定采用选项 2。
That change might look insignificant, but it resulted in a lot of weird issues suddenly disappearing. Additionally, it was essential for me to fix this before addressing the issue I'm just about to start talking about 😄!
这个变化可能看起来微不足道,但它导致很多奇怪的问题突然消失。此外,在解决我即将开始谈论的问题之前,我必须解决这个问题!
Canonical links 规范链接
If you've been following me for a while, you might have started reading my content on Medium. I started blog.maximeheckel.com just about a year ago as of the time I'm writing these words. All the content on this site that dates back to before August 2019, was originally published on Medium.
如果您关注我有一段时间了,您可能已经开始在 Medium 上阅读我的内容。大约一年前,也就是我写下这些话的时候,我才创建了 blog.maximeheckel.com。本站2019年8月之前的所有内容最初发布于Medium。
On top of that, I did not edit the articles when migrating them to this website, nor did I delete the Medium ones. This resulted in duplicated content, which meant that my newly deployed blog was in competition with Medium on the same keyword, the same content, from the same author when it comes to ranking on Google.
最重要的是,我在将文章迁移到这个网站时没有编辑这些文章,也没有删除 Medium 的文章。这导致了内容重复,这意味着我新部署的博客在 Google 排名方面与来自同一作者的相同关键字、相同内容、相同的博客展开竞争。
Thankfully there's a way to avoid this: setting canonical URLs. These URLs are placed in the <head>
of your blog posts source code and designate that this post is the "original" post with that given content.
值得庆幸的是,有一种方法可以避免这种情况:设置规范 URL。这些 URL 放置在博客帖子源代码的 <head>
中,并指定该帖子是具有给定内容的“原始”帖子。
There are 2 steps to add valid canonical URLs to your website:
将有效的规范 URL 添加到您的网站有两个步骤:
- You need to add them to the
<head>
of your post. See example below
您需要将它们添加到帖子的<head>
中。请参阅下面的示例 - Head over to any third party platform you used in the past that has the content and add this canonical URL into the setting page of your post. I followed this guide on Medium to update my old blog post.
前往您过去使用过的任何具有该内容的第三方平台,并将此规范 URL 添加到您帖子的设置页面中。我按照 Medium 上的指南更新了我的旧博客文章。
Example of canonical URL 规范 URL 示例
1<link2rel="canonical"3href="https://blog.maximeheckel.com/posts/learning-in-public/"4/>
Of course, you cannot do the first step until you've fixed any potential trailing slashes issues you may have like the ones I shared just above.
当然,在解决了您可能遇到的任何潜在的尾随斜杠问题(如我上面分享的问题)之前,您无法执行第一步。
Simplied version of the SEO component I built with support for canonical URLs
我构建的 SEO 组件的简化版本,支持规范 URL
1import { graphql, StaticQuery } from 'gatsby';2import React from 'react';3import Helmet from 'react-helmet';45const query = graphql`6query SEO {7site {8siteMetadata {9defaultTitle: title10author11keywords12siteUrl: url13defaultDescription: description14twitter15}16}17}18`;1920const SEO = ({ title, desc, image, pathname, date }) => (21<StaticQuery22query={query}23render={({24site: {25siteMetadata: {26author,27defaultTitle,28siteUrl,29keywords,30defaultDescription,31twitter,32},33},34}) => {35const seo = {36description: desc || defaultDescription,37image: `${siteUrl}${image}`,38date: date ? date : '',39title: title || defaultTitle,40url: `${siteUrl}/${pathname ? `posts/${pathname}` : ''}`,41};4243return (44<Helmet title={seo.title} defer={false}>45<html lang="en" />46<meta name="description" content={seo.description} />47<meta name="image" content={seo.image} />48<link rel="canonical" href={seo.url} />49<meta property="og:url" content={seo.url} />50<meta property="og:type" content="article" />51<meta52name="keywords"53content={keywords && keywords.length > 0 ? keywords.join(`, `) : ''}54/>55<meta property="og:title" content={seo.title} />56<meta property="og:description" content={seo.description} />57<meta property="og:image" content={seo.image} />58<meta name="twitter:card" content="summary_large_image" />59<meta name="twitter:creator" content={twitter} />60<meta name="twitter:site" content={twitter} />61<meta name="twitter:title" content={seo.title} />62<meta name="twitter:description" content={seo.description} />63<meta name="twitter:image" content={seo.image} />64</Helmet>65);66}}67/>68);
Conclusion 结论
In a nutshell: 简而言之:
- Be mindful of the consistency of your trailing slashes! Inconsistencies can lead to poor ranking.
请注意尾部斜杠的一致性!不一致可能会导致排名不佳。 - If you syndicate your content, do not forget to add canonical URLs. I was basically in competition with my own Medium posts up until late this year and missed on a lot more traffic and potential readers.
如果您联合内容,请不要忘记添加规范 URL。直到今年年底,我基本上都在与自己的 Medium 帖子竞争,错过了更多的流量和潜在读者。 - Do not blindly trust gatsby plugins! Especially the ones that inject things in the
<head>
of your pages. If misused, they can be pretty harmful without even you knowing.
不要盲目相信 gatsby 插件!尤其是那些在页面的<head>
中注入内容的。如果滥用,它们可能会在您不知情的情况下造成相当大的危害。 - Check the page source of your website! Inspecting via the dev tools is sometimes not enough to ensure the meta tags are properly injected in your site.
检查您网站的页面来源!通过开发工具进行检查有时不足以确保元标记正确注入您的网站。 - Make sure your meta tags can't be blocked from rendering because of a client side side effect when relying on SSR.
确保您的元标记不会因为依赖 SSR 时的客户端副作用而被阻止渲染。 - When in doubt: Write tests! I dedicated a whole blog post about CI/CD where I showcase how great tests and a great CI/CD pipeline help me keep my peace of mind.
如有疑问:编写测试!我专门写了一篇关于 CI/CD 的博客文章,其中展示了出色的测试和出色的 CI/CD 管道如何帮助我保持内心平静。
If you want to go further into how to build an audience, and learn more about creating content and SEO, I would highly encourage you to follow @monicalent on Twitter as well as her Blogging For Devs course. She's an SEO expert and I learned more about efficient SEO techniques in a single newsletter than I would have otherwise!
如果您想进一步了解如何建立受众群体,并了解有关创建内容和 SEO 的更多信息,我强烈建议您在 Twitter 上关注 @monicalent 以及她的 Blogging For Devs 课程。她是一位 SEO 专家,我在一份时事通讯中学到了比其他方式更多的关于高效 SEO 技术的知识!
Liked this article? Share it with a friend on Twitter or support me to take on more ambitious projects to write about. Have a question, feedback or simply wish to contact me privately? Shoot me a DM and I'll do my best to get back to you.
喜欢这篇文章吗?在 Twitter 上与朋友分享,或者支持我承担更雄心勃勃的项目来撰写。有疑问、反馈或只是想私下联系我?请给我发私信,我会尽力回复您。
Have a wonderful day. 祝你有美好的一天。
– Maxime ——马克西姆
A look back at what I learned fixing my terrible SEO mistakes on my Gatsby websites