aboutsummaryrefslogtreecommitdiff
path: root/src/hyde.c
blob: 350a518d5c8da85a89f796d3d30be717cb0546d8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include "template.h"
#include <stdio.h>
#include <stdlib.h>

struct post {
    char title[64];
    char tags[8][32];
};

int main() {
    char *input = read_file("index.tpl");

    struct hashmap *ctx = hashmap_new();
    hashmap_insert(ctx, "title", "Hello world");

    struct post home = { 
        .title = "Homepage",
        .tags = {
            "Tag 1", "Tag 2"
        }
    };
    hashmap_insert(ctx, "home", &home);

    struct post posts[] = {
        { .title = "Post 1", .tags = { "p1t1" } },
        { .title = "Post 2", .tags = { "p2t1" } },
    };
    hashmap_insert(ctx, "posts", &posts);

    char *output = template(input, ctx);
    printf("Output: %s\n", output);
    hashmap_free(ctx);
    free(input);
    free(output);
}