Fork me on GitHub
#reagent
<
2022-10-20
>
agorgl09:10:37

Hello! Is there any good html minifier that works with babashka?

borkdude09:10:06

@U03PYN9FG77 I think for html minifiers you should look at the JS ecosystem probably. e.g. https://www.npmjs.com/package/html-minifier-terser

agorgl09:10:28

I saw that bootleg had recently (March) added a compress-html function but it is not yet in latest release!

agorgl09:10:41

I'm trying to make a utility that converts html to pretty hiccup (to integrate it into my editor), so far I have something in the lines of:

(ns html2hiccup
  (:require [babashka.pods :as pods]
            [babashka.deps :as deps]
            [clojure.string :as str]))

(pods/load-pod 'retrogradeorbit/bootleg "0.1.9")
(deps/add-deps '{:deps {zprint/zprint {:mvn/version "1.2.4"}}})
(deps/add-deps '{:deps {org.babashka/spec.alpha {:git/url ""
                                                 :git/sha "1a841c4cc1d4f6dab7505a98ed2d532dd9d56b78"}}})

(require '[pod.retrogradeorbit.bootleg.utils :refer [convert-to]]
         '[zprint.core :refer [zprint]])

(-> *in*
    slurp
    (convert-to :hiccup-seq)
    (zprint {:style :hiccup}))

agorgl09:10:05

My problem is that hickory adds whitespace to converted output like this:

❯ echo -n '<div class="hello"><p>    This is an example</p></div>' | ./html2hiccup.clj
([:div {:class "hello"}
  [:p "    This is an example"]])

borkdude09:10:58

You could maybe just strip the whitespace yourself?

agorgl09:10:13

Yeah I'll probably do that for now