Overview
| Comment: | Move normalize func into dust.rkt | 
|---|---|
| Timelines: | family | ancestors | descendants | both | trunk | 
| Files: | files | file ages | folders | 
| SHA3-256: | dc2a4bd031e4ab5cc9cf3a66f53d5104 | 
| User & Date: | joel on 2020-03-31 03:45:52 | 
| Other Links: | manifest | tags | 
Context
| 2020-03-31 | ||
| 03:49 | Make xref tag more convenient, update code docs check-in: 63baf301 user: joel tags: trunk | |
| 03:45 | Move normalize func into dust.rkt check-in: dc2a4bd0 user: joel tags: trunk | |
| 2020-03-24 | ||
| 03:26 | Style updates for headings, lists, and separators check-in: 34d3bec4 user: joel tags: trunk | |
Changes
Modified code-docs/dust.scrbl from [6b21bda7] to [33008fed].
| ︙ | ︙ | |||
| 154 155 156 157 158 159 160 161 162 163 164 165 166 167 | 
(first-words txs-decimals 5)
(first-words txs-punc-and-split-elems 5)
(first-words txs-dashes 5)
(first-words txs-parens-commas 5)
(first-words txs-short 5)
]
@section{Article parsers and helpers}
@defparam[listing-context ctxt (or/c 'blog 'feed 'print "") #:value ""]
A parameter specifying the current context where any listings of articles would appear. Its purpose
is to allow articles to exclude themselves from certain special collections (e.g., the blog, the RSS
 | > > > > > > > > > > > > | 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 | 
(first-words txs-decimals 5)
(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 ""]
A parameter specifying the current context where any listings of articles would appear. Its purpose
is to allow articles to exclude themselves from certain special collections (e.g., the blog, the RSS
 | 
| ︙ | ︙ | 
Modified dust.rkt from [aa082dfb] to [cb0db902].
| ︙ | ︙ | |||
| 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | 
         web-root
         articles-folder
         series-folder
         images-folder
         articles-pagetree
         series-pagetree
         first-words
         build-note-id
         notes->last-disposition-values
         disposition-values
         )
(define default-authorname "Joel Dueck")
(define series-folder "series")
 | > | 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | 
         web-root
         articles-folder
         series-folder
         images-folder
         articles-pagetree
         series-pagetree
         first-words
         normalize
         build-note-id
         notes->last-disposition-values
         disposition-values
         )
(define default-authorname "Joel Dueck")
(define series-folder "series")
 | 
| ︙ | ︙ | |||
| 257 258 259 260 261 262 263 264 265 266 267 268 269 270 | 
  (check-equal? (first-words txs-decimals 5) "Four score and 7.8 years")
  (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, e.g., "* thoroughly recanted" into (values "*" "thoroughly recanted")
(define (disposition-values str)
  (cond [(string=? "" str) (values "" "")]
        [else (let ([splut (string-split str)])
                (values (car splut) (string-join (cdr splut))))]))
 | > > > > > > | 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 | 
  (check-equal? (first-words txs-decimals 5) "Four score and 7.8 years")
  (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)])
                (values (car splut) (string-join (cdr splut))))]))
 | 
| ︙ | ︙ | 
Modified util/newpost.rkt from [d7b70e83] to [5a285fa8].
| ︙ | ︙ | |||
| 9 10 11 12 13 14 15 | 
         racket/string
         racket/file
         racket/system
         "../dust.rkt")
(provide main)
 | < < < < < | 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | 
         racket/string
         racket/file
         racket/system
         "../dust.rkt")
(provide main)
(define (make-filename basename)
  (build-path (current-directory) articles-folder (string-append basename ".poly.pm")))
(define (comment . strs)
  (format "◊; ~a" (apply string-append strs)))
(define date-string
 | 
| ︙ | ︙ |