Skip to article frontmatterSkip to article content
Jupyter Book tutorial

Create a website

Build a website with Jupyter Book

πŸ›  Throughout the tutorial, whenever you’re supposed to do something you will see a πŸ› 

Build your first bookΒΆ

Next we’ll download some sample content and use jupyter book start to render it as a local web server!

Download example contentΒΆ

We provide an example project that includes a few simple markdown files and some Jupyter Notebooks. Through the course of the tutorials we will add content to these documents that show off some of the features of MyST.

πŸ›  Download the example content[^no-git], and navigate into the folder:

$ git clone https://github.com/jupyter-book/mystmd-quickstart.git
$ cd mystmd-quickstart

[^no-git]: If you aren't familiar with git, it isn't required for this tutorial, you can download the zip file with the contents from the [quickstart repository](https://github.com/jupyter-book/mystmd-quickstart).

### Initialize Jupyter Book in the content folder πŸš€

Next we will create a `myst.yml` configuration file that is required to render your project.
This is the [configuration file used by MyST](xref:guide/quickstart#initialize-myst-in-the-content-folder), and what Jupyter Book uses to control its behavior.

πŸ›  Run `jupyter book`

The `jupyter book` command is a shortcut for `jupyter book init`, which has a few more options for writing specific parts of the configuration file and a table of contents for your site.

```shell
$ jupyter book

Welcome to the Jupyter Book (via myst) CLI! πŸŽ‰ πŸš€

jupyter book init walks you through creating a myst.yml file.

You can use Jupyter Book (via myst) to:

 - create interactive websites from markdown and Jupyter Notebooks πŸ“ˆ
 - build & export professional PDFs and Word documents πŸ“„

Learn more about this CLI and MyST Markdown at: https://jupyterbook.org


πŸ’Ύ Writing new project and site config file: myst.yml

Preview your book locallyΒΆ

Now that we a valid Jupyter Book project, we can preview it as a website to make sure that Jupyter Book is working properly.

πŸ›  When prompted, type Yes to install and serve your book locally:

? Would you like to run "jupyter book start" now? Yes

or manually serve the quickstart content with the following command:

$ jupyter book start

Starting the server requires a theme, this will download the default book-theme from the MyST themes. This can take up to a minute the first time, and then will be cached in the _build/templates directory.

πŸ• Fetching template metadata from https://api.mystmd.org/templates/site/myst/book-theme
πŸ’Ύ Saved template to path _build/templates/site/myst/book-theme
‡️ Installing web libraries (can take up to 60 s)
πŸ“¦ Installed web libraries in 13 s
πŸ“– Built interactive-graphs.ipynb in 21 ms.
πŸ“– Built paper.md in 32 ms.
πŸ“– Built README.md in 35 ms.
πŸ“š Built 3 pages for myst in 82 ms.

  ✨✨✨  Starting Book Theme  ✨✨✨

⚑️ Compiled in 524ms.

πŸ”Œ Server started on port 3000!  πŸ₯³ πŸŽ‰

  πŸ‘‰  http://localhost:3000  πŸ‘ˆ

πŸ›  Open your web browser to http://localhost:3000[1]

The example site in this tutorial only has three pages and by default the 01-paper.md page is seen in FigureΒ 1, which has minimal styles applied to the content.

The myst theme for the 01-paper.md page without any changes made.

FigureΒ 1:The myst theme for the 01-paper.md page without any changes made.

πŸŽ‰ Congratulations, you just build your first MyST site!

Configuration and structureΒΆ

The final section of this tutorial takes a closer look at the files that we just created, and aspects of your book that can be customized.

Folder structureΒΆ

If you are using a text editor, for example VSCode, open up the folder to explore the files:

quickstart/
  β”œβ”€β”€ πŸ†• _build
  β”‚   β”œβ”€β”€ exports
  β”‚   β”œβ”€β”€ site
  β”‚   β”‚   β”œβ”€β”€ content
  β”‚   β”‚   β”œβ”€β”€ public
  β”‚   β”‚   └── config.json
  β”‚   β”œβ”€β”€ temp
  β”‚   └── templates
  β”‚       β”œβ”€β”€ site/myst/book-theme
  β”‚       └── tex/myst/arxiv_two_column
  β”œβ”€β”€ images
  β”‚   β”œβ”€β”€ image.png
  β”‚   └── image.gif
  β”œβ”€β”€ 01-paper.md
  β”œβ”€β”€ 02-notebook.ipynb
  β”œβ”€β”€ README.md
  └── πŸ†• myst.yml

Running jupyter book init added:

  • myst.yml - the configuration file for your myst project and site
  • _build - the folder containing the processed content and other site assets, which are used by the local web server.

The _build folder also contains your templates (including the site template you installed) and any exports you make (when we build a PDF the exported document will show up in the _build/exports folder). You can clean up the built files at any time using myst clean[2].

Configure site and page optionsΒΆ

If we open and look inside our myst.yml we will see a basic configuration like this:

# See docs at: https://mystmd.org/guide/frontmatter
version: 1
project:
  # title:
  # description:
  keywords: []
  authors: []
  # github:
  # bibliography: []
site:
  template: book-theme
  # title:
  # options:
  #   logo: my_logo.png
  nav: []
  actions:
    - title: Learn More
      url: https://mystmd.org/guide
  domains: []

There are two important parts to the myst.yml:

project:
The project holds metadata about the collection of files, such as authors, affiliations and licenses for all of the files, any of these values can optionally be overridden in a file. To see all of the options see Frontmatter, which includes which fields can be overridden by files in the project.
site:
The site holds template information about the website, such as the logo, navigation, site actions and which template to use.

πŸ›  In myst.yml: Change the β€œ# title:” comment in site to β€œtitle: Fancy Title πŸŽ©β€ and save

Saving the myst.yml will have triggered a β€œfull site rebuild”[3]. Take a look at the browser tab and you’ll see that it has updated:

The site title will control site meta tags, and the browser-tab title, which is appended to each page title in the book-theme.

FigureΒ 2:The site title will control site meta tags, and the browser-tab title, which is appended to each page title in the book-theme.

FootnotesΒΆ
  1. If port 3000 is in use on your machine, an open port will be used instead, follow the link provided in the terminal.

  2. By default the jupyter book clean command doesn’t remove installed templates or cached web responses; however, the function can with a:
    jupyter book clean --all, or
    jupyter book clean --templates --cache.

    Before deleting any folders jupyter book will confirm what is going to happen, or you can bypass this confirmation with the -y option. For example:

    Deleting all the following paths:
    
      - _build/site
      - _build/templates
    
    ? Would you like to continue? Yes
    
    πŸ—‘ Deleting: _build/site
    πŸ—‘ Deleting: _build/templates
  3. If the server stopped, you can restart the server using jupyter book start.