···11+# Chilp!
22+33+Yes! Based on the sound a bird makes!
44+55+Chilp allows you to get a nice little comment section on your static blog, completely client-side! How? Well, as often: thievery!
66+77+...okay, let me go a little slower. Maybe you've seen those blogs before, where you needed GitHub to comment? They've likely been
88+using [Utterances](https://utteranc.es/), which creates a GitHub issue, and then renders the comments on it as comments on your post.
99+1010+This is super duper cool, I used this too! However, if you're a bit less of a developer, making a GitHub account feels cumbersome just to comment on a blog post.
1111+... On the other hand, if you ARE very into tech you may just be like me, and annoyed at how GitHub handles things privacy and performance-wise.
1212+1313+Now, I'm not the first to do this, I've seen others use Bluesky for their comment backends as well. However, being a [Gleamling](https://gleam.run/) and avid fan of the [Lustre framework](https://hexdocs.pm/lustre/guide/01-quickstart.html), well!
1414+1515+So, with v1 I was still very heavily trying to understand the Mastodon API and what it told me. Then, I created Chilp with some... Unconventionalities, which meant I didn't feel like highlighting it too much.
1616+... BUT!
1717+1818+## Chilp version 2
1919+2020+Okay, the intro is done, let me show you how easy it is for me to insert a Chilp widget.
2121+2222+This is just the example from <https://github.com/lustre-labs/lustre/blob/main/examples/01-basics/01-hello-world/src/app.gleam>, I added only about 20 lines to it!
2323+2424+### An example
2525+2626+2727+```gleam
2828+// IMPORTS --------------------------------------------------------------------------------------------------------------
2929+import lustre
3030+import lustre/element.{type Element}
3131+import lustre/element/html
3232+import lustre/event
3333+import chilp // <--- Imports Chilp the ergonomic way, if you want less imports,
3434+import chilp/widget // /-------- going with only `chilp/widget` is okay too! Then you'd need to
3535+import chilp/widget/anchors // <- make sure your anchor is sanely split using a backslash though.
3636+3737+// MAIN -----------------------------------------------------------------------------------------------------------------
3838+3939+pub fn main() {
4040+ let assert Ok(_) = widget.register()
4141+ let app = lustre.simple(init, update, view)
4242+ let assert Ok(_) = lustre.start(app, "#app", Nil)
4343+4444+ Nil
4545+}
4646+4747+type Model =
4848+ Int
4949+5050+fn init(_) -> Model {
5151+ 0
5252+}
5353+5454+// UPDATE --------------------------------------------------------------------------------------------------------------
5555+5656+type Message {
5757+ UserClickedIncrement
5858+ UserClickedDecrement
5959+}
6060+6161+fn update(model: Model, message: Message) -> Model {
6262+ case message {
6363+ UserClickedIncrement -> model + 1
6464+ UserClickedDecrement -> model - 1
6565+ }
6666+}
6767+6868+// VIEW -----------------------------------------------------------------------------------------------------------------
6969+7070+fn view(model: Model) -> Element(Message) {
7171+ let count = int.to_string(model)
7272+7373+ html.div([], [
7474+ html.button([event.on_click(UserClickedDecrement)], [html.text("-")]),
7575+ html.p([], [html.text("Count: "), html.text(count)]),
7676+ html.button([event.on_click(UserClickedIncrement)], [html.text("+")]),
7777+ // And then we place the widget itself here! under the counter.
7878+ chilp.widget(
7979+ // Anchoring this one to me mewing on the timeline
8080+ option.Some(anchors.Mastodon(
8181+ instance: "pony.social",
8282+ postid: "115911235653686237",
8383+ )),
8484+ // And anchoring this one to a post about my hamster
8585+ option.Some(anchors.Bluesky(
8686+ did: "did:plc:jgtfsmv25thfs4zmydtbccnn",
8787+ postid: "3mjeg3m7fd22i",
8888+ )),
8989+ ),
9090+ ])
9191+}
9292+```
9393+9494+The widget will be unstyled but is very easily styled into shape using for example DaisyUI, if you just want to see it alive, see the bottom of this post!
9595+9696+### What it does
9797+9898+Well, as one would expect, Chilp fetches your posts from the anchored platforms, then lists the comments under them and renders them into view.
9999+It also creates the well known 'enter your instance address' for Mastodon users to respond from the instance of their choice, while showing buttons
100100+to the favourite appviews for Bluesky users to instantly respond!
101101+102102+Let's not keep on nerding now, just AMA in the comments below!