<script>
    const fetchNodes = (async () => {
        const response = await fetch("http://127.0.0.1:5000/journals.json");
        return await response.json();
    })();
    const converter = new showdown.Converter();
    import { replaceWiki } from "./util.js";

</script>

<main>
    This is nodes module
    {#await fetchNodes}
        .. Waiting
    {:then nodes}
        {#each nodes as node}
            <div>
                New Node <span class="node-title">{node.uri}</span>
                {#each node.subnodes as subnode}
                <div>
                    User: <span class="node-title">{subnode.user}</span>
                </div>
                    <div>
                        {#if typeof subnode.content === "string"}
                            {@html converter.makeHtml(replaceWiki(subnode.content))}
                        {/if}
                    </div>
                {/each}
            </div>
        {/each}
    {/await}
</main>

<style>
    div {
        margin-bottom: 10px;
    }
    .node-title {
        font-weight: bold;
    }
</style>