Skip to content

Commit 740b25d

Browse files
Use djot for project pages
1 parent 35675fd commit 740b25d

File tree

7 files changed

+52
-44
lines changed

7 files changed

+52
-44
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1+
---
12
title = "Fungecraft"
2-
33
download = "https://modrinth.com/datapack/fungecraft"
4-
54
youtube = '<iframe width="560" height="315" src="https://www.youtube-nocookie.com/embed/RI9JmWbVt7M" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen></iframe>'
5+
---
66

7-
description = """Fungecraft is a Minecraft version of the esoteric programming language Befunge, using Minecraft blocks instead of ASCII Characters.<br/>
8-
<br/>
9-
Fungecraft is to date one of my favourite packs that I've worked on. It was my first real computational datapack, and it was a lot of fun to work on.<br/>
10-
With the making of it, I was able to prove that mcfunction was turing complete, which cool. I was also very passionate about esolangs at the time, hence the reason for making it.<br/>
11-
<br/>
12-
I made Fungecraft before string parsing was a thing, so I used blocks instead of a book as input.<br/>
13-
I think Fungecraft helped me get into the mindset of this kind of datapack, and allowed me to later go on to make far more complex packs, such as Code of Copper."""
7+
Fungecraft is a Minecraft version of the esoteric programming language Befunge, using Minecraft blocks instead of ASCII Characters.\
8+
\
9+
Fungecraft is to date one of my favourite packs that I've worked on. It was my first real computational datapack, and it was a lot of fun to work on.
10+
With the making of it, I was able to prove that mcfunction was turing complete, which cool. I was also very passionate about esolangs at the time, hence the reason for making it.\
11+
\
12+
I made Fungecraft before string parsing was a thing, so I used blocks instead of a book as input.
13+
I think Fungecraft helped me get into the mindset of this kind of datapack, and allowed me to later go on to make far more complex packs, such as Code of Copper.
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1+
---
12
title = "Gadgets"
2-
33
download = "https://www.planetminecraft.com/data-pack/gadgets-5629494/"
4-
54
youtube = '<iframe width="560" height="315" src="https://www.youtube-nocookie.com/embed/fzf6l934f4w" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen></iframe>'
5+
---
66

7-
description = """Gadgets is a datapack that I made when I was feeling motivated, but didn't have any good ideas. I'm not particularly proud of it, but I guess it's an interesting pack.<br/>
8-
<br/>
9-
It's not very original, which is why I don't care much for it. I guess I learned something about datapacks while making it, but overall it was just me trying to get some views and downloads as I hadn't really posted a datapack in a while."""
7+
Gadgets is a datapack that I made when I was feeling motivated, but didn't have any good ideas. I'm not particularly proud of it, but I guess it's an interesting pack.\
8+
\
9+
It's not very original, which is why I don't care much for it. I guess I learned something about datapacks while making it, but overall it was just me trying to get some views and downloads as I hadn't really posted a datapack in a while.
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1+
---
12
title = "Lucky Blocks"
2-
33
download = "https://modrinth.com/datapack/lucky-blocks"
4-
54
youtube = '<iframe width="560" height="315" src="https://www.youtube-nocookie.com/embed/Br87So1Ouag" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen></iframe>'
5+
---
66

7-
description = """My lucky blocks datapack was a very big project for me at the time, and remains my most popular datapack to date. This particular datapack holds a special place in my heart, as it marked the beginning of my journey as a Minecraft content creator on YouTube. <br/>
8-
<br/>
9-
There are 5 tiers of lucky blocks: Coal up to Netherite. Each one holds better rewards, but also bigger dangers. Upon breaking a Lucky Block, you might be showered with valuable treasures, ranging from rare resources like diamonds and emeralds to powerful enchanted items. Alternatively, you might find yourself facing unexpected challenges as waves of mobs descend upon you or treacherous traps are sprung.<br/>
10-
<br/>
11-
The main reason this datapack took so much effort to make was that I had to create my own custom crafting table, so that the lucky blocks were easily craftable. I'm very thankful I did so though, because I have used the crafter in many datapacks since."""
7+
My lucky blocks datapack was a very big project for me at the time, and remains my most popular datapack to date. This particular datapack holds a special place in my heart, as it marked the beginning of my journey as a Minecraft content creator on YouTube. \
8+
\
9+
There are 5 tiers of lucky blocks: Coal up to Netherite. Each one holds better rewards, but also bigger dangers. Upon breaking a Lucky Block, you might be showered with valuable treasures, ranging from rare resources like diamonds and emeralds to powerful enchanted items. Alternatively, you might find yourself facing unexpected challenges as waves of mobs descend upon you or treacherous traps are sprung.\
10+
\
11+
The main reason this datapack took so much effort to make was that I had to create my own custom crafting table, so that the lucky blocks were easily craftable. I'm very thankful I did so though, because I have used the crafter in many datapacks since.

src/build.gleam

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ pub fn main() {
2323
|> add_dynamic_routes(
2424
categories,
2525
project.view,
26-
fn(category: projects.Category) {
26+
fn(category: projects.Category(a)) {
2727
#("/projects/" <> category.path, category.projects)
2828
},
2929
)

src/website/data/projects.gleam

+22-14
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@ import gleam/bool
22
import gleam/dict.{type Dict}
33
import gleam/list
44
import gleam/string
5+
import lustre/element
6+
import lustre/ssg/djot
57
import simplifile
68
import tom.{type Toml}
79

8-
pub type Category {
9-
Category(title: String, path: String, projects: Dict(String, Project))
10+
pub type Category(a) {
11+
Category(title: String, path: String, projects: Dict(String, Project(a)))
1012
}
1113

12-
fn categories() -> List(Category) {
14+
fn categories() -> List(Category(a)) {
1315
let assert Ok(contents) = simplifile.read("projects/projects.toml")
1416
let assert Ok(toml) = tom.parse(contents)
1517
let assert Ok(categories) = tom.get_array(toml, ["categories"])
@@ -20,27 +22,28 @@ fn categories() -> List(Category) {
2022
Category(title:, path:, projects: dict.new())
2123
}
2224

23-
pub fn all() -> List(Category) {
25+
pub fn all() -> List(Category(a)) {
2426
use category <- list.map(categories())
2527
let assert Ok(files) = simplifile.read_directory("projects/" <> category.path)
2628
let projects =
2729
list.fold(files, category.projects, fn(projects, file) {
28-
use <- bool.guard(!string.ends_with(file, ".toml"), projects)
30+
use <- bool.guard(!string.ends_with(file, ".djot"), projects)
2931
let file_path = "projects/" <> category.path <> "/" <> file
3032
let assert Ok(contents) = simplifile.read(file_path)
31-
let assert Ok(toml) = tom.parse(contents)
3233

33-
let title = get_string_key(toml, "title")
34-
let download = get_string_key(toml, "download")
35-
let youtube = get_string_key(toml, "youtube")
36-
let description = get_string_key(toml, "description")
37-
// Remove .toml suffix
34+
let assert Ok(metadata) = djot.metadata(contents)
35+
let contents = djot.render(contents, djot.default_renderer())
36+
37+
let title = get_string_key(metadata, "title")
38+
let download = get_string_key(metadata, "download")
39+
let youtube = get_string_key(metadata, "youtube")
40+
// Remove .djot suffix
3841
let project_name = string.drop_end(file, 5)
3942

4043
dict.insert(
4144
projects,
4245
project_name,
43-
Project(title:, download:, youtube:, description:),
46+
Project(title:, download:, youtube:, contents:),
4447
)
4548
})
4649
Category(..category, projects:)
@@ -52,6 +55,11 @@ fn get_string_key(toml: Dict(String, Toml), key: String) -> String {
5255
value
5356
}
5457

55-
pub type Project {
56-
Project(title: String, download: String, youtube: String, description: String)
58+
pub type Project(a) {
59+
Project(
60+
title: String,
61+
download: String,
62+
youtube: String,
63+
contents: List(element.Element(a)),
64+
)
5765
}

src/website/page/project.gleam

+2-6
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import lustre/element/html
44
import website/component
55
import website/data/projects.{type Project}
66

7-
pub fn view(project: Project) -> Element(a) {
7+
pub fn view(project: Project(a)) -> Element(a) {
88
component.page(project.title, [
99
html.div([attribute.class("mx-auto max-w-3xl px-4 sm:px-6 lg:px-8")], [
1010
html.h1(
@@ -13,11 +13,7 @@ pub fn view(project: Project) -> Element(a) {
1313
),
1414
]),
1515
html.div([attribute.class("mx-auto max-w-4xl px-4 sm:px-6 lg:px-8")], [
16-
html.div([attribute.class("py-8 leading-8")], [
17-
html.p([attribute.class("text-xl")], [
18-
component.dangerous_html(project.description),
19-
]),
20-
]),
16+
html.div([attribute.class("py-8 leading-8 text-xl")], project.contents),
2117
component.dangerous_html(project.youtube),
2218
html.a(
2319
[

src/website/page/projects.gleam

+6-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import lustre/element/html
66
import website/component
77
import website/data/projects.{type Category, type Project}
88

9-
pub fn view(categories: List(Category)) -> Element(a) {
9+
pub fn view(categories: List(Category(a))) -> Element(a) {
1010
component.text_page(
1111
"Projects",
1212
"My Projects",
@@ -32,7 +32,11 @@ pub fn view(categories: List(Category)) -> Element(a) {
3232
)
3333
}
3434

35-
fn format_project(category: String, id: String, project: Project) -> Element(a) {
35+
fn format_project(
36+
category: String,
37+
id: String,
38+
project: Project(a),
39+
) -> Element(a) {
3640
html.a([attribute.href("/projects/" <> category <> "/" <> id)], [
3741
html.div(
3842
[

0 commit comments

Comments
 (0)