wiki/spartan.md

2.8 KiB

spartan

spartan is a relatively new internet protocol that is somewhat similar to gemini but a lot of simpler to play with because of the lack of TLS.

like gemini, it is much lighter than the web and has a much smaller user base.

first time hearing about spartan? you should check out its homepage: gemini://spartan.mozz.us

at tilde.cafe, we run a spartan server (spsrv), and all ~cafe users can have their own files hosted on spartan by putting content in their ~/public_spartan directory.

your spartan site will then be live at both spartan://tilde.cafe/~username/ and spartan://username.tilde.cafe

the ~/public_spartan directory is not created by default. use mkdir ~/public_spartan to create it, then you can start building your site!

spartan uses gemtext markup (instead of, say, html for the web) for more information about how you write gemtext, check out the Introduction to Gemtext Markup, there is also a cheatsheet.

to browse spartan content, you will need a client or a web proxy.

clients

  • gelim: try gelim spartan://tilde.cafe at the terminal
  • or just use the web proxy portal.mozz.us

CGI

make sure you set the correct shebang and make the file executable.

then, print the status and type per the spartan spec: here's a simple example in sh

#!/bin/sh
printf "2 text/gemini\r\n"
echo "hello world"

note that the first line must send \r\n

if you want to debug your script, you can redirect your stderr into a file, if you use shell scripts, you'd do it like this:

#!/bin/sh
exec 2>/tmp/my_spartan_debug.txt
printf "2 text/gemini\r\n"
echo "hello world"

keep in mind that all cgi scripts run under a single user ("spartan"), so it might not have permission to run scripts, or write files, that you can

also be careful about what the scripts can write, because there's nothing preventing someone else from overwriting your files, with their scripts!

you can also check for the user's input. for example, you your index.gmi you can have a input prompt:

=: echo.sh send some input

then in echo.sh:

#!/usr/bin/env sh

printf "2 application/octet-stream\r\n"
cat /dev/stdin

try visiting your spartan page, enter some input on that link line and see the result!

alternatively you could send input directly in gelim:

gelim spartan://username.tilde.cafe/echo.sh -Ii 'hello!'

(note: -I is so gelim quits immediately after displaying output, -i is for sending the input)