Website updates#

This page discusses how to make frontend and backend website changes to pigweed.dev, Pigweed’s main documentation website, and how to customize Sphinx, the website generator that powers pigweed.dev.

Image hosting#

Images should not be checked into the Pigweed repository because it significantly slows down the repository cloning process. Images should instead be hosted on Pigweed’s image CDN, https://storage.googleapis.com/pigweed-media.

If you’re adding an image to a pigweed.dev doc, here’s the recommended workflow:

  1. When drafting a change, it’s OK to temporarily check in the image so that there is a record of it in Gerrit.

  2. When your change is almost ready to merge, a Pigweed teammate will upload your image to Pigweed’s image CDN, and then leave a comment on your change asking you to delete the checked-in image and replace the reference to it with the URL to the CDN-hosted image.

Create redirects#

pigweed.dev supports client-side HTML redirects. The redirects are powered by sphinx-reredirects.

To create a redirect:

  1. Open //docs/sphinx/redirects.json.

  1. Create a new key-value pair. The key is the obsolete path that should be redirected. The value is the redirect destination. See Usage.

    • The path in the key should not have a filename extension. The path in the value should.

    • The path in the value should be relative to the path in the key.

    • The path in the value should contain the full HTML filename. E.g. values should be like ./examples/index.html, not ./examples/.

Example of the redirect that sphinx-reredirects auto-generates:

<html>
  <head>
    <meta http-equiv="refresh" content="0; url=pw_sys_io_rp2040/docs.html">
  </head>
</html>

Note

Server-side redirects are the most robust solution, but client-side redirects are good enough for our needs:

  • Client-side redirects are supported in all browsers and should therefore work for all real pigweed.dev readers.

  • Client-side redirects were much easier and faster to implement.

  • Client-side redirects can be stored alongside the rest of the pigweed.dev source code.

  • Google Search interprets the kind of client side redirects that we use as permanent redirects, which is the behavior we want. See meta refresh and its HTTP equivalent. The type of client-side redirect we used is called a “instant meta refresh redirect” in that guide.

Auto-generated source code and issues URLS#

In the site nav there’s a Source code and Issues URL for each module. These links are auto-generated. The auto-generation logic lives in //pw_docgen/py/pw_docgen/sphinx/module_metadata.py.

Copy-to-clipboard feature on code blocks#

The copy-to-clipboard feature on code blocks is powered by sphinx-copybutton.

sphinx-copybutton recognizes $ as an input prompt and automatically removes it.

There is a workflow for manually removing the copy-to-clipboard button for a particular code block but it has not been implemented yet. See Remove copybuttons using a CSS selector.

Fonts and typography#

pigweed.dev is taking an iterative approach to its fonts and typography. See b/353530954 for context, examples of how to update fonts, and to leave feedback.

Rationale for current choices:

  • Headings: Lato. Per UX team’s recommendation.

  • Copy: Noto Sans. Noto is one of two fonts recommended by Material Design 3. It seems to complement Lato well. See Typography.

  • Code: Roboto Mono. Also per UX team’s recommendation. Roboto Mono is mature and well-established in this space.

Sitemap generation#

https://pigweed.dev/sitemap.xml is generated by the custom Sphinx Extension located at //docs/sphinx/_extensions/sitemap.py. A custom extension is necessary because the pigweed.dev production server redirects pages that end in …/docs.html to …/ (e.g. pigweed.dev/pw_string/docs.html redirects to pigweed.dev/pw_string/) and no third-party extension supports the kind of URL rewrite customization that we need. See b/386257958.

Google Analytics ID#

The pigweed.dev Google Analytics ID is not hardcoded anywhere in the upstream Pigweed repo. It is passed through the environment like this:

  1. Docs builders provide a Google Analytics ID as a command line argument.

  2. //docs/sphinx/conf.py looks for the existence of a GOOGLE_ANALYTICS_ID OS environment variable and passes the variable along to Sphinx when found.

  3. //pw_docgen/py/pw_docgen/sphinx/google_analytics.py looks for the Sphinx build environment variable and injects the ID (and related JavaScript code) into each page’s HTML when found.

Passing the ID through the environment helps us ensure that the production ID is only used when someone views the docs from the production domain (pigweed.dev).