Skip to content

Conversation

graphiteisaac
Copy link
Member

G'day!

Today I come bearing a new page layout, the table of contents layout! I've had this one in the pipelines for a bit now, but I've properly factored it as a separate unit so it can be used now.

This includes a small refactor, adding a new layout.gleam file with our basic layout functions, giving some clearer distinction between page content and layout things. It also includes a function that parses Djot document content to produce a List of ContentLinks, used to build the table of contents in the layout.

For now, since I want to start small(er), I have just set it up manually on the two deployment pages.

image

Copy link
Member

@lpil lpil left a comment

Choose a reason for hiding this comment

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

Thank you!! I've left a few lil notes

pub fn table_of_contents_from_djot(document: jot.Document) -> List(ContentLink) {
document.content
|> list.fold(from: [], over: _, with: fn(accum, block) {
case block {
Copy link
Member

Choose a reason for hiding this comment

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

Flatten these nested case expressions and the list.first into a single case expression please.

let href =
"#"
<> dict.get(attributes, "id")
|> result.unwrap("")
Copy link
Member

Choose a reason for hiding this comment

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

Skip if id is missing instead of rendering an invalid link

])
}

pub fn with_toc(
Copy link
Member

Choose a reason for hiding this comment

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

No abbreviations in Gleam code please!

@@ -0,0 +1,292 @@
import gleam/dict
Copy link
Member

Choose a reason for hiding this comment

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

Merge this module back into the page module please.

The fact the PagaMeta data type no longer has an appropriate to live without creating dependency cycles shows that this is one module and not two.

ContentLink(title: String, href: String, children: List(ContentLink))
}

pub fn table_of_contents_from_djot(document: jot.Document) -> List(ContentLink) {
Copy link
Member

Choose a reason for hiding this comment

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

Is this used anywhere?

Copy link
Member Author

Choose a reason for hiding this comment

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

It is not currently, but it will be as soon as you use djot to write a guide like this.

Copy link
Member

Choose a reason for hiding this comment

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

ooo smart

/// Social media share preview image name
preload_images: List(String),
)
}
Copy link
Member

Choose a reason for hiding this comment

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

This belongs in the page module!

Includes moving the layout module back into the page module, making the
djot table of contents much less ugly, and improving code style (toc ->
table_of_contents)
@graphiteisaac
Copy link
Member Author

Thanks, I've implemented much of this feedback now.

foolish that I did not include this in the last commit but alas
Copy link
Member

@lpil lpil left a comment

Choose a reason for hiding this comment

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

Thanks!!

@lpil lpil merged commit 5f8f66b into gleam-lang:main Oct 9, 2025
2 checks passed
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