Skip to content

Commit

Permalink
fix client sanitize, fix hash navigation, render 2 col index, drain b…
Browse files Browse the repository at this point in the history
…uffers in runner
  • Loading branch information
carbon-hvze committed Aug 7, 2023
1 parent 3579a75 commit 227aa06
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 17 deletions.
9 changes: 6 additions & 3 deletions src/js/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -310,9 +310,12 @@ main(() => {
}

window.addEventListener('popstate', (ev) => {
console.log('pop', ev, window.location.href);
var href = window.location.href;
load_page(href, false);
var l = new URL(window.location.href);
if (!l.hash){
console.log('pop', ev, window.location.href);
var href = window.location.href;
load_page(href, false);
}
});

// TODO check prefix to use in browser app
Expand Down
2 changes: 1 addition & 1 deletion src/js/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ var on_editor_keydown = (ctx, ev) => {
};

var sanitize = (s) => {
return s.replace(/[\u0020\u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff]+/g, " ");
return s.replace(/[\u0020\u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff]/g, " ");
};

var _render = (ev)=> {
Expand Down
2 changes: 1 addition & 1 deletion src/zd/blocks/content.clj
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
[:div (zentext/parse-block ztx data block)])

(defmethod methods/rendercontent :datalog
[ztx ctx {{headers :table-of} :ann data :data :as block}]
[ztx ctx {data :data :as block}]
(if-let [params (:in data)]
;; TODO impl preprocess to remove :in from queries
(apply d/query ztx data params)
Expand Down
28 changes: 22 additions & 6 deletions src/zd/blocks/zd.clj
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,29 @@
(partition-by #(= 1 (count (:ps %))))
(partition 2)
(map (fn [[h t]]
(concat h t))))]
[:div {:class (c :flex :flex-wrap [:w "100%"])}
(for [gr docs]
[:div {:class (c [:py 2] [:pr 10] :text-sm :flex-col :flex)}
(for [{:keys [s ps]} gr]
(if (> (count t) 20)
h
(concat h t)))))
total (reduce + (map count docs))
group-idx (loop [[[idx item] & oth] (map-indexed vector (map count docs))
left (int (/ total 2))]
(if (<= left 0)
idx
(recur oth (- left item))))
[l r] (split-at group-idx docs)]
[:div {:class (c :flex :flex-row)}
[:div {:class (c :flex [:w "50%"])}
[:div {:class (c [:py 2] [:w "50%"] :text-sm :flex-col :flex)}
(doall
(for [{:keys [s ps]} (apply concat l)]
[:div (conj (indent-item ps)
(link/symbol-link ztx s))])])]))
(link/symbol-link ztx s))]))]]
[:div {:class (c :flex [:w "50%"])}
[:div {:class (c [:py 2] [:w "50%"] :text-sm :flex-col :flex)}
(doall
(for [{:keys [s ps]} (apply concat r)]
[:div (conj (indent-item ps)
(link/symbol-link ztx s))]))]]]))

(defmethod methods/renderkey :zd/docname
[ztx ctx {data :data :as block}]
Expand Down
19 changes: 13 additions & 6 deletions src/zd/runner.clj
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
(ns zd.runner
(:require [clojure.java.io :as io]
[clojure.string :as str])
(:import [java.lang ProcessBuilder]))
(:import [java.lang ProcessBuilder]
[java.util.concurrent TimeUnit]))

(defn read-env [override]
(->
Expand Down Expand Up @@ -29,11 +30,17 @@

(defn exec [{dir :dir env :env args :exec :as opts}]
(let [prc (proc opts)
p (.start prc)]
(.waitFor p)
{:status (.exitValue p)
:stdout (read-stream (.getInputStream p))
:stderr (read-stream (.getErrorStream p))}))
p (.start prc)
inp (.getInputStream p)
err (.getErrorStream p)]
(loop [stdout []
stderr []]
(if (.waitFor p 30 TimeUnit/SECONDS)
{:status (.exitValue p)
:stdout (into stdout (read-stream inp))
:stderr (into stderr (read-stream err))}
(recur (into stdout (read-stream inp))
(into stderr (read-stream err)))))))

(defn run [opts]
(let [prc (proc opts)]
Expand Down

0 comments on commit 227aa06

Please sign in to comment.