Using an emergence site as a Joplin notes backend

Joplin is an open-source note taking and to-do application with solid clients for all platforms that supports synchronization via a WebDAV backend.

Use emergence site as a private synchronization backend

Any emergence site can work out-of-the-box as a synchronization backend for Joplin just by configuring http://mysite.example.org/develop/notes as the WebDAV URL and a developer username/password. The notes portion of that URL could be any path you’d like to use as a root for notes in the site’s filesystem.

Use emergence site to share notes as links

Notes can then be easily exposed for public link-sharing by adding a simple route handler and rendering template. To get a sharable link in Joplin’s desktop client, right-click on any note and select Copy Markdown link, you’ll get something like this on your clipboard: [Emergence](:/b419eedd617b4883bc7a0d68dd1ab3ef). Just change that URL to http://mysite.example.org/b419eedd617b4883bc7a0d68dd1ab3ef and it’s ready to share!

site-root/_notfound.php

<?php

// grab note ID from first unhandled path component
$noteId = array_shift(Site::$pathStack);


// bail if it's not there or doesn't match an existing note file
if (
    !$noteId
    || !$noteNode = Site::resolvePath(['notes', "{$noteId}.md"])
) {
    return RequestHandler::throwNotFoundError();
}


// get contents of Joplin note file and parse into components
$noteContent = stream_get_contents($noteNode->get());
preg_match('/(?<title>.*?)\n\n(?<body>.*)\n\n(?<trailers>.*)/s', $noteContent, $noteComponents);


// render a response
return RequestHandler::respond('note', [
    'id' => $noteId,
    'title' => $noteComponents['title'],
    'body' => $noteComponents['body'],
    'trailers' => $noteComponents['trailers']
]);

html-templates/note.tpl

{extends designs/site.tpl}

{block title}{$title|escape}&mdash;{$dwoo.parent}{/block}

{block content}
    <header class="page-header">
        <h1 class="header-title title-1">{$title|escape}</h1>
    </header>
    
    {$body|markdown}
{/block}