Skip to content

Commit 340c0e7

Browse files
committed
Frontmatter: raise on duplicated @children_order entry
1 parent c4b6ce0 commit 340c0e7

File tree

4 files changed

+13
-8
lines changed

4 files changed

+13
-8
lines changed

src/model/frontmatter.ml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ let apply fm line =
1313
| Children_order children_order, { children_order = None } ->
1414
{ children_order = Some (Location_.same line children_order) }
1515
| Children_order _, { children_order = Some _ } ->
16-
(* TODO raise warning about duplicate children field *) fm
16+
Error.raise_warning
17+
(Error.make "Duplicated @children_order entry" line.location);
18+
fm
1719

1820
let parse_child c =
1921
if Astring.String.is_suffix ~affix:"/" c then
@@ -39,4 +41,5 @@ let parse_children_order loc co =
3941
Error
4042
(Error.make "Only words are accepted when specifying children order" loc)
4143

42-
let of_lines lines = List.fold_left apply empty lines
44+
let of_lines lines =
45+
Error.catch_warnings @@ fun () -> List.fold_left apply empty lines

src/model/frontmatter.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ val parse_children_order :
1313
Odoc_parser.Ast.nestable_block_element Location_.with_location list ->
1414
(line Location_.with_location, Error.t) result
1515

16-
val of_lines : line Location_.with_location list -> t
16+
val of_lines : line Location_.with_location list -> t Error.with_warnings

src/model/semantics.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ let rec find_tag f = function
4444
find_tag f tl)
4545

4646
let rec find_tags acc f = function
47-
| [] -> acc
47+
| [] -> List.rev acc
4848
| hd :: tl -> (
4949
match f hd.Location.value with
5050
| Some x -> find_tags ((x, hd.location) :: acc) f tl
@@ -85,7 +85,7 @@ let handle_internal_tags (type a) tags : a handle_internal_tags -> a = function
8585
None))
8686
unparsed_lines
8787
in
88-
Frontmatter.of_lines lines
88+
Frontmatter.of_lines lines |> Error.raise_warnings
8989
| Expect_none ->
9090
(* Will raise warnings. *)
9191
ignore (find_tag (fun _ -> None) tags);

test/frontmatter/frontmatter.t/run.t

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,20 +56,22 @@ When there is one frontmatter, it is extracted from the content:
5656
}
5757
]
5858

59-
When there is more than one children order, the last one:
59+
When there is more than one children order, we raise a warning and keep only the first entry:
6060

6161
$ odoc compile two_frontmatters.mld
62+
File "two_frontmatters.mld", line 5, characters 0-25:
63+
Warning: Duplicated @children_order entry
6264
File "two_frontmatters.mld":
6365
Warning: Non-index page cannot specify (children _) in the frontmatter.
6466
$ odoc_print page-two_frontmatters.odoc | jq '.frontmatter'
6567
{
6668
"children": {
6769
"Some": [
6870
{
69-
"Page": "bli3"
71+
"Page": "bli1"
7072
},
7173
{
72-
"Page": "bli4"
74+
"Page": "bli2"
7375
}
7476
]
7577
}

0 commit comments

Comments
 (0)