marmite 0.4.2

Marmite is the easiest static site generator.
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
use std::fs;
use std::process::Command;
use tempfile::TempDir;

#[test]
fn test_subfolder_with_frontmatter_yaml() {
    let temp_dir = TempDir::new().unwrap();
    let input_dir = temp_dir.path().join("input");
    let output_dir = temp_dir.path().join("output");

    fs::create_dir_all(input_dir.join("content").join("python")).unwrap();
    fs::write(input_dir.join("marmite.yaml"), "name: Blog").unwrap();

    fs::write(
        input_dir
            .join("content")
            .join("python")
            .join("frontmatter.yaml"),
        "date: 2026-01-01\nstream: python\ntags:\n  - python\n  - programming\n",
    )
    .unwrap();

    fs::write(
        input_dir
            .join("content")
            .join("python")
            .join("databases.md"),
        "---\ntitle: Databases\n---\n# Databases\n\nUsing databases with Python.\n",
    )
    .unwrap();

    fs::write(
        input_dir.join("content").join("python").join("classes.md"),
        "---\ntitle: Classes\n---\n# Classes\n\nPython classes tutorial.\n",
    )
    .unwrap();

    let output = Command::new("cargo")
        .args([
            "run",
            "--quiet",
            "--",
            input_dir.to_str().unwrap(),
            output_dir.to_str().unwrap(),
        ])
        .output()
        .expect("Failed to execute marmite");

    assert!(
        output.status.success(),
        "Command failed: {}",
        String::from_utf8_lossy(&output.stderr)
    );

    assert!(
        output_dir.join("python-databases.html").exists(),
        "databases page should be rendered with python stream prefix"
    );
    assert!(
        output_dir.join("python-classes.html").exists(),
        "classes page should be rendered with python stream prefix"
    );
    assert!(
        output_dir.join("python.html").exists(),
        "python stream page should exist"
    );

    let databases_html = fs::read_to_string(output_dir.join("python-databases.html")).unwrap();
    assert!(
        databases_html.contains("Databases"),
        "databases page should contain its title"
    );
}

#[test]
fn test_subfolder_file_overrides_folder_defaults() {
    let temp_dir = TempDir::new().unwrap();
    let input_dir = temp_dir.path().join("input");
    let output_dir = temp_dir.path().join("output");

    fs::create_dir_all(input_dir.join("content").join("python")).unwrap();
    fs::write(input_dir.join("marmite.yaml"), "name: Blog").unwrap();

    fs::write(
        input_dir
            .join("content")
            .join("python")
            .join("frontmatter.yaml"),
        "date: 2026-01-01\nstream: python\n",
    )
    .unwrap();

    fs::write(
        input_dir.join("content").join("python").join("special.md"),
        "---\ntitle: Special\nstream: advanced\n---\n# Special\n\nAdvanced topic.\n",
    )
    .unwrap();

    let output = Command::new("cargo")
        .args([
            "run",
            "--quiet",
            "--",
            input_dir.to_str().unwrap(),
            output_dir.to_str().unwrap(),
        ])
        .output()
        .expect("Failed to execute marmite");

    assert!(
        output.status.success(),
        "Command failed: {}",
        String::from_utf8_lossy(&output.stderr)
    );

    assert!(
        output_dir.join("advanced-special.html").exists(),
        "file should use its own stream override, not the folder default"
    );
    assert!(
        !output_dir.join("python-special.html").exists(),
        "file should not use the folder default stream"
    );
}

#[test]
fn test_root_frontmatter_yaml() {
    let temp_dir = TempDir::new().unwrap();
    let input_dir = temp_dir.path().join("input");
    let output_dir = temp_dir.path().join("output");

    fs::create_dir_all(input_dir.join("content")).unwrap();
    fs::write(input_dir.join("marmite.yaml"), "name: Blog").unwrap();

    fs::write(
        input_dir.join("content").join("frontmatter.yaml"),
        "authors:\n  - admin\n",
    )
    .unwrap();

    fs::write(
        input_dir.join("content").join("2026-01-01-post.md"),
        "---\ntitle: A Post\n---\n# A Post\n\nContent.\n",
    )
    .unwrap();

    let output = Command::new("cargo")
        .args([
            "run",
            "--quiet",
            "--",
            input_dir.to_str().unwrap(),
            output_dir.to_str().unwrap(),
        ])
        .output()
        .expect("Failed to execute marmite");

    assert!(
        output.status.success(),
        "Command failed: {}",
        String::from_utf8_lossy(&output.stderr)
    );

    assert!(
        output_dir.join("a-post.html").exists(),
        "post should be rendered"
    );
    assert!(
        output_dir.join("author-admin.html").exists(),
        "author page should be generated from root frontmatter defaults"
    );
}

#[test]
fn test_root_and_subfolder_frontmatter_layering() {
    let temp_dir = TempDir::new().unwrap();
    let input_dir = temp_dir.path().join("input");
    let output_dir = temp_dir.path().join("output");

    fs::create_dir_all(input_dir.join("content").join("python")).unwrap();
    fs::write(input_dir.join("marmite.yaml"), "name: Blog").unwrap();

    fs::write(
        input_dir.join("content").join("frontmatter.yaml"),
        "authors:\n  - admin\ndate: 2026-01-01\n",
    )
    .unwrap();

    fs::write(
        input_dir
            .join("content")
            .join("python")
            .join("frontmatter.yaml"),
        "stream: python\ntags:\n  - python\n",
    )
    .unwrap();

    fs::write(
        input_dir.join("content").join("python").join("intro.md"),
        "---\ntitle: Python Intro\n---\n# Python Intro\n\nIntro content.\n",
    )
    .unwrap();

    let output = Command::new("cargo")
        .args([
            "run",
            "--quiet",
            "--",
            input_dir.to_str().unwrap(),
            output_dir.to_str().unwrap(),
        ])
        .output()
        .expect("Failed to execute marmite");

    assert!(
        output.status.success(),
        "Command failed: {}",
        String::from_utf8_lossy(&output.stderr)
    );

    assert!(
        output_dir.join("python-python-intro.html").exists(),
        "post should use python stream from subfolder frontmatter"
    );
    assert!(
        output_dir.join("python.html").exists(),
        "python stream page should exist"
    );
    assert!(
        output_dir.join("author-admin.html").exists(),
        "author from root frontmatter should be inherited through subfolder"
    );
}

#[test]
fn test_translation_group_without_frontmatter_yaml() {
    let temp_dir = TempDir::new().unwrap();
    let input_dir = temp_dir.path().join("input");
    let output_dir = temp_dir.path().join("output");

    fs::create_dir_all(input_dir.join("content").join("hello")).unwrap();
    fs::write(input_dir.join("marmite.yaml"), "name: Blog\nlanguage: en\n").unwrap();

    fs::write(
        input_dir.join("content").join("hello").join("en-hello.md"),
        "---\ntitle: Hello\ndate: 2026-01-01\n---\n# Hello\n\nHello world.\n",
    )
    .unwrap();

    fs::write(
        input_dir.join("content").join("hello").join("pt-ola.md"),
        "---\ntitle: Ola\ndate: 2026-01-01\n---\n# Ola\n\nOla mundo.\n",
    )
    .unwrap();

    let output = Command::new("cargo")
        .args([
            "run",
            "--quiet",
            "--",
            input_dir.to_str().unwrap(),
            output_dir.to_str().unwrap(),
        ])
        .output()
        .expect("Failed to execute marmite");

    assert!(
        output.status.success(),
        "Command failed: {}",
        String::from_utf8_lossy(&output.stderr)
    );

    let has_en =
        output_dir.join("en-hello.html").exists() || output_dir.join("hello.html").exists();
    let has_pt = output_dir.join("pt-ola.html").exists() || output_dir.join("ola.html").exists();

    assert!(
        has_en,
        "English translation should be rendered even without frontmatter.yaml"
    );
    assert!(
        has_pt,
        "Portuguese translation should be rendered even without frontmatter.yaml"
    );
}

#[test]
fn test_empty_frontmatter_yaml_enables_subfolder() {
    let temp_dir = TempDir::new().unwrap();
    let input_dir = temp_dir.path().join("input");
    let output_dir = temp_dir.path().join("output");

    fs::create_dir_all(input_dir.join("content").join("notes")).unwrap();
    fs::write(input_dir.join("marmite.yaml"), "name: Blog").unwrap();

    fs::write(
        input_dir
            .join("content")
            .join("notes")
            .join("frontmatter.yaml"),
        "",
    )
    .unwrap();

    fs::write(
        input_dir
            .join("content")
            .join("notes")
            .join("2026-01-01-first-note.md"),
        "---\ntitle: First Note\n---\n# First Note\n\nA note.\n",
    )
    .unwrap();

    let output = Command::new("cargo")
        .args([
            "run",
            "--quiet",
            "--",
            input_dir.to_str().unwrap(),
            output_dir.to_str().unwrap(),
        ])
        .output()
        .expect("Failed to execute marmite");

    assert!(
        output.status.success(),
        "Command failed: {}",
        String::from_utf8_lossy(&output.stderr)
    );

    assert!(
        output_dir.join("first-note.html").exists(),
        "empty frontmatter.yaml should still enable the subfolder for rendering"
    );
}

#[test]
fn test_nested_subfolder_frontmatter_yaml() {
    let temp_dir = TempDir::new().unwrap();
    let input_dir = temp_dir.path().join("input");
    let output_dir = temp_dir.path().join("output");

    fs::create_dir_all(input_dir.join("content").join("poetry").join("love")).unwrap();
    fs::write(input_dir.join("marmite.yaml"), "name: Blog").unwrap();

    fs::write(
        input_dir
            .join("content")
            .join("poetry")
            .join("love")
            .join("frontmatter.yaml"),
        "date: 2026-01-01\nstream: poetry\ntags:\n  - love\n  - poetry\n",
    )
    .unwrap();

    fs::write(
        input_dir
            .join("content")
            .join("poetry")
            .join("love")
            .join("roses.md"),
        "---\ntitle: Roses\n---\n# Roses\n\nRoses are red.\n",
    )
    .unwrap();

    let output = Command::new("cargo")
        .args([
            "run",
            "--quiet",
            "--",
            input_dir.to_str().unwrap(),
            output_dir.to_str().unwrap(),
        ])
        .output()
        .expect("Failed to execute marmite");

    assert!(
        output.status.success(),
        "Command failed: {}",
        String::from_utf8_lossy(&output.stderr)
    );

    assert!(
        output_dir.join("poetry-roses.html").exists(),
        "nested subfolder content should render with inherited stream"
    );
}

#[test]
fn test_nested_frontmatter_inheritance_from_ancestor() {
    let temp_dir = TempDir::new().unwrap();
    let input_dir = temp_dir.path().join("input");
    let output_dir = temp_dir.path().join("output");

    fs::create_dir_all(input_dir.join("content").join("poetry").join("love")).unwrap();
    fs::write(input_dir.join("marmite.yaml"), "name: Blog").unwrap();

    // Only parent has frontmatter.yaml, not the nested subfolder
    fs::write(
        input_dir
            .join("content")
            .join("poetry")
            .join("frontmatter.yaml"),
        "date: 2026-01-01\nstream: poetry\n",
    )
    .unwrap();

    fs::write(
        input_dir
            .join("content")
            .join("poetry")
            .join("love")
            .join("sonnet.md"),
        "---\ntitle: Sonnet\n---\n# Sonnet\n\nA love sonnet.\n",
    )
    .unwrap();

    let output = Command::new("cargo")
        .args([
            "run",
            "--quiet",
            "--",
            input_dir.to_str().unwrap(),
            output_dir.to_str().unwrap(),
        ])
        .output()
        .expect("Failed to execute marmite");

    assert!(
        output.status.success(),
        "Command failed: {}",
        String::from_utf8_lossy(&output.stderr)
    );

    assert!(
        output_dir.join("poetry-sonnet.html").exists(),
        "file in nested subfolder should inherit from ancestor frontmatter.yaml"
    );
}

#[test]
fn test_three_level_frontmatter_layering() {
    let temp_dir = TempDir::new().unwrap();
    let input_dir = temp_dir.path().join("input");
    let output_dir = temp_dir.path().join("output");

    fs::create_dir_all(input_dir.join("content").join("tutorials").join("python")).unwrap();
    fs::write(input_dir.join("marmite.yaml"), "name: Blog").unwrap();

    // Root defaults
    fs::write(
        input_dir.join("content").join("frontmatter.yaml"),
        "authors:\n  - admin\ndate: 2026-01-01\n",
    )
    .unwrap();

    // Level 1 adds stream
    fs::write(
        input_dir
            .join("content")
            .join("tutorials")
            .join("frontmatter.yaml"),
        "stream: tutorial\n",
    )
    .unwrap();

    // Level 2 adds tags
    fs::write(
        input_dir
            .join("content")
            .join("tutorials")
            .join("python")
            .join("frontmatter.yaml"),
        "tags:\n  - python\n",
    )
    .unwrap();

    fs::write(
        input_dir
            .join("content")
            .join("tutorials")
            .join("python")
            .join("basics.md"),
        "---\ntitle: Python Basics\n---\n# Python Basics\n\nLearn Python.\n",
    )
    .unwrap();

    let output = Command::new("cargo")
        .args([
            "run",
            "--quiet",
            "--",
            input_dir.to_str().unwrap(),
            output_dir.to_str().unwrap(),
        ])
        .output()
        .expect("Failed to execute marmite");

    assert!(
        output.status.success(),
        "Command failed: {}",
        String::from_utf8_lossy(&output.stderr)
    );

    // Stream from level 1 should be inherited through level 2
    assert!(
        output_dir.join("tutorial-python-basics.html").exists(),
        "three-level layering should work: root (author/date) + tutorials (stream) + python (tags)"
    );
    // Author from root should be inherited through all levels
    assert!(
        output_dir.join("author-admin.html").exists(),
        "root author should be inherited through nested frontmatter layers"
    );
}

#[test]
fn test_nested_translation_group() {
    let temp_dir = TempDir::new().unwrap();
    let input_dir = temp_dir.path().join("input");
    let output_dir = temp_dir.path().join("output");

    fs::create_dir_all(input_dir.join("content").join("poetry").join("love")).unwrap();
    fs::create_dir_all(input_dir.join("content").join("poetry").join("nature")).unwrap();
    fs::write(input_dir.join("marmite.yaml"), "name: Blog\nlanguage: en\n").unwrap();

    // Love subfolder: translation group
    // Default language (en) file has no prefix
    fs::write(
        input_dir
            .join("content")
            .join("poetry")
            .join("love")
            .join("love-poem.md"),
        "---\ntitle: Love Poem\ndate: 2026-01-01\n---\n# Love Poem\n\nA love poem.\n",
    )
    .unwrap();

    fs::write(
        input_dir
            .join("content")
            .join("poetry")
            .join("love")
            .join("pt-poema-amor.md"),
        "---\ntitle: Poema de Amor\ndate: 2026-01-01\n---\n# Poema de Amor\n\nUm poema de amor.\n",
    )
    .unwrap();

    // Nature subfolder: separate translation group
    fs::write(
        input_dir
            .join("content")
            .join("poetry")
            .join("nature")
            .join("nature-poem.md"),
        "---\ntitle: Nature Poem\ndate: 2026-01-01\n---\n# Nature Poem\n\nA nature poem.\n",
    )
    .unwrap();

    fs::write(
        input_dir
            .join("content")
            .join("poetry")
            .join("nature")
            .join("pt-poema-natureza.md"),
        "---\ntitle: Poema da Natureza\ndate: 2026-01-01\n---\n# Poema da Natureza\n\nUm poema da natureza.\n",
    )
    .unwrap();

    let output = Command::new("cargo")
        .args([
            "run",
            "--quiet",
            "--",
            input_dir.to_str().unwrap(),
            output_dir.to_str().unwrap(),
        ])
        .output()
        .expect("Failed to execute marmite");

    assert!(
        output.status.success(),
        "Command failed: {}",
        String::from_utf8_lossy(&output.stderr)
    );

    // Default language (en) renders without prefix, translations with lang prefix
    let love_en = output_dir.join("love-poem.html").exists();
    let love_pt = output_dir.join("pt-poema-de-amor.html").exists();
    let nature_en = output_dir.join("nature-poem.html").exists();
    let nature_pt = output_dir.join("pt-poema-da-natureza.html").exists();

    assert!(
        love_en,
        "English love poem should be rendered without lang prefix"
    );
    assert!(love_pt, "Portuguese love poem should be rendered");
    assert!(
        nature_en,
        "English nature poem should be rendered without lang prefix"
    );
    assert!(nature_pt, "Portuguese nature poem should be rendered");
}