Index: code-docs/dust.scrbl ================================================================== --- code-docs/dust.scrbl +++ code-docs/dust.scrbl @@ -156,10 +156,22 @@ (first-words txs-punc-and-split-elems 5) (first-words txs-dashes 5) (first-words txs-parens-commas 5) (first-words txs-short 5) ] + +@defproc[(normalize [str string?]) string?]{ + +Removes all non-space/non-alphanumeric characters from @racket[_str], converts it to lowercase, and +replaces all spaces with hyphens. + +@examples[#:eval dust-eval +(normalize "Why, Hello World!") +(normalize "My first-ever 99-argument function, haha") +] + +} @section{Article parsers and helpers} @defparam[listing-context ctxt (or/c 'blog 'feed 'print "") #:value ""] Index: dust.rkt ================================================================== --- dust.rkt +++ dust.rkt @@ -43,10 +43,11 @@ series-folder images-folder articles-pagetree series-pagetree first-words + normalize build-note-id notes->last-disposition-values disposition-values ) @@ -259,10 +260,16 @@ (check-equal? (first-words txs-punc+split-elems 5) "Stop! she called. She was") (check-equal? (first-words txs-dashes 5) "One and only one. That") (check-equal? (first-words txs-dashes 4) "One and only one.") (check-equal? (first-words txs-parens-commas 5) "She counted one two silently") (check-equal? (first-words txs-short 5) "Not much here!")) + +;; Convert a string into all lowercase, replace all non-alphanum chars with ‘-’ +(define (normalize str) + (~> (regexp-replace* #rx"[^A-Za-z0-9 ]" str "") + string-downcase + (string-normalize-spaces #px"\\s+" "-"))) ;; Convert, e.g., "* thoroughly recanted" into (values "*" "thoroughly recanted") (define (disposition-values str) (cond [(string=? "" str) (values "" "")] [else (let ([splut (string-split str)]) Index: util/newpost.rkt ================================================================== --- util/newpost.rkt +++ util/newpost.rkt @@ -11,15 +11,10 @@ racket/system "../dust.rkt") (provide main) -(define (normalize str) - (define alphanum-only - (regexp-replace* #rx"[^A-Za-z0-9 ]" str "")) - (string-normalize-spaces (string-downcase alphanum-only) #px"\\s+" "-")) - (define (make-filename basename) (build-path (current-directory) articles-folder (string-append basename ".poly.pm"))) (define (comment . strs) (format "◊; ~a" (apply string-append strs)))