Lichen v1.2
This unmaintained version of Lichen is written in PHP. It requires a more complex server setup with various .htaccess rewrites.
Changelog
1.2 (2022-05-15)
- Editor textarea forced to monospace typeface
- Better checking to ignore CMS directories
- Fixed syntax error (@milofultz@merveilles.town)
- Headers are limited to level 3 (@aw@merveilles.town)
- List items require space between asterisk and content (@aw@merveilles.town)
- No whitespace is tolerated before directives (@aw@merveilles.town)
- Nested directives are no longer allowed (@aw@merveilles.town)
- Alt tags are supported for preformatted blocks (@aw@merveilles.town)
- Blockquotes are limited to single line (@aw@merveilles.town)
- Ability to create new directories
- Ability to delete directories
- Empty directories are now displayed
- Improved file manager iconography
- Documented sample nginx configuration (@flyingrub@merveilles.town)
1.1 (2022-05-10)
- Case-insensitive file extension handling
- PHP7 support (@scops@social.tchncs.de)
1.0 (2022-05-09)
- Initial release.
Directory Structure
. ├── cms │ ├── edit.php │ ├── gemtext.php │ └── render.php ├── theme │ └── layout.php ├── .htaccess ├── index.gmi └── assets ├── image.jpg └── stylesheet.css
- 'cms' contains the Lichen code
- 'theme' contains the layout templates (not publicly accessible)
- '.htaccess' configures Apache to render Gemtext files as HTML and configures access control
- Everything else is free-form static hosting
Nginx
If you'd like to use Nginx instead of Apache, delete all of the .htaccess files and use this configuration:
map $is_redirected $auth_type { default "Restricted"; true "off"; } server { listen 80; root /var/www/html; include mime.types; index index.gmi; location / { # --- discard .gmi extensions and redirect rewrite (.*)\.gmi$ $1 permanent; # --- try .gmi files without extensions if (-f ${document_root}${uri}.gmi) { set $redirect_url ${uri}.gmi; set $is_redirected true; rewrite ^(.*)$ /cms/render.php?${redirect_url} last; } # --- try index files if (-f ${document_root}${uri}index.gmi) { set $redirect_url ${uri}index.gmi; set $is_redirected true; rewrite ^(.*)$ /cms/render.php?${redirect_url} last; } try_files $uri $uri/ =404; } location /cms/ { auth_basic $auth_type; auth_basic_user_file /home/private/lichen.htpasswd; fastcgi_split_path_info ^(.+\.php)(/.+)$; set $path_info $fastcgi_path_info; fastcgi_pass unix:/run/php/php-fpm.sock; include fastcgi_params; fastcgi_param REDIRECT_URL $redirect_url if_not_empty; fastcgi_param SCRIPT_FILENAME ${document_root}${fastcgi_script_name}; fastcgi_param PATH_INFO $path_info; try_files $fastcgi_script_name =404; } location /theme/ { return 404; } }
Layout
The main HTML template is 'theme/layout.php'. This template is rendered with the content of the current Gemtext file. The following PHP variables are provided:
- $path: the absolute path of the Gemtext file being requested (e.g. '/index.gmi')
- $title: the content of the first heading, useful for placing in the HTML <title> tag
- $body: the content of the Gemtext rendered to HTML
Image Processing
Not everyone is familiar with appropriate resolutions and image optimization for the web, so PHP's GD can be used to automatically resize uploaded images. The original source image will be discarded when this is enabled. Use the following environment variables:
- IMG_RESIZE_ENABLE: 'true' to enable (disabled by default)
- IMG_RESIZE_FORMAT: 'source' to use the same format as the original, or force everything to 'jpeg', 'gif', 'png', 'bmp', 'webp', or 'avif' (default 'source')
- IMG_RESIZE_MAX_WIDTH: number in pixels, images larger than this width will be reduced (default 800)
- IMG_RESIZE_JPEG_QUALITY: quality from 0 to 100 (library default is ~75)
- IMG_RESIZE_PNG_COMPRESSION: compression level from 0 to 9
- IMG_RESIZE_AVIF_QUALITY: quality from 0 to 100 (library default is 30)
- IMG_RESIZE_AVIF_SPEED: speed from 0 (slow, smaller file) to 10 (fast, larger file) (library default is 6)
- IMG_RESIZE_WEBP_QUALITY: quality from 0 to 100
These environment variables can be set in .htaccess if Apache's mod_env is enabled. See the provided .htaccess file.
Note that filenames must not have spaces in order to be compatible with the Gemtext link format. To facilitate this, spaces in filenames are automatically replaced with underscores when uploading via the editor UI.