(import scheme) (import (chicken base)) (import (chicken file)) (import (chicken format)) (import (chicken io)) (import (chicken pathname)) (import (chicken process-context)) (import (chicken time)) (import (chicken time posix)) (import scsh-process) (define target-dir (make-pathname (get-environment-variable "HOME") "fallkiste")) (define (slugify path timestamp) (define charset "BEdar9GF7WCebpLS4ykYc2VZKsoNfxnhH8Qui1jUA3JDzM6twPqXRvmgT5") (define charset-size (string-length charset)) (define epoch (local-time->seconds #(0 0 0 1 0 120 0 0 #f 0))) (define (encode timestamp) (let loop ((timestamp timestamp) (chars '())) (if (> timestamp 0) (let ((char (string-ref charset (modulo timestamp charset-size)))) (loop (quotient timestamp charset-size) (cons char chars))) (list->string chars)))) (let ((ext (or (pathname-extension path) ".txt"))) (let* ((slug (encode (- timestamp epoch))) (new-path (make-pathname target-dir slug ext))) (copy-file path new-path) (run (permalink ,new-path))))) (case (length (command-line-arguments)) ((0) (let ((path (create-temporary-file ".txt"))) (call-with-output-file path (lambda (out) (display (read-string #f) out))) (slugify path (current-seconds)))) ((1) (slugify (car (command-line-arguments)) (current-seconds))) (else (fprintf (current-error-port) "usage: ~a [path]\n" (program-name)) (exit 1)))