You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/config.md
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -21,7 +21,7 @@ The following options are supported.
21
21
22
22
## root
23
23
24
-
The path to the source root; defaults to `docs`.
24
+
The path to the source root; defaults to `src`. (Prior to <ahref="https://github.com/observablehq/framework/pull/1253"class="observablehq-version-badge"data-version="prerelease"title="Added in #1253"></a>, the default was `docs`.)
25
25
26
26
## output
27
27
@@ -67,9 +67,9 @@ See the [list of available themes](./themes) for more.
67
67
68
68
## style
69
69
70
-
The path to a custom stylesheet, relative to the source root. This option takes precedence over the [theme option](#theme) (if any), providing more control by allowing you to remove or alter the default stylesheet and define a custom theme.
70
+
The path to a custom stylesheet, relative to the source root (typically `src`). This option takes precedence over the [theme option](#theme) (if any), providing more control by allowing you to remove or alter the default stylesheet and define a custom theme.
71
71
72
-
The custom stylesheet should typically import `observablehq:default.css` to build on the default styles. You can also import any of the built-in themes. For example, to create a stylesheet that builds up on the `air` theme, create a `custom-style.css` file in the `docs` folder, then set the style option to `custom-style.css`:
72
+
The custom stylesheet should typically import `observablehq:default.css` to build on the default styles. You can also import any of the built-in themes. For example, to create a stylesheet that builds up on the `air` theme, create a `custom-style.css` file in the source root, then set the style option to `custom-style.css`:
Copy file name to clipboardExpand all lines: docs/contributing.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -16,7 +16,7 @@ yarn dev
16
16
17
17
Lastly visit <http://127.0.0.1:3000>.
18
18
19
-
The local preview server restarts automatically if you edit any of the TypeScript files, though you may need to reload. The default page is [docs/index.md](https://github.com/observablehq/framework/blob/main/docs/index.md?plain=1); if you edit that file and save changes, the live preview in the browser will automatically update.
19
+
The local preview server restarts automatically if you edit any of the TypeScript files, though you may need to reload. The default page is [`docs/index.md`](https://github.com/observablehq/framework/blob/main/docs/index.md?plain=1); if you edit that file and save changes, the live preview in the browser will automatically update.
Copy file name to clipboardExpand all lines: docs/deploying.md
+4-4Lines changed: 4 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -26,7 +26,7 @@ The first time you deploy a project, you will be prompted to configure the proje
26
26
27
27
When the deploy command finishes, it prints a link to observablehq.cloud where you can view your deployed project. If you choose *private* as the access level, that link will only be accessible to members of your Observable workspace. (You can invite people to your workspace by going to observablehq.com.) If you chose *public*, you can share your project link with anyone. You can change the access level of a project later [from your workspace projects page](https://observablehq.com/select-workspace?next=projects).
28
28
29
-
<divclass="note">The deploy command creates a file at <code>docs/.observablehq/deploy.json</code> with information on where to deploy the project. This file is required for automated deploys. You will need to commit this file to git to deploy via GitHub Actions. (If you have configured a source root besides <code>docs</code>, the file will be placed there instead.)</div>
29
+
<divclass="note">The deploy command creates a file at <code>.observablehq/deploy.json</code> under the source root (typically <code>src</code>) with information on where to deploy the project. This file is required for automated deploys. You will need to commit this file to git to deploy via GitHub Actions.</div>
30
30
31
31
<divclass="tip">To see more available options when deploying:<pre><codeclass="language-sh">npm run deploy -- --help</code></pre></div>
This uses one cache per calendar day (in the `America/Los_Angeles` time zone). If you deploy multiple times in a day, the results of your data loaders will be reused on the second and subsequent runs. You can customize the `date` and `cache-data` steps to change the cadence of the caching. For example you could use `date +'%Y-%U'` to cache data for a week or `date +'%Y-%m-%dT%H` to cache it for only an hour.
121
121
122
-
<div class="note">You’ll need to edit the paths above if you’ve configured a source root other than <code>docs</code>.</div>
122
+
<div class="note">You’ll need to edit the paths above if you’ve configured a source root other than <code>src</code>.</div>
Copy file name to clipboardExpand all lines: docs/files.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -211,11 +211,11 @@ display(total);
211
211
212
212
## Routing
213
213
214
-
Attached files live in the source root (by default `docs`) alongside your Markdown pages. For example, say `index.md` has some JavaScript code that references `FileAttachment("quakes.csv")`:
214
+
Attached files live in the source root (typically `src`) alongside your Markdown pages. For example, say `index.md` has some JavaScript code that references `FileAttachment("quakes.csv")`:
<figcaption>The default home page (<code>docs/index.md</code>) after creating a new project.</figcaption>
170
+
<figcaption>The default home page (<code>src/index.md</code>) after creating a new project.</figcaption>
171
171
</figure>
172
172
173
173
### Test live preview
174
174
175
175
Live preview means that as you save changes, your in-browser preview updates instantly. Live preview applies to Markdown pages, imported JavaScript modules (so-called *hot module replacement*), data loaders, and file attachments. This feature is implemented by the preview server watching files and pushing changes to the browser over a socket.
176
176
177
-
To experience live preview, open <code>docs/index.md</code> in your preferred text editor — below we show Visual Studio Code — and position your browser window so that you can see your editor and browser side-by-side. If you then replace the text “Hello, Observable Framework” with “Hi, Mom!” and save, you should see:
177
+
To experience live preview, open <code>src/index.md</code> in your preferred text editor — below we show Visual Studio Code — and position your browser window so that you can see your editor and browser side-by-side. If you then replace the text “Hello, Observable Framework” with “Hi, Mom!” and save, you should see:
178
178
179
179
<figureclass="wide">
180
180
<picture>
@@ -186,7 +186,7 @@ To experience live preview, open <code>docs/index.md</code> in your preferred te
186
186
187
187
### Create a new page
188
188
189
-
Now let’s add a page for our weather dashboard. Create a new file `docs/weather.md` and paste in the following snippet:
189
+
Now let’s add a page for our weather dashboard. Create a new file `src/weather.md` and paste in the following snippet:
190
190
191
191
````md run=false
192
192
# Weather report
@@ -216,7 +216,7 @@ As evidenced by the code <code class="language-js">1 + 2</code> rendered as <cod
216
216
217
217
Next, let’s load some data. The [National Weather Service (NWS)](https://www.weather.gov/documentation/services-web-api) provides an excellent and free API for local weather data within the United States. We’ll use the `/points/{latitude},{longitude}` endpoint to get metadata for the closest grid point to the given location, and then fetch the corresponding hourly forecast.
218
218
219
-
Create a new file <code>docs/data/forecast.json.js</code> and paste in the following snippet:
219
+
Create a new file <code>src/data/forecast.json.js</code> and paste in the following snippet:
If this barfs a bunch of JSON in the terminal, it’s working as intended. 😅 Normally you don’t run data loaders by hand — Framework runs them automatically, as needed — but data loaders are “just” programs so you can run them manually if you want. Conversely, any executable or shell script that runs on your machine and outputs something to stdout can be a data loader!
286
286
287
287
### File attachments
288
288
289
-
Framework uses [file-based routing](./loaders#routing) for data loaders: the data loader <code>forecast.json.js</code> serves the file <code>forecast.json</code>. To load this file from <code>docs<spanclass="wbr">/</span>weather.md</code> we use the relative path <code>./data<spanclass="wbr">/</span>forecast.json</code>. In effect, data loaders are simply a naming convention for generating “static” files — a big advantage of which is that you can edit a data loader and the changes immediately propagate to the live preview without needing a reload.
289
+
Framework uses [file-based routing](./loaders#routing) for data loaders: the data loader <code>forecast.json.js</code> serves the file <code>forecast.json</code>. To load this file from <code>src<spanclass="wbr">/</span>weather.md</code> we use the relative path <code>./data<spanclass="wbr">/</span>forecast.json</code>. In effect, data loaders are simply a naming convention for generating “static” files — a big advantage of which is that you can edit a data loader and the changes immediately propagate to the live preview without needing a reload.
290
290
291
291
To load a file in JavaScript, use the built-in [`FileAttachment`](./files). In `weather.md`, replace the contents of the JavaScript code block (the parts inside the triple backticks <code>```</code>) with the following code:
292
292
@@ -508,7 +508,7 @@ When deploy completes, Framework will show your project’s URL on observablehq.
508
508
<spanclass="muted">└</span> <spanclass="muted">Deployed project now visible at <u>https://example.observablehq.cloud/hello-framework/</u></span>
509
509
</pre>
510
510
511
-
<divclass="tip">Your deploy configuration is saved to <code>docs<spanclass="wbr">/</span>.observablehq<spanclass="wbr">/</span>deploy.json</code>. When collaborating on a project, you should commit this file to git so your collaborators don’t have to separately configure deploy.</div>
511
+
<divclass="tip">Your deploy configuration is saved to <code>src<spanclass="wbr">/</span>.observablehq<spanclass="wbr">/</span>deploy.json</code>. When collaborating on a project, you should commit this file to git so your collaborators don’t have to separately configure deploy.</div>
Copy file name to clipboardExpand all lines: docs/imports.md
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -67,7 +67,7 @@ If you do not specify an entry point, the default entry point is determined by t
67
67
68
68
Framework downloads `npm:` imports from jsDelivr during preview and build. This improves performance, security, and stability of your built site by removing runtime dependencies on external sites.
69
69
70
-
Downloads from npm are cached in `.observablehq/cache/_npm` within your [source root](./config#root) (`docs` by default). An imported module is downloaded from jsDelivr only if it is not already in the cache. You can clear the cache and restart the server to re-fetch the latest versions of libraries from npm.
70
+
Downloads from npm are cached in `.observablehq/cache/_npm` within your [source root](./config#root) (typically `src`). An imported module is downloaded from jsDelivr only if it is not already in the cache. You can clear the cache and restart the server to re-fetch the latest versions of libraries from npm.
71
71
72
72
Self-hosting of `npm:` imports applies to transitive static and [dynamic imports](#dynamic-imports). In addition to downloading modules, Framework downloads supporting files as needed for [recommended libraries](#implicit-imports) and [`import.meta.resolve`](#import-resolutions). For example, [DuckDB](./lib/duckdb) needs WebAssembly modules, and [KaTeX](./lib/tex) needs a stylesheet and fonts. For dynamic imports and `import.meta.resolve`, Framework is only able to self-host import specifiers that are static string literals.
73
73
@@ -97,7 +97,7 @@ import mime from "mime/lite";
97
97
98
98
Unlike `npm:` imports, Node imports do not support semver ranges: the imported version is determined by what is installed in your `node_modules` directory. Use your package manager (_e.g._, edit your `package.json` and run `npm install`, or run `npm update`) to change which version is imported.
99
99
100
-
Imports from `node_modules` are cached in `.observablehq/cache/_node` within your [source root](./config#root) (`docs` by default). You shouldn’t need to clear this cache as it is automatically managed, but feel free to clear it you like.
100
+
Imports from `node_modules` are cached in `.observablehq/cache/_node` within your [source root](./config#root) (typically `src`). You shouldn’t need to clear this cache as it is automatically managed, but feel free to clear it you like.
101
101
102
102
## Local imports
103
103
@@ -249,7 +249,7 @@ Imported modules are copied to the output root (`dist` by default) during build,
Copy file name to clipboardExpand all lines: docs/loaders.md
+10-10Lines changed: 10 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -139,7 +139,7 @@ Like with any other file, files from generated archives are live in preview (ref
139
139
140
140
## Routing
141
141
142
-
Data loaders live in the source root (typically `docs`) alongside your other source files. When a file is referenced from JavaScript via `FileAttachment`, if the file does not exist, Framework will look for a file of the same name with a double extension to see if there is a corresponding data loader. By default, the following second extensions are checked, in order, with the corresponding language and interpreter:
142
+
Data loaders live in the source root (typically `src`) alongside your other source files. When a file is referenced from JavaScript via `FileAttachment`, if the file does not exist, Framework will look for a file of the same name with a double extension to see if there is a corresponding data loader. By default, the following second extensions are checked, in order, with the corresponding language and interpreter:
143
143
144
144
- `.js` - JavaScript (`node`)
145
145
- `.ts` - TypeScript (`tsx`)
@@ -185,7 +185,7 @@ You can then run the `observable preview` or `observable build` commands as usua
185
185
186
186
</div>
187
187
188
-
Data loaders are run in the same working directory in which you run the `observable build` or `observable preview` command, which is typically the project root. In Node, you can access the current working directory by calling `process.cwd()`, and the data loader’s source location with [`import.meta.url`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/import.meta). To compute the path of a file relative to the data loader source (rather than relative to the current working directory), use [`import.meta.resolve`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/import.meta/resolve). For example, a data loader in `docs/summary.txt.js` could read the file `docs/table.txt` as:
188
+
Data loaders are run in the same working directory in which you run the `observable build` or `observable preview` command, which is typically the project root. In Node, you can access the current working directory by calling `process.cwd()`, and the data loader’s source location with [`import.meta.url`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/import.meta). To compute the path of a file relative to the data loader source (rather than relative to the current working directory), use [`import.meta.resolve`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/import.meta/resolve). For example, a data loader in `src/summary.txt.js` could read the file `src/table.txt` as:
Executable (`.exe`) data loaders are run directly and must have the executable bit set. This is typically done via [`chmod`](https://en.wikipedia.org/wiki/Chmod). For example:
198
198
199
199
```sh
200
-
chmod +x docs/quakes.csv.exe
200
+
chmod +x src/quakes.csv.exe
201
201
```
202
202
203
203
While a `.exe` data loader may be any binary executable (_e.g.,_ compiled from C), it is often convenient to specify another interpreter using a [shebang](<https://en.wikipedia.org/wiki/Shebang_(Unix)>). For example, to write a data loader in Perl:
@@ -220,7 +220,7 @@ Data loaders generate files at build time that live alongside other [static file
220
220
221
221
```ini
222
222
.
223
-
├─ docs
223
+
├─ src
224
224
│ ├─ index.md
225
225
│ └─ quakes.json.sh
226
226
└─ ...
@@ -249,7 +249,7 @@ As another example, say you have a `quakes.zip` archive that includes yearly fil
249
249
250
250
```ini
251
251
.
252
-
├─ docs
252
+
├─ src
253
253
│ ├─ index.md
254
254
│ └─ quakes.zip
255
255
└─ ...
@@ -269,11 +269,11 @@ Becomes this output:
269
269
└─ ...
270
270
```
271
271
272
-
A data loader is only run during build if its corresponding output file is referenced in at least one page. Framework does not scour the source root (`docs`) for data loaders.
272
+
A data loader is only run during build if its corresponding output file is referenced in at least one page. Framework does not scour the source root (typically `src`) for data loaders.
273
273
274
274
## Caching
275
275
276
-
When a data loader runs successfully, its output is saved to a cache which lives in `.observablehq/cache` within the source root (by default `docs`).
276
+
When a data loader runs successfully, its output is saved to a cache which lives in `.observablehq/cache` within the source root (typically `src`).
277
277
278
278
During preview, Framework considers the cache “fresh” if the modification time of the cached output is newer than the modification time of the corresponding data loader source. If you edit a data loader or update its modification time with `touch`, the cache is invalidated; when previewing a page that uses the data loader, the preview server will detect that the data loader was modified and automatically run it, pushing the new data down to the client and re-evaluating any referencing code — no reload required!
279
279
@@ -282,13 +282,13 @@ During build, Framework ignores modification times and only runs a data loader i
282
282
To purge the data loader cache and force all data loaders to run on the next build, delete the entire cache. For example:
283
283
284
284
```sh
285
-
rm -rf docs/.observablehq/cache
285
+
rm -rf src/.observablehq/cache
286
286
```
287
287
288
-
To force a specific data loader to run on the next build instead, delete its corresponding output from the cache. For example, to rebuild `docs/quakes.csv`:
288
+
To force a specific data loader to run on the next build instead, delete its corresponding output from the cache. For example, to rebuild `src/quakes.csv`:
289
289
290
290
```sh
291
-
rm -f docs/.observablehq/cache/quakes.csv
291
+
rm -f src/.observablehq/cache/quakes.csv
292
292
```
293
293
294
294
See [Automated deploys: Caching](./deploying#caching) for more on caching during CI.
0 commit comments