Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Specify children order in frontmatter #1193

Open
wants to merge 17 commits into
base: master
Choose a base branch
from

Conversation

panglesd
Copy link
Collaborator

@panglesd panglesd commented Aug 30, 2024

Now that we have a convention for hierarchical pages, we need a way for the author to specify the order.

This PR does that by using the frontmatter, using this syntax:

children: child1 dir1/ child2 dir2/

The trailing / for directories is needed to distinguish them from files.

This PR is mostly ready, but:

  • TODO warnings:
    • warn when a children field is given in the frontmatter of a non index page,
    • warn when an entry of the children list is not found (should it happen during linking of the page or during the compile-index command?)
    • Test those warnings
  • Decide what to do when a children is omitted from the list:
    • ❌ do not include it in the toc (I'm in favor, this is what is implemented)?
    • ✔️ Include it at the end of the list (I'm not in favor)?
    • ✔️ Warn the user?
  • Decide what to do when there is no children list in an index page:
    • ❌ Warn the user? (not in favor!)
    • ✔️ Use alphabetical order on unit names (in favor, this is what the current PR does)
    • ❌ Use the alphabetical order on page main title (not in favor!)
  • Clean up/factor the implementation of PageToc.
  • Fix compat CI

Page don't and won't use dot references as in `page1.page2`.
Use

```
children: page1 page2 page3
```

in the frontmatter
Children order specifies order in an index page for the current directory. It
has to specify what is a page and what is a directory, as we can have:

```
doc/
  index
  foo
  foo/
    index
    bar
```

In the specification of the order in `doc/index`, we must make the difference
between the foo page and the foo directory. This was not practical with
references. So instead, the order specification has its own type.
Allow sequences of spaces in a row: `children:      page1           page2`.
@@ -582,6 +582,20 @@ let run libs verbose packages_dir odoc_dir odocl_dir html_dir stats nb_workers
(fun () -> render_stats env nb_workers)
in

List.iter
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is all of this just debug ? Otherwise, it seems too verbose and opaque.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is only showing filtered logs for debugging. I'll remove it.

let fm, content =
let fm, rev_content =
List.fold_left
(fun (fm_acc, content_acc) doc ->
match doc.Location_.value with
| `Code_block (Some "meta", content, None) ->
(parse_frontmatter content.Location_.value :: fm_acc, content_acc)
(content.Location_.value :: fm_acc, content_acc)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The previous code was more logical (parse each blocks and concatenate the values rather than concatenate the blocks and parse something no one wrote) and allowed more graceful handling of errors with locations.
Anyway, that's a temporary syntax.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, we are going to have the frontmatter consistently at the top, so there won't be any distinction.
So, I suggest leaving it as is.


type library = { name : string; units : Paths.Identifier.RootModule.t list }

type page_hierarchy = { hierarchy_name : string; pages : toc }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't expect the page hierarchy to have a name and be an extra level on top of a toc. What if this hierarchy contains an index.mld and a children order ? Is here an extra indentation with the name repeated ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This "hierarchy_name" corresponds to the name of the library's package: the one passed in the -P option of odoc compile-index.
It is currently turned into a "{hierarchy_name}'s Pages" title:

# Package1's Pages

- The best way to do foo
  - Guide
  - example
  - tutorial 

# Package2's Pages

- Blazingly fast bar
  - Guide
  - example
  - tutorial 

# Library1's modules

- Foo
- Bar

We could possibly remove this hierarchy_name, but I would argue that it is better done in another PR (this PR is not introducing the behavior).

(Maybe:

# Pages

- The best way to do foo
  - Guide
  - example
  - tutorial 
- Blazingly fast bar
  - Guide
  - example
  - tutorial 

# Libraries

- library1
  - Foo
  - Bar

)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes total sense! I think the hierarchy name is something we'd want in the breadcrumbs and so for clarity, we should also have it in the sidebar.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants