💾 Archived View for gemini.sensorstation.co › computing.gemini.gmi-to-html.gmi captured on 2022-01-08 at 13:40:44. Gemini links have been rewritten to link to archived content

View Raw

More Information

-=-=-=-=-=-=-

gmi-to-html.php

We needed to share some frequently-updated content over HTTP; the particular consumers of this content can't be bothered to use Gemini. First we went with plain text as a no-software solution, but line wrapping issues produced a hideous result with difficult readability. Markdown seems like an obvious next choice, but parsing it is tricky; something we wouldn't want to do without pulling in a library. We didn't want to get burned in the future by versioning or configuration issues with a Markdown library (Python/library versioning conflicts, subdependencies breaking, etc.; you know, software).

Since gemtext is so simple to parse, we whipped one up just a few hours with no dependencies. Now we can write and store plain gemtext on our web server and have PHP generate HTML on the fly with nice styles and proper text wrapping.

gmi-to-html.php

Here's a sample .htaccess file to make this work with Apache.

DirectoryIndex index.gmi

# DISABLE CACHING
Header set Cache-Control "no-cache, no-store, must-revalidate" 	
Header set Pragma "no-cache" 	
Header set Expires 0

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.gmi [NC,L]

RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^.+\.gmi$ /gmi-to-html.php [NC,L]

ErrorDocument 404 /index.gmi
ErrorDocument 403 /index.gmi