Skip to content

How to write docs pages

Marion Schleifer edited this page Oct 22, 2020 · 23 revisions

Purpose

This page explains how to write docs pages so that we have a consistent structure across our whole documentation.

Docs page structure

Meta information

The following meta information should be added at the beginning of each docs page: description and keywords.

An example:

.. meta::
   :description: Data validations in Hasura
   :keywords: hasura, docs, schema, data validation

Reference

Before the page title, add a reference that can be used to link to this page.

An example:

.. _data_validations:

Note: References can also be added above any title within the docs page in order to link to a specific section directly.

Page title

Add a main title for each docs page.

An example:

Data validations
================

Table of contents

Ensure every new added page has a "Table of contents" section with the appropriate depth.

.. contents:: Table of contents
  :backlinks: none
  :depth: 2
  :local:

Introduction

Add an Introduction section:

Introduction
------------

In the section, give a short overview of what the page is about.

General guidelines

Content

  • Add appropriate cross-links in content to assist users. i.e. if you refer to some functionality that is documented in some other docs page, add a link to that page. e.g. if you have a statement like "create a relationship between tables X and Y ...", make "create a relationship" a link to the Create relationships page.
  • Try to make each section within a page self-sufficient. i.e. avoid structuring all pages as step-by-step guides unless it really is the intent. This ensures that we can refer to sections externally (from other docs pages, console, etc.) and expect that the user will be able to follow the section without being lost on context that was set in earlier sections of the page. Adding statements such as "As we have described in the above section ..." might help to set up the needed context.

Header section

  • Page titles should be self sufficient. Users might not have the context of the hierarchy of the page in the docs tree. A user can land on a page via search as well. e.g. Say you are adding a new deployment guide for AWS under Guides -> Deployment -> AWS. The title of this page should not be just AWS but instead AWS deployment guide for Hasura GraphQL engine. It's ok to alias it to just AWS in the sidebar as there the user has the context of the page hierarchy.
  • Ensure heading underlines are the same length as the headings. Short underlines will throw warnings during builds.
  • Use bold in headings in place of string literals for aesthetics (i.e. ** in place of ``).
  • The nesting of headings is as follows:
Main page title
===============

First heading
-------------

Second heading
^^^^^^^^^^^^^^

Third heading
"""""""""""""

Fourth heading
**************

References / links

Internal links

When linking to other docs pages, use references (:ref:) rather than relative links in order to avoid broken links.

An example:

:ref:`data validation <data_validation>`

In this example, data validation is the link text, and <data_validation> is the reference to which the link will point.

External links

When linking to external pages, make sure to add a double _ in the end to avoid Duplicate explicit target name warnings.

An example:

Google <https://www.google.com/>__

Note: If you link to an external resource, make sure to link to the most current version of the same, e.g. https://www.postgresql.org/docs/current/intro-whatis.html rather than https://www.postgresql.org/docs/9.6/intro-whatis.html.

Images

Before adding images to docs, first compress them via some tool to ensure users don't have to unnecessarily download more data than needed. There are several options how to compress images:

Sometimes you can compress images by over 75% without losing any visible quality.

Add images using the thumbnail directive to allow click-to-zoom.

An example:

.. thumbnail:: /img/graphql/manual/schema/validation-add-check-constraint.png
   :alt: Add check constraint
   :width: 700px
  • Add an :alt: tag for all images
  • To adjust the image size, use the :width: tag

Style elements for emphasizing

If you have screenshots in your docs page and you want to emphasize something, please use this color code: #ec1c74.

Generally, if you want to show selecting something, use borders. If you want to show clicking on a button, use arrows.

Notes / Admonitions

A note can be added in order to draw attention to something like limitations, or to link to external reference documentation. It has the title "Notes".

An example:

.. note::
  Please checkout the [Postgres documentation](https://www.postgresql.org/docs/current/functions-comparison.html) for more information.

An admonition is the same as a note, but its title can be defined.

Add an admonition as follows:

.. admonition:: Supported from
  Scheduled triggers are supported from `v.1.3.0` and above.

Note: Make sure to place the note / admonition in a place where the user will see it at the appropriate time.

Code blocks

While adding code blocks ensure the right language type is set. Sometimes adding placeholders breaks the language's syntax in which case you'll have to set the language type to none to avoid warnings during builds.

GraphQL request examples

Our docs have a GraphiQL extension that allows displaying GraphQL requests in the GraphiQL UI.

  • Use a tab width of 2 for nesting the requests and responses for optimal use of the space and maintaining consistency.
  • Nest query arguments for logical readability. Unfortunately GraphiQL prettify does not do a good job of doing this by default.
  • Ensure that the order of fields in the responses is the same as in the requests for better readability.

Use it as follows:

.. graphiql::
  :view_only:
  :query:
    query {
      author_by_pk(id: 1) {
        id
        name
      }
    }
  :response:
    {
      "data": {
        "author_by_pk": {
          "id": 1,
          "name": "Justin"
        }
      }
    }

Run docs build

Run the docs build in the end again with make livehtml and make sure there are no warnings because of duplicate labels etc.

Clone this wiki locally