A self-hosted alternative backend for the Obsidian Share Note plugin.
This re-implements the share-note-self-hosted-backend in Python with a few changes:
- fully documented setup instructions
- no database
- readable links in the form of: https://notes.dns.t0.vc/share-note-example-7cf9f1
- note encryption is not yet implemented (I trust my own server)
- note expiry is not yet implemented
- bottom right "Published with Share Note" replaced with larger theme toggle button
- note named "Share Note Index" presented as domain's index page, example: https://notes.dns.t0.vc/
- Point a domain / subdomain to your server.
- Set up the sharenote-py server using the Docker or Python instructions below.
- Install the "Share Note" community plugin by Alan Grainger.
- Activate the plugin, open the plugin's settings page.
- Disable "Share as encrypted by default" at the bottom (not yet implemented), close settings.
- Edit the
.obsidian/plugins/share-note/data.json
file in your vault's filesystem. - Set the "server" value to your server's URL from step 1, example:
https://notes.example.com
(no trailing slash). - Open Obsidian's Community Plugins settings, then deactivate and reactivate the Share Note plugin.
You should back up the static/
directory where the notes are so that links don't break if you have to set this all up again.
Assuming you already have Docker installed:
$ cp settings.py.example settings.py
$ vim settings.py
$ sudo docker compose build sharenote
$ sudo docker compose up -d
The sharenote-py server will now be listening on port 8086.
You should now skip to the reverse proxy instructions below, or set one up with Docker.
View logs:
$ docker compose logs -f
How to update:
$ sudo docker compose down
$ git pull --rebase
$ sudo docker compose build sharenote
$ sudo docker compose up -d
Run the last two commands any time you make a change (ie. to settings.py
).
This guide assumes a modern Debian or Ubuntu GNU/Linux server.
Install dependencies:
$ sudo apt install python3 python3-pip python3-virtualenv
Clone this repo, create a venv, activate it, and install:
$ git clone https://github.com/tannercollin/sharenote-py.git
$ cd sharenote-py/
$ virtualenv -p python3 env
$ source env/bin/activate
(env) $ pip install -r requirements.txt
Copy the settings file and edit it:
$ cp settings.py.example settings.py
$ sensible-editor settings.py
You can now run it directly:
$ source env/bin/activate
(env) $ DEBUG=true python main.py
The above run command is useful for development / debugging. In production we'll run it with gunicorn
.
You can keep sharenote-py alive with supervisor:
$ sudo apt install supervisor
$ sudo touch /etc/supervisor/conf.d/sharenote.conf
$ sudoedit /etc/supervisor/conf.d/sharenote.conf
Edit the file, replacing tanner
with your user and sharenote-py location:
[program:sharenote]
user=tanner
directory=/home/tanner/sharenote-py
command=/home/tanner/sharenote-py/env/bin/gunicorn main:flask_app
stopasgroup=true
killasgroup=true
autostart=true
autorestart=true
stderr_logfile=/var/log/sharenote.log
stderr_logfile_maxbytes=10MB
stdout_logfile=/var/log/sharenote.log
stdout_logfile_maxbytes=10MB
Load the supervisor config:
$ sudo supervisorctl reread; sudo supervisorctl reload
You can control the supervisor process with these commands:
$ sudo supervisorctl status sharenote
$ sudo supervisorctl restart sharenote
$ sudo supervisorctl stop sharenote
$ sudo supervisorctl start sharenote
Next configure a reverse proxy following the instructions below.
To expose sharenote-py via https, you should configure an nginx reverse proxy:
$ sudo apt install nginx certbot python3-certbot-nginx
$ sudoedit /etc/nginx/sites-available/default
Add to the bottom of the file:
server {
root /var/www/html;
index index.html index.htm;
server_name notes.example.com; # replace with the domain you pointed to the server. don't forget the semicolon.
client_max_body_size 20M;
location / {
proxy_pass http://127.0.0.1:8086/;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
# will get switched automatically:
listen 80;
}
Then run sudo certbot --nginx
and follow the prompts.
Generate SSL certificate:
$ sudo service nginx restart
$ sudo certbot --nginx
Follow prompts to activate HTTPS and enable redirects.
This program is free and open-source software licensed under the MIT License. Please see the LICENSE
file for details.
That means you have the right to study, change, and distribute the software and source code to anyone and for any purpose. You deserve these rights.
Thanks to @alangrainger for making the Share Note plugin.
Thanks to all the devs behind Obsidian.