Skip to content

Commit 44321de

Browse files
committed
updating decadv
1 parent 9e74fa4 commit 44321de

1 file changed

Lines changed: 150 additions & 22 deletions

File tree

content-org/garden/december-adventure.org

Lines changed: 150 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ I've taken the liberty of retroactively logging the days I missed.
1616
| 日 | 月 | 火 | 水 | 木 | 金 | 土 |
1717
|----+----+----+----+----+----+----|
1818
| | [[december 1][01]] | [[december 2 - 3][02]] | [[december 2 - 3][03]] | [[december 4][04]] | [[december 5][05]] | [[december 6][06]] |
19-
| [[december 7][07]] | [[december 8][08]] | [[december 9][09]] | [[december 10][10]] | [[December 11][11]] | 12 | 13 |
19+
| [[december 7][07]] | [[december 8][08]] | [[december 9][09]] | [[december 10][10]] | [[December 11][11]] | [[december 12][12]] | [[december 13][13]] |
2020
| 14 | 15 | 16 | 17 | 18 | 19 | 20 |
2121
| 21 | 22 | 23 | 24 | 25 | 26 | 27 |
2222
| 28 | 29 | 30 | 31 | | | |
@@ -277,7 +277,6 @@ though it definitely won't feel as smooth. Then finally onto the interesting
277277
part: understanding the patterns behind the gaps in ink and the radical shapes!
278278

279279
* december 10
280-
281280
Today I let the intrusive thoughts win and started seriously considering writing
282281
my own static site generator. It feels like the illogical next step to starting
283282
a digital garden. I don't know if I have the technical chops for it, but I'd
@@ -290,7 +289,7 @@ learning =emacs= and =org-mode= (and to be clear, I don't have any plans to stop
290289
using =emacs=), I've always felt hopelessly out of my depth, and I never end up
291290
setting aside the time to get comfortable enough with site generation toolchain
292291
that I use. This leads to frustration with little things like not being able to
293-
quite control the final HTML markup that's generated. Sure -- maybe there's a
292+
quite control the final html markup that's generated. Sure -- maybe there's a
294293
way of fixing the little issues that bug me, but I'm easily intimidated by =ox-hugo=
295294
and =hugo=. It'd also be nice to remove =emacs= in the toolchain -- I sometimes have
296295
trouble getting the publishing to work on my laptop (and, indeed, I couldn't get
@@ -346,8 +345,7 @@ congestion pricing. It looks like they analyzed a combination of epa and city
346345
sensors. I'd like to get around to understanding this more carefully, so
347346
maybe I'll leave this for another day (it seems the code is on [[https://github.com/timothyfraser/nyc_congestion_rep][GitHub]]).
348347

349-
* December 11
350-
348+
* december 11
351349
Working late today, but while I'm taking a bit of a break, here's some thoughts
352350
on basic functionality of a static site generator/site design that I'd like:
353351
- *input:* I like the idea of writing in markdown, because I think you can throw
@@ -370,40 +368,170 @@ on basic functionality of a static site generator/site design that I'd like:
370368
Then there's some more fun things after the basic functionality is done:
371369
- *output:* supporting multiple outputs, say gophermap for gopher or gemtext for
372370
gemini
373-
- *fun little modules:* a little program that detects and reports linkrot, or a
374-
little date-to-co2ppm transformer, or whatever other silly thing I think up of
371+
- *fun little modules:* syntax highlighting, a little program that detects and
372+
reports linkrot, or a little date-to-co2ppm transformer, or whatever other
373+
silly thing I think up of
375374

376375
Before bed I got =gforth= and =uxn= installed, and was playing around learning the
377376
basics of forth-style programming. It's not as scary as it looked, and I hope to
378377
get some time to play with them tomorrow.
379378

379+
* december 12
380+
I wrote my first =uxntal= program today! I was following compudanza's wonderful
381+
[[https://compudanzas.net/introduction_to_uxn_programming_book.html][book/online tutorial]] of which I worked through "day 1" and "day 2". So far it's
382+
been the basics of stack-based computation and drawing pixels and sprites to the
383+
screen. I love that drawing to the screen is presented immediately after the
384+
basics -- how fun!
385+
386+
#+ATTR_HTML: :alt a red keffiyeh pattern of pixel drawn on a white window
387+
[[file:images/december-adventure-2025/uxn-keffiyeh-d.jpg]]
388+
389+
I wrote some code to draw the patterns on the keffiyeh I tend to have draped
390+
around my chair. I don't know how to write loops yet, so the code's a bit silly,
391+
but it was fun regardless! Once I learn how to loop and set variables I'll clean
392+
up the code and put it up here.
393+
394+
* december 13
395+
Watered the plants (always takes longer than I expect) and leisurely did some
396+
laundry.
397+
398+
#+ATTR_HTML: :alt picture of succulents, aloe, coleus, etc.
399+
[[file:images/december-adventure-2025/uxn-keffiyeh-d.jpg]]
400+
401+
(I think I took this photo in June, everything's way bigger now, but the
402+
camera's in the other room and I can't be bothered)
403+
404+
** static site generation
405+
Anyway, I got some time to start thinking about my static site generator more
406+
concretely. Working name (because I needed a directory name in my projects
407+
folder) is /kishin/ (記伸), coming from "memory" (記憶) and "extend" (伸びる),
408+
inspired by the word memex.
409+
410+
Earlier I was considering writing my input files in Markdown, but more and more
411+
I'm starting to think that it's not much more work to just write plain html (my
412+
current emacs setup seems to have a good amount of snippets already set up in
413+
=html-mode=). The job of the static site generator will be to:
414+
- do basic templating (separating out the header, footer, etc. from content)
415+
- handle media (organization of images, automatically generating thumbnails,
416+
etc.)
417+
- handle timestamps, tags, backlinks, or more generally metadata linking and
418+
display
419+
- run any processing modules that I end up writing (math rendering, syntax
420+
highlighting)
421+
422+
In terms of parsing html, I'm not sure how much heavy lifting I'll actually have
423+
to do. For now I'm thinking I'll try out the tree-sitter html parser. I'd love
424+
to be dependency-free and write a bespoke parser, but I should probably ease
425+
myself into the intricacies of string parsing and data structures in =c=. In any
426+
case, I've wanted to play with tree-sitter ever since I watched Max Brunsfeld's
427+
[[https://www.youtube.com/watch?v=Jes3bD6P0To][strange loop]] talk on it.
428+
429+
Actually, now that I think about it for a moment, tree-sitter might be the way
430+
to go if I want to do any syntax highlighting for my code blocks...
431+
432+
** tree-sitter
433+
As a complete newbie to the =c= programming world, I couldn't make heads or tails
434+
of the [[https://tree-sitter.github.io/tree-sitter/using-parsers/1-getting-started.html][getting started]] page in the tree-sitter documentation. After being
435+
confused for a solid half-hour, here's what I ended up doing, which worked:
436+
1. cloned both the [[https://github.com/tree-sitter/tree-sitter][tree-sitter]] and [[https://github.com/tree-sitter/tree-sitter-html][tree-sitter-html]] sources, built them with
437+
=make=, and copied the resulting =libtree-sitter.a= and =libtree-sitter-html.a=
438+
files into my =lib/= folder.
439+
2. copied tree-sitter's =tree-sitter/lib/src/*= as well as
440+
=tree-sitter/lib/include/tree_sitter/api.h= into my =include/tree-sitter/=
441+
3. made sure my =Makefile= knew about these static libraries and the inner include
442+
path
443+
444+
I don't know if this is what I was supposed to do, but I'm able to use
445+
tree-sitter from my =main.c=, so it'll do for now. I copied the example code from
446+
the tree-sitter documentation and started playing around with traversing the
447+
tree with =TSTreeCursor=.
448+
#+begin_src c
449+
#include <string.h>
450+
#include <stdio.h>
451+
452+
#include "tree-sitter/api.h"
453+
454+
const TSLanguage *tree_sitter_html(void);
455+
456+
int main() {
457+
// Create a parser.
458+
TSParser *parser = ts_parser_new();
459+
460+
// Set the parser's language (HTML in this case).
461+
ts_parser_set_language(parser, tree_sitter_html());
462+
463+
// Build a syntax tree based on source code stored in a string.
464+
const char *source_code = "Hi你好!<p>para</p>";
465+
TSTree *tree = ts_parser_parse_string(
466+
parser,
467+
NULL,
468+
source_code,
469+
strlen(source_code)
470+
);
471+
472+
// Get the root node of the syntax tree.
473+
TSNode root_node = ts_tree_root_node(tree);
474+
// Print the syntax tree as an S-expression.
475+
char *string = ts_node_string(root_node);
476+
// For the example above, "Hi你好!<p>para</p>", it looks like:
477+
// > (document (text) (element (start_tag (tag_name)) (text) (end_tag (tag_name))))
478+
printf("Syntax tree: %s\n", string);
479+
480+
// Start traversing the tree with a cursor
481+
TSTreeCursor cursor = ts_tree_cursor_new(root_node);
482+
bool result = ts_tree_cursor_goto_first_child(&cursor);
483+
// If no child was found, abort
484+
if(!result)
485+
return 1;
486+
487+
// Print out the node type, and start and end bytes
488+
TSNode nextNode = ts_tree_cursor_current_node(&cursor);
489+
// For the example above, it looks like:
490+
// > text
491+
// > 0
492+
// > 9
493+
// You can check that the Chinese characters here are 3 bytes each
494+
// in utf-8 (I suppose somewhere along the lines tree-sitter is figuring
495+
// out that we're using utf-8) and so, adding the 3 extra bytes from "Hi!",
496+
// we do indeed expect 9 bytes
497+
printf("%s\n", ts_node_type(nextNode));
498+
printf("%d\n", ts_node_start_byte(nextNode));
499+
printf("%d\n", ts_node_end_byte(nextNode));
500+
501+
// Free all of the heap-allocated memory.
502+
free(string);
503+
ts_tree_cursor_delete(&cursor);
504+
ts_tree_delete(tree);
505+
ts_parser_delete(parser);
506+
return 0;
507+
}
508+
#+end_src
509+
510+
In additional to traversal there's a query API, but I'll scope that out later.
511+
I'll leave this here for now. Tomorrow I'll see if I have the time to put
512+
together an example static site and get started on the actual site generation.
513+
380514
-----
381515

382516
Down here I'm collecting the little project ideas that tend to pop into
383517
my head:
384518
- write up some notes on the basics of how C programs are compiled and linked,
385-
as well as the platform-dependent aspects.
519+
what static/dynamic objects and linking are, command line tools to investigate
520+
symbols, platform-dependent aspects, etc.
386521

387-
/inspired by:/ me realizing I have no
388-
idea what I'm doing when I'm putting together a Makefile or working on a
389-
C project on my mac when traveling
390-
- learn and write a toy program in assembly! and/or forth! and/or uxntal! if I
391-
can get the kakuji editor working, it might be a good second program to port
392-
over.
393-
394-
/inspired by:/ [[https://100r.co][100r]], learning more about how memory and caches works
522+
/inspired by:/ me realizing I have no idea what I'm doing when I'm putting
523+
together a Makefile or working on a C project on my mac when traveling
395524
- speaking of uxn... the =screen.tal= example that ships with =uxn= generates
396525
patterns that remind me of the keffiyeh. time for a little spritework?
397526

398527
/inspired by:/ https://www.youtube.com/watch?v=jLRE_TSpnYc
399-
- exploring moving away from org/ox-hugo for static site generation.
400-
401-
/inspired by:/ as much as I love being able to use org-babel to write and run code from
402-
directly inside my posts, losing control over the final export is annoying.
403-
maybe I could just post-process the generated html? or rather, use tools that
404-
hugo exposes to do so?
405528
- take a look at [[https://github.com/timothyfraser/nyc_congestion_rep][recent work]] on the impact of ny congestion pricing on air
406529
quality.
407530

408531
/inspired by:/ the air leaking through my windows freezing my toes
409532
feeling less pm2.5y than usual
533+
- learn a little bit of lean and formalize something fun! Or at least write a
534+
new math blog post
535+
536+
/inspired by:/ me remembering (idk why) Kuo-Tsai Chen's work on integrated
537+
integrals, and the connections to Hochschild homology.

0 commit comments

Comments
 (0)