Integrating ESP-Docs into Your Project
This document describes how to integrate ESP-Docs into your project to continuously build and deploy your documentation to a server, such as Espressif’s server docs.espressif.com (recommended for Espressif software documentation).
While performing the steps in this document, you can always refer to the documentation that has already been deployed to Espressif’s server as examples, such as ESP-IDF Programming Guide, ESP-AT User Guide, esptool.py Documentation, and ESP-Docs User Guide.
The process to integrate ESP-Docs can be broken down into the following steps:
Get Familiar with the Documentation Folder
The contents of the basic documentation folder are described below to provide more details about the folder structure and the function of each file. Your folder might look slightly different, but being familiar with these building blocks will help you better understand the following steps in this document.
_static: contains graphics files, sources of diagrams, attachments not shown directly in the documentation (e.g., schematics) as well as other resources, such as font files.docs_version.js: configures target and version information displayed in HTML layout, such as the target and language selector in the top-left corner of ESP-IDF Programming Guide.periph_timing.json: sample figure in JSON format.
en: English language folder that contains English documents and a build configuration file.conf.py: build configuration file that contains configuration information specific to the English documents, such as the English copyright information.index.rst: English homepage that defines documentation structure with a table of contents tree (toctree). See Defining document structure for more information.subpage.rst: sample subpage ofindex.rst.
zh_CN: the same asenbut for the Simplified Chinese language.conf.py: the same asen/conf.pybut for the Chinese documents.index.rst: the same asen/index.rstbut for the Chinese documents.subpage.rst: the same asen/subpage.rstbut in Chinese.
README.md: introduction to thedocsfolder.build_example.sh: contains the command to simplify building this sample documentation.conf_common.py: contains the build configuration information common to both English and Chinese documents. The contents of this file are imported during the building process for each language to the standard Sphinx configuration fileconf.pylocated in respective language folders (e.g.docs/en,docs/zh_CN). See Sphinx Configuration for more information.requirements.txt: package dependencies and their versions for building documentation, such as ESP-Docs.
Prepare a Documentation Folder
Copy one of the following sample documentation folders to the root directory of your project depending on whether the project needs support for target, version, or building API documentation from header files:
Doc Folder
Target
Version
API Doc
Y
Y
–
Y
Y
Y
–
Y
Y
–
–
Y
Y
–
Y
Rename the folder to
docs.Delete the
build_example.shfile (if there is one).(Optional) Go to
docs/requirements.txtand change the ESP-Docs version as needed. ESP-Docs follows the semantic versioning scheme. For features supported by each release, please see release history.
Update Build Configuration Files
Build configuration files are where you set the variables that are affecting the final documentation output built with ESP-Docs. As mentioned in Get Familiar with the Documentation Folder, there should be two types of configuration files in each project:
conf_common.pyen/conf.pyandzh_CN/conf.py
The configuration files in the sample documentation folder configure how to build the sample documentation instead of your documentation, so you need to reconfigure a few variables for your documentation.
In
conf_common.py, reconfigure some of the following variables based on your needs:
languages: supported languages, such asenandzh_CN. It must be set to at least one language element, namely the current project’s language.
idf_targets: project target used as a URL slug, such asesp32inhttps://docs.espressif.com/projects/esp-idf/en/latest/esp32/. The variable is optional, but you should set either both this variable andidf_targetor neither. For more information aboutidf_target, see Build System Integration .
extensions: extensions that add more functionalities to ESP-Docs, such assphinx_copybuttonandsphinxcontrib.wavedrom.
github_repo: GitHub repository to which the links generated by link_roles.py point.
html_context['github_user']: GitHub user name used by sphinx_idf_theme.
html_context['github_repo']: GitHub repo name used by sphinx_idf_theme.
html_static_path: path to the_staticfolder.
project_slug: short name of the project as a URL slug, such asesp-docs.
versions_url: URL from which to download theversions.jsfile. If it is specified as a relative URL, such as_static/docs_version.js, the file will be downloaded relative to theHTMLroot folder.
pdf_file_prefix: PDF filename prefix used for generating the link to download the PDF together with the target and version name.
In
en/conf.pyandzh_CN/conf.py, reconfigure some of the following variables based on your needs:
project: name of your documentation in HTML, such as ESP-IDF Programming Guide, ESP-AT User Guide.
copyright: copyright statement.
pdf_title: name of your documentation in PDF.
language: language for content autogenerated by ESP-Docs.
Update CI Configuration File
Note
The following descriptions assume you are using Gitlab CI for building documentation and deploying it to www.espressif.com, and will have to be tweaked if you are running something else for CI/CD.
The GitLab CI configuration file, .gitlab-ci.yml, is where you add jobs to enable the automatic and continuous building and deploying of your documentation to the www.espressif.com server.
In the .gitlab-ci.yml of your project, do the steps given below. For examples, please refer to esp-docs/.gitlab-ci.yml and esp-idf/.gitlab/ci/docs.yml.
Use an appropriate docker image to build the documentation. For convenience, you can reuse the image used by ESP-IDF,
$CI_DOCKER_REGISTRY/esp-idf-doc-env-v5.0:2-3. For the latest version of this image, go to Documentation Team Site > Section ESP-Docs User Guide > esp-idf-doc-env image.Add the jobs to build documentation in HTML and PDF. For examples, please refer to the
build_esp_docs_htmlandbuild_esp_docs_pdfjobs in .gitlab-ci.yml.In the above building documentation jobs, add
pip install -r requirements.txtto install package dependencies.Add the jobs to deploy the built documentation to the server:
Copy and paste the
.deploy_docs_templateanddeploy_docs_esp_docsjobs from .gitlab-ci.yml to your.gitlab-ci.yml.Write the job for deploying your documentation based on the
deploy_docs_esp_docsjob.
Note
If your project is hosted on GitLab and the updates made in GitLab later are synchronized to GitHub, in such case, please only run deploy_docs job after the job that synchronizes your repository to GitHub. This is crucial because if synchronization to GitHub fails, the links within your documentation that refer to the GitHub project may not function correctly.
Configure the required environment variables depending on your project:
a:
ESP_DOCS_LATEST_BRANCH_NAME: decides which git branch will be built and deployed aslatest. Defaults tomasterand should therefore be changed to e.g.mainif that is the naming scheme of your master branch in your git repo.
Configure the variables mentioned in the jobs that deploy documentation:
Find out who the server’s admin is. To know who this person is and more information about the variables, please go to Documentation Team Site > Section ESP-Docs User Guide > Deploying documentation to docs.espressif.com.
Ask the admin to create an SSH key for you and a directory for your documentation on the server.
Go to your project’s Settings > CI/CD and expand the Variables section. Select Add variable and fill in the details for your variables. For more information on how to add a variable to a project, see the GitLab documentation.
What’s Next?
Push your changes to GitLab and check if the pipeline passes.
If yes, you can check the Artifacts to see what the built sample documentation looks like.
Now it is time to put your reST source files into the respective language folder and have them built and deployed!