diff options
author | Guilherme C. T <gctrindade@outlook.com> | 2022-07-31 02:50:41 -0700 |
---|---|---|
committer | Guilherme C. T <gctrindade@outlook.com> | 2022-07-31 02:50:41 -0700 |
commit | 710b763adf40d55624f7da7ee89b790ea212accc (patch) | |
tree | 57b35ce0b48d96e370e6c495996304b297299f28 /gemini.cl | |
parent | 723ad177189f8055e5ca01503f091dc920f8854b (diff) |
Added function to map a URL path to a local gemini file.url-file-mapping
Diffstat (limited to 'gemini.cl')
-rw-r--r-- | gemini.cl | 28 |
1 files changed, 28 insertions, 0 deletions
@@ -24,3 +24,31 @@ (defun status->number (key) (cdr (assoc key (reverse-alist +status-codes+)))) + +(defvar +site-root+ (pathname (user-homedir-pathname))) + +(defun find-resource (url-path-string) + ;; If the URL ends with a `.gmi` or `.gemini`, assume it points to a file and check if it exists. + ;; Otherwise, assume it points to a directory, and check if `index.gmi` or `index.gemini` exists in that directory. + ;; Returns the pathname of the file if it exists; nil otherwise. + (let ((path-local (merge-pathnames (pathname url-path-string) +site-root+))) + (cond ( + (search ".." url-path-string) + ; TODO: Replace this with some sort of (is-unsafe-URL) function. + ; URL is unsafe. + nil) + ((or (string= "gmi" (pathname-type path-local)) + (string= "gemini" (pathname-type path-local))) + ; URL points to a file. + (probe-file path-local)) + (t + ; URL points to a directory. + ; Due to how pathnames work, we must ensure that the last character in the URL is a single "/" for it to be treated as a directory. + (let + ((path-local-dir (pathname + (if (pathname-name path-local) + (pathname (concatenate 'string (namestring path-local) "/")) + path-local + )))) + (or (probe-file (merge-pathnames "index.gmi" path-local-dir)) + (probe-file (merge-pathnames "index.gemini" path-local-dir))))))))
\ No newline at end of file |