Skip to content

Commit

Permalink
✨ Add extends field to myst.yml for composing multiple yamls (#1215)
Browse files Browse the repository at this point in the history
* 🔧 Refactor config loading to separate validation from saving
* 🏄‍♀️  Add extend key to top-level config
* ⛽️ Load and fill frontmatter from extend config key
* 🔄 Support circular deps and live reloading for extending config
* 🧪 Add page frontmatter to extend-config test
* 📚 Move composing-myst-yml from note to section in docs
  • Loading branch information
fwkoch committed May 21, 2024
1 parent 72a127c commit f4d5231
Show file tree
Hide file tree
Showing 24 changed files with 453 additions and 114 deletions.
5 changes: 5 additions & 0 deletions .changeset/green-brooms-applaud.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'myst-cli': patch
---

Support circular deps and live reloading for extending config
6 changes: 6 additions & 0 deletions .changeset/large-peas-melt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'myst-frontmatter': patch
'myst-cli': patch
---

Load and fill frontmatter from extend config key
6 changes: 6 additions & 0 deletions .changeset/many-worms-know.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'myst-config': patch
'myst-cli': patch
---

Add extend key to top-level config
5 changes: 5 additions & 0 deletions .changeset/stupid-experts-pull.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'myst-cli': patch
---

Refactor config loading to separate validation from saving
18 changes: 18 additions & 0 deletions docs/frontmatter.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,24 @@ project:
open_access: true
```
(composing-myst-yml)=
#### Composing multiple `.yml` files

You may separate your frontmatter into multiple, composable files. To reference other files from your main `myst.yml` file, use the `extends` key with relative path(s) to the other configuration files:

```yaml
version: 1
site: ...
project: ...
extends:
- ../macros.yml
- ../funding.yml
```

Each of these files listed under `extends` must contain valid `myst.yml` structure with `version: 1` and `site` or `project` keys. They may also have additional files listed under `extends`.

Composing files together this way allows you to have a single source of truth for project frontmatter that may be reused across multiple projects, for example math macros or funding information.

+++

## Available frontmatter fields
Expand Down
2 changes: 1 addition & 1 deletion docs/quickstart-myst-websites.md
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ site:
...
```

Doing this will keep the `_build` directory at the root level, but everything else outside of the `content` folder will be ignored. If you have a project in the same configuration file it can be accessed with `path: .`. Projects are "mounted" at the `slug:` (i.e. `/my-content/`) above.
Doing this will keep the `_build` directory at the root level, but everything else outside of the `content` folder will be ignored. If you have a project in the same configuration file it can be accessed with `path: .`. Projects are "mounted" at the `slug:` (e.g. `/my-content/` above).
:::

## Additional options
Expand Down
12 changes: 9 additions & 3 deletions packages/myst-cli/src/build/site/watch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ function watchConfigAndPublic(
opts: ProcessSiteOptions,
) {
const watchFiles = ['public'];
const siteConfigFile = selectors.selectCurrentSiteFile(session.store.getState());
const state = session.store.getState();
const siteConfigFile = selectors.selectCurrentSiteFile(state);
if (siteConfigFile) watchFiles.push(siteConfigFile);
watchFiles.push(...selectors.selectConfigExtensions(state));
return chokidar
.watch(watchFiles, {
ignoreInitial: true,
Expand All @@ -37,6 +39,7 @@ function triggerProjectReload(
const projectConfigFile = projectPath
? selectors.selectLocalConfigFile(state, projectPath)
: selectors.selectCurrentProjectFile(state);
if (selectors.selectConfigExtensions(state).includes(file)) return true;
if (file === projectConfigFile || basename(file) === '_toc.yml') return true;
// Reload project if file is added or remvoed
if (['add', 'unlink'].includes(eventType)) return true;
Expand Down Expand Up @@ -64,8 +67,11 @@ async function processorFn(
!KNOWN_FAST_BUILDS.has(extname(file)) ||
['add', 'unlink'].includes(eventType)
) {
let reloadProject = false;
if (file && triggerProjectReload(session, file, eventType, siteProject?.path)) {
let reloadProject = opts?.reloadProject ?? false;
if (
reloadProject ||
(file && triggerProjectReload(session, file, eventType, siteProject?.path))
) {
session.log.info('💥 Triggered full project load and site rebuild');
reloadProject = true;
} else {
Expand Down
Loading

0 comments on commit f4d5231

Please sign in to comment.