Fix bug open statics

This commit is contained in:
Andros Fenollosa
2021-07-30 01:33:02 +02:00
parent 8707081966
commit 13ef07f0b4
11 changed files with 27 additions and 20 deletions

View File

@@ -1,33 +1,33 @@
(ns rsspaper.html
(:require
[clojure.java.io :as io]
[rsspaper.config :refer [config]]
[clojure.string :as str]
[selmer.parser :as s]))
[clojure.java.io :as io]
[rsspaper.config :refer [config]]
[clojure.string :as str]
[selmer.parser :as s]
[me.raynes.fs :as fs]
[me.raynes.fs.compression :as fsc]))
(defn copy-uri-to-file [uri file]
(with-open [in (io/input-stream uri)
out (io/output-stream file)]
(io/copy in out)))
(defn make-html
[articles]
;; Render html in dist/index.html
(let [dir-dist "dist/"
file-index "index.html"
path-theme (io/resource (str "themes/" (:theme config) "/"))
path-dist-index (str dir-dist "index.html")
]
zip-static "static.zip"
tmp-static "/tmp/rsspaper.zip"]
;; Remove old index.html
#_(when (.exists (io/file path-dist-index)) (io/delete-file path-dist-index))
(when (.exists (io/file path-dist-index)) (io/delete-file path-dist-index))
;; Make dir dist
#_(.mkdir (java.io.File. dir-dist))
(fs/mkdir dir-dist)
;; Make dist/index.html
#_(with-open [wrtr (io/writer path-dist-index)]
(.write wrtr (s/render-file (str path-theme "index.html") {:title (:title config)
:articles articles})))
(with-open [writer (io/writer path-dist-index)]
(.write writer (s/render-file (str path-theme file-index) {:title (:title config)})))
;; Make statics
;; Iterate statics
(doseq [file (.listFiles (io/file path-theme) )]
(let [path (.getPath file)
relative-path (second (str/split path #"resources/"))
relative-dist-path (str dir-dist relative-path)]
;; Remove old static
(when (.exists (io/file relative-dist-path)) (io/delete-file relative-dist-path))
;; Copy new static
(io/copy (io/file path) (io/file dir-dist))))))
(copy-uri-to-file (str path-theme zip-static) tmp-static)
(fsc/unzip tmp-static dir-dist)))