Project Structure and Configuration#

Sphinx reads the .rst files under source/ and writes a static site to _build/html. Everything about how it does that is set in one file, source/conf.py. This page shows where each file lives and which settings to change when you make the site your own.

Directory layout#

docs/
├── requirements.txt        # Python packages to install
├── source/
│   ├── conf.py             # Sphinx configuration
│   ├── index.rst           # Home page (cards, latest posts)
│   ├── about.rst
│   ├── contact.rst
│   ├── _extra/CNAME        # Copied to the site root; sets the custom domain
│   ├── _static/custom.css  # Extra CSS
│   ├── _templates/         # Navigation bar and footer snippets
│   ├── posts/              # One .rst file per blog post, plus index.rst
│   └── projects/
│       ├── index.rst
│       ├── trade_engine.rst        # Redirect page to separately built docs
│       └── personal_website/       # This section
└── _build/
    └── html/               # Generated site; created by sphinx-build

_build is generated output. Delete it freely, and never edit files inside it.

Dependencies#

requirements.txt lists what the site needs:

Sphinx>=8.2
ablog>=0.11
numpydoc>=1.5
pydata-sphinx-theme>=0.16
sphinx-design>=0.6
sphinx-mathjax-offline>=0.0.2
sphinxcontrib-youtube>=1.4

Extensions#

Extensions add features to Sphinx and are listed in conf.py:

extensions = [
    'sphinx.ext.extlinks',
    'sphinx.ext.intersphinx',
    'sphinx.ext.todo',
    'ablog',
    'sphinxcontrib.youtube',
    'sphinx.ext.mathjax',
    'sphinx-mathjax-offline',
    'numpydoc',
    'sphinx.ext.graphviz',
    'sphinx_design',
    'sphinx.ext.githubpages',
]

Extension

What it is used for

ablog

Blog posts, tags, categories, archives and the Atom feed (see Posts).

sphinx_design

Cards, grids, buttons, badges and tabs, such as the home page cards.

sphinx.ext.mathjax, sphinx-mathjax-offline

Rendering maths written with .. math:: and :math:. The offline package bundles MathJax with the site.

sphinx.ext.graphviz

The graphviz directive for diagrams. Needs Graphviz’s dot on your PATH.

sphinxcontrib.youtube

The youtube directive for embedded videos.

sphinx.ext.githubpages

Writes the .nojekyll file that GitHub Pages needs (see GitHub Pages).

sphinx.ext.todo, sphinx.ext.extlinks, sphinx.ext.intersphinx, numpydoc

Optional. Todo notes, link shortcuts, links to other projects’ docs, and NumPy-style docstrings. Remove any you do not use, together with its line in requirements.txt.

Settings to change for your own site#

These settings in conf.py carry the author’s identity and address:

project = "Sam Khalilian"
author = "Sam Khalilian"
html_title = "Sam Khalilian"                  # browser tab title
blog_title = "Sam Khalilian"
blog_baseurl = "https://samkhalilian.dev/"    # public address of the site; used for feed links
blog_authors = {"Sam Khalilian": ("Sam Khalilian", None)}

Setting

What it controls

project, author, copyright

Names used in the page titles and the footer.

blog_baseurl

The address the feed links point to. Set it to where your site will really be served from.

blog_authors

The names allowed in a post’s :author: option.

html_extra_path and _extra/CNAME

Files copied unchanged to the site root. CNAME holds your custom domain; delete it if you have none.

html_theme_options

Logo text, social links, banner and footer. See Theme and Customisation.

Other values, such as language and today_fmt, can stay as they are.