poet 0.7.0

Static site generator with optional MCP server and LLM SEO optimizations
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
pub mod build_project_params;
pub mod build_project_result;
pub mod build_project_result_holder;
pub mod build_project_result_stub;
mod content_document_rendering_context;

use std::collections::BTreeMap;
use std::collections::HashMap;
use std::collections::HashSet;
use std::path::Path;
use std::path::PathBuf;
use std::sync::Arc;

use anyhow::Result;
use anyhow::anyhow;
use dashmap::DashMap;
use log::debug;
use log::info;
use rayon::iter::IntoParallelRefIterator as _;
use rayon::iter::ParallelIterator as _;
use rhai::Dynamic;
use syntect::parsing::SyntaxSet;

use crate::asset_manager::AssetManager;
use crate::author_resolve_result::AuthorResolveResult;
use crate::build_project::build_project_params::BuildProjectParams;
use crate::build_project::build_project_result_stub::BuildProjectResultStub;
use crate::build_project::content_document_rendering_context::ContentDocumentRenderingContext;
use crate::build_timer::BuildTimer;
use crate::content_document::ContentDocument;
use crate::content_document_basename::ContentDocumentBasename;
use crate::content_document_collection::ContentDocumentCollection;
use crate::content_document_collection_ranked::ContentDocumentCollectionRanked;
use crate::content_document_component_context::ContentDocumentComponentContext;
use crate::content_document_front_matter::ContentDocumentFrontMatter;
use crate::content_document_in_collection::ContentDocumentInCollection;
use crate::content_document_linker::ContentDocumentLinker;
use crate::content_document_reference::ContentDocumentReference;
use crate::content_document_source::ContentDocumentSource;
use crate::document_error_collection::DocumentErrorCollection;
use crate::eval_content_document_mdast::eval_content_document_mdast;
use crate::filesystem::Filesystem as _;
use crate::filesystem::memory::Memory;
use crate::find_front_matter_in_mdast::find_front_matter_in_mdast;
use crate::find_table_of_contents_in_mdast::find_table_of_contents_in_mdast;
use crate::generate_sitemap::create_sitemap;
use crate::string_to_mdast::string_to_mdast;

fn render_document<'render>(
    ContentDocumentRenderingContext {
        asset_path_renderer,
        authors,
        available_authors,
        available_collections,
        content_document:
            ContentDocument {
                mdast,
                reference:
                    reference @ ContentDocumentReference {
                        basename_path: _,
                        front_matter,
                        generated_page_base_path: _,
                    },
            },
        content_document_collections_ranked,
        content_document_linker,
        esbuild_metafile,
        is_watching,
        rhai_template_renderer,
        syntax_set,
    }: ContentDocumentRenderingContext<'render>,
) -> Result<String> {
    let component_context = ContentDocumentComponentContext {
        asset_manager: AssetManager::from_esbuild_metafile(esbuild_metafile, asset_path_renderer),
        authors: authors.clone(),
        available_authors,
        available_collections,
        content_document_collections_ranked,
        content_document_linker,
        front_matter: front_matter.clone(),
        is_watching,
        reference: reference.clone(),
        table_of_contents: None,
    };

    let table_of_contents = find_table_of_contents_in_mdast(
        mdast,
        &component_context,
        rhai_template_renderer,
        syntax_set,
    )?;

    let component_context_with_toc = component_context.with_table_of_contents(table_of_contents);

    let layout_content = eval_content_document_mdast(
        mdast,
        &component_context_with_toc,
        rhai_template_renderer,
        syntax_set,
    )?;

    rhai_template_renderer.render(
        &front_matter.layout,
        component_context_with_toc.clone(),
        Dynamic::from_map(front_matter.props.clone()),
        layout_content.into(),
    )
}

pub async fn build_project(
    BuildProjectParams {
        asset_path_renderer,
        authors,
        esbuild_metafile,
        generated_page_base_path,
        generate_sitemap,
        is_watching,
        rhai_template_renderer,
        source_filesystem,
    }: BuildProjectParams,
) -> Result<BuildProjectResultStub> {
    info!(
        "Building project in {}...",
        source_filesystem.base_directory.display()
    );
    info!("Processing content files...");

    let _build_timer = BuildTimer::default();
    let error_collection: DocumentErrorCollection = Default::default();
    let memory_filesystem = Arc::new(Memory::default());
    let syntax_set = SyntaxSet::load_defaults_newlines();

    let mut content_document_basename_by_id: HashMap<String, ContentDocumentBasename> =
        HashMap::new();
    let mut content_document_by_basename: HashMap<
        ContentDocumentBasename,
        ContentDocumentReference,
    > = HashMap::new();
    let mut content_document_collections: HashMap<String, ContentDocumentCollection> =
        HashMap::new();
    let mut content_document_collections_ranked: HashMap<String, ContentDocumentCollectionRanked> =
        HashMap::new();
    let mut content_document_list: Vec<ContentDocument> = Vec::new();
    let mut content_document_sources: BTreeMap<ContentDocumentBasename, ContentDocumentSource> =
        Default::default();

    for file in source_filesystem.read_project_files().await? {
        if file.kind.is_content() {
            let mdast = string_to_mdast(&file.contents)?;
            let front_matter: ContentDocumentFrontMatter = find_front_matter_in_mdast(&mdast)?
                .ok_or_else(|| {
                    anyhow!("No front matter found in file: {:?}", file.relative_path)
                })?;

            let basename_path = file.get_stem_path_relative_to(&PathBuf::from("content"));
            let basename: ContentDocumentBasename = basename_path.clone().into();
            let content_document_reference = ContentDocumentReference {
                basename_path,
                front_matter: front_matter.clone(),
                generated_page_base_path: generated_page_base_path.clone(),
            };

            if let Some(id) = &front_matter.id {
                if content_document_basename_by_id.contains_key(id) {
                    error_collection.register_error(
                        content_document_reference.basename().to_string(),
                        anyhow!("Duplicate document id: #{id} in '{basename}'"),
                    );
                }

                content_document_basename_by_id.insert(id.clone(), basename.clone());
            }

            content_document_by_basename
                .insert(basename.clone(), content_document_reference.clone());
            content_document_list.push(ContentDocument {
                mdast: mdast.clone(),
                reference: content_document_reference.clone(),
            });

            if content_document_reference.front_matter.render {
                let relative_path = format!("{basename}.md");

                content_document_sources.insert(
                    basename,
                    ContentDocumentSource {
                        file_entry: file,
                        mdast,
                        reference: content_document_reference,
                        relative_path,
                    },
                );
            }
        }
    }

    // Validate before/after/parent documents in collections
    for reference in content_document_by_basename.values() {
        // Validate primary collections
        if let Some(primary_collection) = &reference.front_matter.primary_collection
            && !reference
                .front_matter
                .collections
                .placements
                .iter()
                .any(|placement| placement.name == *primary_collection)
        {
            error_collection.register_error(
                reference.basename().to_string(),
                anyhow!(
                    "Document does belong to the collection it claims to be it's primary collection"
                ),
            );
        }

        for collection in &reference.front_matter.collections.placements {
            if let Some(after) = &collection.after
                && !content_document_by_basename.contains_key(after)
            {
                error_collection.register_error(
                    reference.basename().to_string(),
                    anyhow!("Succeeding document does not exist: '{after}'"),
                );
            }

            if let Some(parent) = &collection.parent
                && !content_document_by_basename.contains_key(parent)
            {
                error_collection.register_error(
                    reference.basename().to_string(),
                    anyhow!("Parent document does not exist: '{parent}'"),
                );
            }

            content_document_collections
                .entry(collection.name.clone())
                .or_insert_with(|| ContentDocumentCollection {
                    documents: Default::default(),
                    name: collection.name.clone(),
                })
                .documents
                .push(ContentDocumentInCollection {
                    collection_placement: collection.clone(),
                    reference: reference.clone(),
                })
        }
    }

    for content_document_collection in content_document_collections.values() {
        let content_document_collection_ranked: ContentDocumentCollectionRanked =
            content_document_collection.clone().try_into()?;

        content_document_collections_ranked.insert(
            content_document_collection.name.clone(),
            content_document_collection_ranked,
        );
    }

    if !error_collection.is_empty() {
        return Err(anyhow!("{error_collection}"));
    }

    let authors_arc = Arc::new(authors);

    let available_collections_arc: Arc<HashSet<String>> = Arc::new(
        content_document_collections
            .keys()
            .map(|key| key.to_string())
            .collect::<HashSet<String>>(),
    );
    let content_document_reference_collection_dashmap: DashMap<String, ContentDocumentReference> =
        Default::default();
    let content_document_basename_by_id_arc = Arc::new(content_document_basename_by_id);
    let content_document_by_basename_arc = Arc::new(content_document_by_basename);
    let content_document_collections_ranked_arc = Arc::new(content_document_collections_ranked);
    let content_document_linker = ContentDocumentLinker {
        content_document_basename_by_id: content_document_basename_by_id_arc.clone(),
        content_document_by_basename: content_document_by_basename_arc.clone(),
    };

    content_document_list
        .par_iter()
        .filter(|content_document| {
            if !content_document.reference.front_matter.render {
                debug!(
                    "Document will not be rendered: {}",
                    content_document.reference.basename()
                );

                false
            } else {
                true
            }
        })
        .for_each(|content_document| {
            let AuthorResolveResult {
                found_authors,
                missing_authors,
            } = authors_arc.resolve(&content_document.reference.front_matter.authors);

            for author_name in &missing_authors {
                error_collection.register_error(
                    content_document.reference.basename().to_string(),
                    anyhow!("Author does not exist: '{author_name}'"),
                );
            }

            if !missing_authors.is_empty() {
                return;
            }

            match render_document(ContentDocumentRenderingContext {
                asset_path_renderer: asset_path_renderer.clone(),
                authors: found_authors,
                available_authors: authors_arc.clone(),
                available_collections: available_collections_arc.clone(),
                esbuild_metafile: esbuild_metafile.clone(),
                is_watching,
                content_document,
                content_document_collections_ranked: content_document_collections_ranked_arc
                    .clone(),
                content_document_linker: content_document_linker.clone(),
                rhai_template_renderer: &rhai_template_renderer,
                syntax_set: &syntax_set,
            }) {
                Ok(processed_file) => {
                    match content_document.reference.target_file_relative_path() {
                        Ok(relative_path) => {
                            if let Err(err) = memory_filesystem
                                .set_file_contents_sync(&relative_path, &processed_file)
                            {
                                error_collection.register_error(
                                    content_document.reference.basename().to_string(),
                                    err,
                                );
                            } else {
                                content_document_reference_collection_dashmap.insert(
                                    relative_path.display().to_string(),
                                    content_document.reference.clone(),
                                );
                            }
                        }
                        Err(err) => {
                            error_collection.register_error(
                                content_document.reference.basename().to_string(),
                                anyhow!(err),
                            );
                        }
                    }
                }
                Err(err) => error_collection
                    .register_error(content_document.reference.basename().to_string(), err),
            }
        });

    if generate_sitemap {
        info!("Building sitemap");

        match create_sitemap(
            content_document_by_basename_arc
                .values()
                .filter(|content_document| content_document.front_matter.render),
        ) {
            Ok(sitemap) => {
                if let Err(err) =
                    memory_filesystem.set_file_contents_sync(Path::new("sitemap.xml"), &sitemap)
                {
                    error_collection.register_error("sitemap.xml".to_string(), err);
                }
            }
            Err(err) => {
                error_collection.register_error("sitemap.xml".to_string(), err);
            }
        }
    }

    if error_collection.is_empty() {
        Ok(BuildProjectResultStub {
            esbuild_metafile,
            content_document_linker,
            content_document_sources: Arc::new(content_document_sources),
            memory_filesystem,
        })
    } else {
        Err(anyhow!("{error_collection}"))
    }
}

#[cfg(test)]
mod tests {
    use std::path::Path;
    use std::sync::Arc;

    use anyhow::Result;
    use anyhow::anyhow;
    use tempfile::tempdir;

    use super::build_project;
    use crate::asset_path_renderer::AssetPathRenderer;
    use crate::build_authors::build_authors;
    use crate::build_project::build_project_params::BuildProjectParams;
    use crate::build_project::build_project_result_stub::BuildProjectResultStub;
    use crate::compile_shortcodes::compile_shortcodes;
    use crate::filesystem::Filesystem as _;
    use crate::filesystem::read_file_contents_result::ReadFileContentsResult;
    use crate::filesystem::storage::Storage;

    const LAYOUT_MINIMAL: &str = r#"
fn template(context, props, content) {
  component {
    <!DOCTYPE html>
    <html lang="en">
      <head>
        <title>Test</title>
      </head>
      <body>
        <PrimaryNavigation>nav</PrimaryNavigation>
        {content}
        <ul>
          {
            let ret = [];

            for author in context.authors {
              ret.push(component {
                <li>{author.data.name}</li>
              });
            }

            ret
          }
        </ul>
      </body>
    </html>
  }
}
"#;

    const PRIMARY_NAVIGATION: &str = r#"
fn template(context, props, content) {
  component {
    <nav>{content}</nav>
  }
}
"#;

    async fn build(
        files: &[(&str, &str)],
        generate_sitemap: bool,
    ) -> Result<BuildProjectResultStub> {
        let directory = tempdir()?;
        let source_filesystem = Arc::new(Storage {
            base_directory: directory.path().to_path_buf(),
        });

        for (relative_path, contents) in files {
            source_filesystem
                .set_file_contents(Path::new(relative_path), contents)
                .await?;
        }

        let rhai_template_renderer = compile_shortcodes(source_filesystem.clone()).await?;
        let authors = build_authors(source_filesystem.clone()).await?;

        build_project(BuildProjectParams {
            asset_path_renderer: AssetPathRenderer {
                base_path: "/".to_string(),
            },
            authors,
            esbuild_metafile: Default::default(),
            generated_page_base_path: "/".to_string(),
            generate_sitemap,
            is_watching: false,
            rhai_template_renderer,
            source_filesystem,
        })
        .await
    }

    async fn read(result: &BuildProjectResultStub, relative_path: &str) -> Result<String> {
        match result
            .memory_filesystem
            .read_file_contents(Path::new(relative_path))
            .await?
        {
            ReadFileContentsResult::Found { contents } => Ok(contents),
            ReadFileContentsResult::Directory => Err(anyhow!("{relative_path} is a directory")),
            ReadFileContentsResult::NotFound => Err(anyhow!("{relative_path} was not generated")),
        }
    }

    #[tokio::test]
    async fn renders_content_documents_to_their_target_paths() -> Result<()> {
        let result = build(
            &[
                ("shortcodes/LayoutMinimal.rhai", LAYOUT_MINIMAL),
                ("shortcodes/PrimaryNavigation.rhai", PRIMARY_NAVIGATION),
                ("authors/alice.toml", "name = \"Alice\""),
                (
                    "content/index.md",
                    "+++\ndescription = \"Home\"\nlayout = \"LayoutMinimal\"\ntitle = \"Home\"\nauthors = [\"alice\"]\n+++\n\n# Hello\n\nBody text.\n",
                ),
                (
                    "content/docs/index.md",
                    "+++\ndescription = \"Docs\"\nlayout = \"LayoutMinimal\"\ntitle = \"Docs\"\n\n[[collection]]\nname = \"docs\"\n+++\n\nDocs index.\n",
                ),
                (
                    "content/docs/page.md",
                    "+++\ndescription = \"Page\"\nlayout = \"LayoutMinimal\"\ntitle = \"Page\"\n\n[[collection]]\nname = \"docs\"\nafter = \"docs/index\"\n+++\n\nPage body.\n",
                ),
            ],
            false,
        )
        .await?;

        let home = read(&result, "index.html").await?;

        assert!(home.contains("<!DOCTYPE html>"));
        assert!(home.contains("<nav>nav</nav>"));
        assert!(home.contains("<li>Alice</li>"));

        read(&result, "docs/index.html").await?;
        read(&result, "docs/page/index.html").await?;

        assert_eq!(result.content_document_sources.len(), 3);

        Ok(())
    }

    #[tokio::test]
    async fn generates_sitemap_with_canonical_links_when_requested() -> Result<()> {
        let result = build(
            &[
                ("shortcodes/LayoutMinimal.rhai", LAYOUT_MINIMAL),
                ("shortcodes/PrimaryNavigation.rhai", PRIMARY_NAVIGATION),
                (
                    "content/index.md",
                    "+++\ndescription = \"Home\"\nlayout = \"LayoutMinimal\"\ntitle = \"Home\"\n+++\n\nHome.\n",
                ),
            ],
            true,
        )
        .await?;

        let sitemap = read(&result, "sitemap.xml").await?;

        assert!(sitemap.contains("<urlset"));
        assert!(sitemap.contains("<loc>/</loc>"));

        Ok(())
    }

    const LAYOUT_RICH: &str = r#"
fn template(context, props, content) {
  component {
    <html>
      <head><title>{context.front_matter.title}</title></head>
      <body>
        <p>{context.front_matter.description}</p>
        <span>{context.reference.canonical_link}</span>
        <span>{context.reference.basename}</span>
        <span>reftitle:{context.reference.front_matter.title}</span>
        <span>watching:{context.is_watching}</span>
        <span>props:{context.front_matter.props.len()}</span>
        <span>authors:{context.available_authors.len()}</span>
        {if context.front_matter.render { "<i>is-rendered</i>" } else { "" }}
        {
          let names = "";

          for author in context.authors {
            names += "<b>" + author.basename + "=" + author.data.name + "</b>";
          }

          names
        }
        <ul>
        {
          let toc = "";

          for heading in context.table_of_contents.headings {
            toc += "<li>" + heading.id + ":" + heading.content + ":" + heading.depth + "</li>";
          }

          toc
        }
        </ul>
        {
          let docs = context.collection("docs");
          let heading = "<h2>" + docs.name + "</h2>";

          heading + render_hierarchy(docs.hierarchy, |node, level, children| {
            "<li>" + node.reference.basename + " in " + node.collection_name + " kids " + node.children.len() + children + "</li>"
          })
        }
        {content}
      </body>
    </html>
  }
}
"#;

    const LAYOUT_PLAIN: &str = r#"
fn template(context, props, content) {
  component {
    <html>{content}</html>
  }
}
"#;

    #[tokio::test]
    async fn rich_layout_exercises_template_accessors_and_hierarchy() -> Result<()> {
        let result = build(
            &[
                ("shortcodes/LayoutRich.rhai", LAYOUT_RICH),
                ("shortcodes/LayoutPlain.rhai", LAYOUT_PLAIN),
                ("authors/alice.toml", "name = \"Alice\""),
                (
                    "content/index.md",
                    "+++\ndescription = \"Welcome home\"\nlayout = \"LayoutRich\"\ntitle = \"Home Page\"\nauthors = [\"alice\"]\n+++\n\n# Section One\n\nHome body.\n",
                ),
                (
                    "content/docs/index.md",
                    "+++\ndescription = \"Docs\"\nlayout = \"LayoutPlain\"\ntitle = \"Docs\"\n\n[[collection]]\nname = \"docs\"\n+++\n\nDocs index.\n",
                ),
                (
                    "content/docs/page.md",
                    "+++\ndescription = \"Page\"\nlayout = \"LayoutPlain\"\ntitle = \"Page\"\n\n[[collection]]\nname = \"docs\"\nafter = \"docs/index\"\n+++\n\nPage body.\n",
                ),
            ],
            false,
        )
        .await?;

        let home = read(&result, "index.html").await?;

        assert!(home.contains("<title>Home Page</title>"));
        assert!(home.contains("Welcome home"));
        assert!(home.contains("<i>is-rendered</i>"));
        assert!(home.contains("reftitle:Home Page"));
        assert!(home.contains("watching:false"));
        assert!(home.contains("authors:1"));
        assert!(home.contains("<b>alice=Alice</b>"));
        assert!(home.contains("section-one:Section One:1"));
        assert!(home.contains("<h2>docs</h2>"));
        assert!(home.contains("in docs kids"));

        Ok(())
    }

    #[tokio::test]
    async fn renders_markdown_mdx_component_and_expression() -> Result<()> {
        let result = build(
            &[
                ("shortcodes/LayoutMinimal.rhai", LAYOUT_MINIMAL),
                ("shortcodes/PrimaryNavigation.rhai", PRIMARY_NAVIGATION),
                (
                    "content/index.md",
                    "+++\ndescription = \"Home\"\nlayout = \"LayoutMinimal\"\ntitle = \"Home\"\n+++\n\nValue {40 + 2}\n\n<PrimaryNavigation>\ninner\n</PrimaryNavigation>\n",
                ),
            ],
            false,
        )
        .await?;

        let home = read(&result, "index.html").await?;

        assert!(home.contains("<p>Value 42</p>"));
        assert!(home.contains("<nav><p>inner</p></nav>"));

        Ok(())
    }

    #[tokio::test]
    async fn errors_on_duplicate_document_id() -> Result<()> {
        let front_matter = |title: &str| {
            format!(
                "+++\ndescription = \"d\"\nid = \"dup\"\nlayout = \"LayoutMinimal\"\ntitle = \"{title}\"\n+++\n\nBody.\n"
            )
        };

        let outcome = build(
            &[
                ("content/a.md", &front_matter("A")),
                ("content/b.md", &front_matter("B")),
            ],
            false,
        )
        .await;

        assert!(
            outcome.is_err_and(|error| error.to_string().contains("Duplicate document id: #dup"))
        );

        Ok(())
    }

    #[tokio::test]
    async fn errors_when_a_referenced_author_does_not_exist() -> Result<()> {
        let outcome = build(
            &[(
                "content/a.md",
                "+++\ndescription = \"d\"\nlayout = \"LayoutMinimal\"\ntitle = \"A\"\nauthors = [\"ghost\"]\n+++\n\nBody.\n",
            )],
            false,
        )
        .await;

        assert!(
            outcome.is_err_and(|error| {
                error.to_string().contains("Author does not exist: 'ghost'")
            })
        );

        Ok(())
    }
}