Setting up
Observable Notebook Kit
in order to develop notebooks into websites locally
Create your First Project Folder and Set Up the Notebook Kit
The desktop app is a notebook editor that creates, edits and saves, basically, HTML files. (These files have .html as their extension). You will be editing these files inside folders that are organized to use the Observable Notebook Kit. We set all this up in order to be able turn your notebooks into publishable web sites, locally, at first.
- In whatever way is most comfortable for you (and best organized) create a folder called something appropriate like:
ObservableNotebooks. - Inside this folder make another folder called
docs. This is where you will create and store your notebook files. - Open Observable Desktop and then edit the
Untitleddefault document that appears. Edit the title and create a few more MarkDown (md) cells with some (placeholder) text in them. - Select
File —> Save As...to save what you’ve done, with a name based on the title you chose, inside thedocsfolder of your project folder. - Now use your Terminal program and its Command Line Interface (CLI) to navigate to your
ObservableNotebooksproject folder. (If you haven’t done this before, we’ll do it Together First In Workshop and/or ask questions.) - And, if you’ve never done so before, you will need to install
node.jsand a Package Manager callednpm(Node Package Manager). Go to step 8 if you already havenpminstalled, otherwise: - Download the installer for
node.jsthat is best for your computer. If you have a Mac download from here. Verify at the terminal with (on separate lines):node -vnpm -v
(which will show the installed versions of these packages). - Next, at the Terminal prompt type:
npm add @observablehq/notebook-kit - Hopefully you have a plain text editor that you like to use. Find and edit the file
package.json(which has been created by the previous step) so that it looks like this (it’s thescriptspart that needs adding):
{
"dependencies": {
"@observablehq/notebook-kit": "^1.5.0"
},
"scripts": {
"preview": "notebooks preview --root docs --template docs/nochrome.tmpl",
"build": "notebooks build --root docs --template docs/nochrome.tmpl --out ../dist -- docs/*.html"
}
}
- This file refers to another, a template file, called
nochrome.tmplso now you also need to create this file inside yourdocsfolder. Make a new plain text file using you editor and save it in thedocsfolder. Make sure the file name has that.tmplextension. Its contents should look like this:
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style type="text/css">
@import url("observable:styles/index.css");
* {
margin-top:0 !important;
}
html {
background-color: white;
margin:0;
padding:2vw; /* change this to 0 to override default */
border:0;
}
body {
max-width: none;
margin:0;
padding:0;
border:0;
}
</style>
</head>
<body>
<main></main>
</body>
</html>
- Finally (for now) in your terminal, type:
npm run preview. Then typehand hit return. Read and explore what is displayed.
Note
Even once you’ve done all the above and ironed out any bugs, you may still be surprised when you are trying to preview (by running the script and then hitting o+return to ‘Open’ your notebook as a site).
You may get a file not found error because the site that Observable builds for you expects to find a notebook HTML file named index.html as the default entrance to the website it has just built. An immediate fix is to type at the end of whatever is in you browser’s URL box, add the file name of your notebook: <whateverucalledit>.html. Alternatively, you could rename one of your notebook files as index.html.