add correct href proc, planning

This commit is contained in:
mehbark 2024-04-15 00:23:22 -04:00
parent 6128cd44f6
commit 03f0b12ea9

View file

@ -12,21 +12,28 @@
; terrible, idc
; lossy! (not surprising)
; upcase for nice interning
(defun normalize-name (name)
(ppcre:regex-replace-all
"(^TRACK:|^-+|-+$)"
(ppcre:regex-replace-all
"[^A-Z0-9]+"
(sb-unicode:normalize-string (string-upcase name) :nfkd)
"-")
""))
(defun track->href (track)
(or (gethash "Directory" track)
(let ((r (copy-array (gethash "Track" track))))
(setf r (ppcre:regex-replace-all " " r "-"))
(setf r (ppcre:regex-replace-all "&" r "and"))
(setf r (ppcre:regex-replace-all "[^a-zA-Z0-9-]" r ""))
(setf r (ppcre:regex-replace-all "-{2,}" r ""))
(setf r (ppcre:regex-replace-all "^-+|-+$" r ""))
(nstring-downcase r))))
;; (defun track-ref-p)
(defun track->url (track)
(format nil "https://hsmusic.wiki/track/~a" (track->href track)))
;; (defun track-ref)
; let's just store the href because that's unambiguous and links are desirable anyway
(defun track-normalized-name (track)
(normalize-name (gethash "Track" track)))
; string name -> href
; so we don't have to research over and over
; there's ambiguity here! so consult only when not given a track:!
(defparameter hrefs (make-hash-table :test 'equal))
(loop for track in tracks
do (setf (gethash (gethash "Track" track) hrefs) (track->href track)))
; a -> b <-> a references b
; screw it! let's use symbols. why not? (LKFDSJKFDJ)