|
| 1 | +Technical Documentation Search Engine Optimization (SEO) Guide |
| 2 | +============================================================== |
| 3 | + |
| 4 | +.. meta:: |
| 5 | + :description lang=en: |
| 6 | + Looking to optimize your Sphinx documentation for search engines? |
| 7 | + This SEO guide will help your docs be better understood by both people and crawlers |
| 8 | + as well as help you rank higher in search engine results. |
| 9 | + |
| 10 | + |
| 11 | +This guide will help you optimize your documentation for search engines |
| 12 | +with the goal of increasing traffic to your docs. |
| 13 | +While you optimize your docs to make them more crawler friendly for search engine spiders, |
| 14 | +it's important to keep in mind that your ultimate goal is to make your docs |
| 15 | +more discoverable for your users. |
| 16 | +**You're trying to make sure that when a user types a question into a search engine |
| 17 | +that is answerable by your documentation, that your docs appear in the results.** |
| 18 | + |
| 19 | +This guide isn't meant to be your only resource on SEO, |
| 20 | +and there's a lot of SEO topics not covered here. |
| 21 | +For additional reading, please see the |
| 22 | +:ref:`external resources <guides/technical-docs-seo-guide:External resources>` section. |
| 23 | + |
| 24 | +While many of the topics here apply to all forms of technical documentation, |
| 25 | +this guide will focus on Sphinx, which is the most common |
| 26 | +documentation authoring tool on Read the Docs, |
| 27 | +as well as improvements provided by Read the Docs itself. |
| 28 | + |
| 29 | + |
| 30 | +.. contents:: Table of contents |
| 31 | + :local: |
| 32 | + :backlinks: none |
| 33 | + :depth: 3 |
| 34 | + |
| 35 | + |
| 36 | +SEO Basics |
| 37 | +---------- |
| 38 | + |
| 39 | +Search engines like Google and Bing crawl through the internet |
| 40 | +following links in an attempt to understand and build an index |
| 41 | +of what various pages and sites are about. |
| 42 | +This is called "crawling" or "indexing". |
| 43 | +When a person sends a query to a search engine, |
| 44 | +the search engine evaluates this index using a number of factors |
| 45 | +and attempts to return the results most likely to answer that person's question. |
| 46 | + |
| 47 | +How search engines "rank" sites based on a person's query |
| 48 | +is part of their secret sauce. |
| 49 | +While some search engines publish the basics of their algorithms |
| 50 | +(see Google's published details on PageRank), few search engines |
| 51 | +give all of the details in an attempt to prevent users from gaming the rankings |
| 52 | +with low value content which happens to rank well. |
| 53 | + |
| 54 | +Both `Google <https://support.google.com/webmasters/answer/35769>`_ |
| 55 | +and `Bing <https://www.bing.com/webmaster/help/webmaster-guidelines-30fba23a>`_ publish a set of guidelines |
| 56 | +to help make sites easier to understand for search engines and rank better. |
| 57 | +To summarize some of the most important aspects |
| 58 | +as they apply to technical documentation, your site should: |
| 59 | + |
| 60 | +* Use descriptive and accurate titles in the HTML ``<title>`` tag. |
| 61 | +* Ensure your URLs are descriptive. They are displayed in search results. |
| 62 | +* Avoid low content pages or pages with very little original content. |
| 63 | +* Avoid tactics that attempt to increase your search engine ranking |
| 64 | + without actually improving content. |
| 65 | +* Google specifically `warns about automatically generated content`_ |
| 66 | + although this applies primarily to keyword stuffing and low value content. |
| 67 | + High quality documentation generated from source code |
| 68 | + (eg. auto generated API documentation) seems OK. |
| 69 | + |
| 70 | + .. _warns about automatically generated content: https://support.google.com/webmasters/answer/2721306 |
| 71 | + |
| 72 | +While both Google and Bing discuss site performance as an important factor |
| 73 | +in search result ranking, this guide is not going to discuss it in detail. |
| 74 | +Most technical documentation that uses Sphinx or Read the Docs |
| 75 | +generates static HTML and the performance is typically decent |
| 76 | +relative to most of the internet. |
| 77 | + |
| 78 | + |
| 79 | +Optimizing your docs for search engine spiders |
| 80 | +---------------------------------------------- |
| 81 | + |
| 82 | +Once a crawler or spider finds your site, it will follow links and redirects |
| 83 | +in an attempt to find any and all pages on your site. |
| 84 | +While there are a few ways to guide the search engine in its crawl |
| 85 | +for example by using a :ref:`sitemap <guides/technical-docs-seo-guide:Use a sitemap.xml file>` |
| 86 | +or a :ref:`robots.txt file <guides/technical-docs-seo-guide:Use a robots.txt file>` |
| 87 | +which we'll discuss shortly, |
| 88 | +the most important thing is making sure the spider can follow links on your site |
| 89 | +and get to all your pages. |
| 90 | + |
| 91 | +Avoid orphan pages |
| 92 | +~~~~~~~~~~~~~~~~~~ |
| 93 | + |
| 94 | +Sphinx calls pages that don't have links to them "orphans" |
| 95 | +and will throw a warning while building documentation that contains an orphan |
| 96 | +unless the warning is silenced with the :ref:`orphan directive <sphinx:metadata>`: |
| 97 | + |
| 98 | +:: |
| 99 | + |
| 100 | + $ make html |
| 101 | + sphinx-build -b html -d _build/doctrees . _build/html |
| 102 | + Running Sphinx v1.8.5 |
| 103 | + ... |
| 104 | + checking consistency... /path/to/file.rst: WARNING: document isn't included in any toctree |
| 105 | + done |
| 106 | + ... |
| 107 | + build finished with problems, 1 warning. |
| 108 | + |
| 109 | +You can make all Sphinx warnings into errors during your build process |
| 110 | +by setting ``SPHINXOPTS = -W --keep-going`` in your Sphinx Makefile. |
| 111 | + |
| 112 | + |
| 113 | +Avoid uncrawlable content |
| 114 | +~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 115 | + |
| 116 | +While typically this isn't a problem with technical documentation, |
| 117 | +try to avoid content that is "hidden" from search engines. |
| 118 | +This includes content hidden in images or videos |
| 119 | +which the crawler may not understand. |
| 120 | +For example, if you do have a video in your docs, |
| 121 | +make sure the rest of that page describes the content of the video. |
| 122 | + |
| 123 | +When using images, make sure to set the image alt text or set a caption on figures. |
| 124 | +For Sphinx, the image and figure directives support this: |
| 125 | + |
| 126 | +.. sourcecode:: rst |
| 127 | + |
| 128 | + .. image:: your-image.png |
| 129 | + :alt: A description of this image |
| 130 | + |
| 131 | + .. figure:: your-image.png |
| 132 | + |
| 133 | + A caption for this figure |
| 134 | + |
| 135 | + |
| 136 | +Redirects |
| 137 | +~~~~~~~~~ |
| 138 | + |
| 139 | +Redirects tell search engines when content has moved. |
| 140 | +For example, if this guide moved from ``guides/technical-docs-seo-guide.html`` to ``guides/sphinx-seo-guide.html``, |
| 141 | +there will be a time period where search engines will still have the old URL in their index |
| 142 | +and will still be showing it to users. |
| 143 | +This is why it is important to update your own links within your docs as well as redirecting. |
| 144 | +If the hostname moved from docs.readthedocs.io to docs.readthedocs.org, this would be even more important! |
| 145 | + |
| 146 | +Read the Docs supports a few different kinds of :doc:`user defined redirects </user-defined-redirects>` |
| 147 | +that should cover all the different cases such as redirecting a certain page for all project versions, |
| 148 | +or redirecting one version to another. |
| 149 | + |
| 150 | + |
| 151 | +Canonical URLs |
| 152 | +~~~~~~~~~~~~~~ |
| 153 | + |
| 154 | +Anytime very similar content is hosted at multiple URLs, |
| 155 | +it is pretty important to set a canonical URL. |
| 156 | +The canonical URL tells search engines where the original version |
| 157 | +your documentation is even if you have multiple versions on the internet |
| 158 | +(for example, incomplete translations or deprecated versions). |
| 159 | + |
| 160 | +Read the Docs supports :doc:`setting the canonical URL </guides/canonical>` |
| 161 | +if you are using a :doc:`custom domain </custom_domains>` |
| 162 | +under :guilabel:`Admin` > :guilabel:`Domains` |
| 163 | +in the Read the Docs dashboard. |
| 164 | + |
| 165 | + |
| 166 | +Use a robots.txt file |
| 167 | +~~~~~~~~~~~~~~~~~~~~~ |
| 168 | + |
| 169 | +A ``robots.txt`` file is readable by crawlers |
| 170 | +and lives at the root of your site (eg. https://docs.readthedocs.io/robots.txt). |
| 171 | +It tells search engines which pages to crawl or not to crawl |
| 172 | +and can allow you to control how a search engine crawls your site. |
| 173 | +For example, you may want to request that search engines |
| 174 | +:ref:`ignore unsupported versions of your documentation <faq:How can I avoid search results having a deprecated version of my docs?>` |
| 175 | +while keeping those docs online in case people need them. |
| 176 | + |
| 177 | +By default, Read the Docs serves a ``robots.txt`` for you. |
| 178 | +To customize this file, you can create a ``robots.txt`` file |
| 179 | +that is written to your documentation root on your default branch/version. |
| 180 | + |
| 181 | +See the `Google's documentation on robots.txt <https://support.google.com/webmasters/answer/6062608>`_ |
| 182 | +for additional details. |
| 183 | + |
| 184 | + |
| 185 | +Use a sitemap.xml file |
| 186 | +~~~~~~~~~~~~~~~~~~~~~~ |
| 187 | + |
| 188 | +A sitemap is a file readable by crawlers that contains a list of pages |
| 189 | +and other files on your site and some metadata or relationships about them |
| 190 | +(eg. https://docs.readthedocs.io/sitemap.xml). |
| 191 | +A good sitemaps provides information like how frequently a page or file is updated |
| 192 | +or any alternate language versions of a page. |
| 193 | + |
| 194 | +Read the Docs generates a sitemap for you that contains the last time |
| 195 | +your documentation was updated as well as links to active versions, subprojects, and translations your project has. |
| 196 | +We have a small separate guide on :doc:`sitemaps </guides/sitemaps>`. |
| 197 | + |
| 198 | +See the `Google docs on building a sitemap <https://support.google.com/webmasters/answer/183668>`_. |
| 199 | + |
| 200 | + |
| 201 | +Use meta tags |
| 202 | +~~~~~~~~~~~~~ |
| 203 | + |
| 204 | +Using a meta description allows you to customize how your pages |
| 205 | +look in search engine result pages. |
| 206 | + |
| 207 | +Typically search engines will use the first few sentences of a page if no meta description is provided. |
| 208 | +In Sphinx, you can customize your meta description using the following RestructuredText: |
| 209 | + |
| 210 | +.. sourcecode:: rst |
| 211 | + |
| 212 | + .. meta:: |
| 213 | + :description lang=en: |
| 214 | + Adding additional CSS or JavaScript files to your Sphinx documentation |
| 215 | + can let you customize the look and feel of your docs or add additional functionality. |
| 216 | + |
| 217 | + |
| 218 | +.. figure:: ../_static/images/guides/google-search-engine-results.png |
| 219 | + :align: center |
| 220 | + :figwidth: 80% |
| 221 | + :target: ../_static/images/guides/google-search-engine-results.png |
| 222 | + |
| 223 | + Google search engine results showing a customized meta description |
| 224 | + |
| 225 | +Moz.com, an authority on search engine optimization, |
| 226 | +makes the following suggestions for meta descriptions: |
| 227 | + |
| 228 | +* Your meta description should have the most relevant content of the page. |
| 229 | + A searcher should know whether they've found the right page from the description. |
| 230 | +* The meta description should be between 150-300 characters |
| 231 | + and it may be truncated down to around 150 characters in some situations. |
| 232 | +* Meta descriptions are used for display but not for ranking. |
| 233 | + |
| 234 | +Search engines don't always use your customized meta description |
| 235 | +if they think a snippet from the page is a better description. |
| 236 | + |
| 237 | +Measure, iterate, & improve |
| 238 | +--------------------------- |
| 239 | + |
| 240 | +Search engines (and soon, Read the Docs itself) can provide useful data |
| 241 | +that you can use to improve your docs' ranking on search engines. |
| 242 | + |
| 243 | + |
| 244 | +Search engine feedback |
| 245 | +~~~~~~~~~~~~~~~~~~~~~~ |
| 246 | + |
| 247 | +`Google Search Console <https://search.google.com/search-console>`_ and |
| 248 | +`Bing Webmaster Tools <https://www.bing.com/webmaster/help/webmaster-guidelines-30fba23a>`_ |
| 249 | +are tools for webmasters |
| 250 | +to get feedback about the crawling of their sites (or docs in our case). |
| 251 | +Some of the most valuable feedback these provide include: |
| 252 | + |
| 253 | +* Google and Bing will show pages that were previously indexed that now give a 404 |
| 254 | + (or more rarely a 500 or other status code). |
| 255 | + These will remain in the index for some time but will eventually be removed. |
| 256 | + This is a good opportunity to create a :ref:`redirect <guides/technical-docs-seo-guide:Redirects>`. |
| 257 | +* These tools will show any crawl issues with your documentation. |
| 258 | +* Search Console and Webmaster Tools will highlight security issues found |
| 259 | + or if Google or Bing took action against your site because they believe it is spammy. |
| 260 | + |
| 261 | + |
| 262 | +Analytics tools |
| 263 | +~~~~~~~~~~~~~~~ |
| 264 | + |
| 265 | +A tool like :doc:`Google Analytics </guides/google-analytics>` |
| 266 | +can give you feedback about the search terms people use to find your docs, |
| 267 | +your most popular pages, and lots of other useful data. |
| 268 | + |
| 269 | +Search term feedback can be used to help you optimize content for certain keywords or for related keywords. |
| 270 | +For Sphinx documentation, or other technical documentation that has its own search features, |
| 271 | +analytics tools can also tell you the terms people search for within your site. |
| 272 | + |
| 273 | +Knowing your popular pages can help you prioritize where to spend your SEO efforts. |
| 274 | +Optimizing your already popular pages can have a significant impact. |
| 275 | + |
| 276 | + |
| 277 | +External resources |
| 278 | +------------------ |
| 279 | + |
| 280 | +Here are a few additional resources to help you learn more about SEO |
| 281 | +and rank better with search engines. |
| 282 | + |
| 283 | +* `Moz's beginners guide to SEO <https://moz.com/beginners-guide-to-seo>`_ |
| 284 | +* `Google's Webmaster Guidelines <https://support.google.com/webmasters/answer/35769>`_ |
| 285 | +* `Bing's Webmaster Guidelines <https://www.bing.com/webmaster/help/webmaster-guidelines-30fba23a>`_ |
| 286 | +* `Google's SEO Starter Guide <https://support.google.com/webmasters/answer/7451184>`_ |
0 commit comments