<commit_before>(in-package :cl-notebook)

(define-handler (js/notebook-selector.js :content-type "application/javascript") ()
  (ps (defun notebook-link-template (notebook-path)
        (who-ps-html
         (:li (:a :href (+ "/#book=" notebook-path) notebook-path))))

      (defun selector-template (current-notebook)
        (who-ps-html
         (:div :class "notebook-selector"
          (:p :class "current-notebook" current-notebook)
          (:ul :class "loaded-books-list")
          (:input :class "filesystem-input")
          (:span :class "filesystem-view"))))

      (defun file-template (file)
        (who-ps-html
         (:li (:a :href (+ "/#book=" (@ file :string)) (@ file :name)))))

      (defun directory-template (directory)
        (who-ps-html
         (:li (:span :class "directory-link" (last (@ directory :directory))))))

      (defun filesystem-template (listing)
        (who-ps-html
         (:ul :class "filesystem-list"
              (+ (join (map directory-template (@ listing :directories)))
                 (join (map file-template (@ listing :files)))))))

      (defun filesystem! (input-elem elem directory)
        (get/json
         "/cl-notebook/system/ls" (create :dir directory)
         (lambda (dat)
           (dom-set elem (filesystem-template dat)))))

      (defun loaded-books! (elem)
        (get/json "/cl-notebook/loaded-books" (create)
                  (lambda (dat)
                    (dom-set
                     elem
                     (join (map notebook-link-template dat)) "Blah!"))))

      (defun notebook-selector! (selector)
        (let ((elem (by-selector selector)))
          (dom-set elem (selector-template (@ *notebook* id)))
          (loaded-books! (by-selector elem ".loaded-books-list"))
          (get/json "/cl-notebook/system/home-path" (create)
                    (lambda (initial-dir)
                      (setf (@ (by-selector elem ".filesystem-input") value) initial-dir)
                      (filesystem!
                       (by-selector elem ".filesystem-input") (by-selector elem ".filesystem-view")<commit_msg>Add filter-fs-listing<commit_after>(in-package :cl-notebook)

(define-handler (js/notebook-selector.js :content-type "application/javascript") ()
  (ps (defun notebook-link-template (notebook-path)
        (who-ps-html
         (:li (:a :href (+ "/#book=" notebook-path) notebook-path))))

      (defun selector-template (current-notebook)
        (who-ps-html
         (:div :class "notebook-selector"
          (:p :class "current-notebook" current-notebook)
          (:ul :class "loaded-books-list")
          (:input :class "filesystem-input")
          (:span :class "filesystem-view"))))

      (defun file-template (file)
        (who-ps-html
         (:li (:a :href (+ "/#book=" (@ file :string)) (@ file :name)))))

      (defun directory-template (directory)
        (who-ps-html
         (:li (:span :class "directory-link" (last (@ directory :directory))))))

      (defun filesystem-template (listing)
        (who-ps-html
         (:ul :class "filesystem-list"
              (+ (join (map directory-template (@ listing :directories)))
                 (join (map file-template (@ listing :files)))))))

      (defun filter-fs-listing (listing prefix)
        (let ((f (lambda (path) (chain (@ path :string) (starts-with prefix)))))
          (create :directories (filter f (@ listing :directories))
                  :files (filter f (@ listing :files)))))

      (defun filesystem! (input-elem elem directory)
        (get/json
         "/cl-notebook/system/ls" (create :dir directory)
         (lambda (dat)
           (console.log "FILTERED" (filter-fs-listing dat (+ directory ".b")))
           (dom-set elem (filesystem-template dat)))))

      (defun loaded-books! (elem)
        (get/json "/cl-notebook/loaded-books" (create)
                  (lambda (dat)
                    (dom-set
                     elem
                     (join (map notebook-link-template dat)) "Blah!"))))

      (defun notebook-selector! (selector)
        (let ((elem (by-selector selector)))
          (dom-set elem (selector-template (@ *notebook* id)))
          (loaded-books! (by-selector elem ".loaded-books-list"))
          (get/json "/cl-notebook/system/home-path" (create)
                    (lambda (initial-dir)
                      (setf (@ (by-selector elem ".filesystem-input") value) initial-dir)
                      (filesystem!
                       (by-selector elem ".filesystem-input") (by-selector elem ".filesystem-view")
{'fraction_non_alphanumeric': 0.15856329391151994, 'fraction_numerical': 0.0, 'mean_word_length': 2.0712844653665097, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4730265', 'n_tokens_mistral': 1348, 'n_tokens_neox': 1281, 'n_words': 314}