mirror of
https://github.com/tanrax/RSSPAPER.git
synced 2025-11-25 12:06:14 -05:00
Render posts
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
(ns rsspaper.config
|
||||
(:require
|
||||
[clj-yaml.core :as yaml]))
|
||||
(:require
|
||||
[clj-yaml.core :as yaml]))
|
||||
|
||||
(def config (yaml/parse-string (slurp "config.yaml")))
|
||||
(def config (yaml/parse-string (slurp "config.yaml")))
|
||||
@@ -1,24 +1,10 @@
|
||||
(ns rsspaper.core
|
||||
(:require
|
||||
[rsspaper.config :refer [config]]
|
||||
[ring.middleware.defaults :refer [site-defaults wrap-defaults]]
|
||||
[ring.middleware.reload :refer [wrap-reload]]
|
||||
[ring.middleware.cors :refer [wrap-cors]]
|
||||
[rsspaper.urls :refer [all-routes]]
|
||||
[ring.adapter.jetty :refer [run-jetty]]) (:gen-class))
|
||||
|
||||
(def wrapped-handler
|
||||
;; Handler middlewares
|
||||
(-> all-routes
|
||||
(wrap-defaults (assoc-in site-defaults [:security :anti-forgery] false))
|
||||
(wrap-cors
|
||||
:access-control-allow-origin [(re-pattern (if (config :debug) ".*" (config :domain)))]
|
||||
:access-control-allow-methods [:get])
|
||||
(#(if (config :debug) (wrap-reload %) %))))
|
||||
(:require
|
||||
[rsspaper.feeds :refer [get-feeds]]
|
||||
[rsspaper.html :refer [make-html]]) (:gen-class))
|
||||
|
||||
(defn -main [& args]
|
||||
;; Main
|
||||
;; Welcome
|
||||
(prn (str "Open " (config :domain) ":" (config :port)))
|
||||
;; Run web server
|
||||
(run-jetty wrapped-handler {:port (config :port)}))
|
||||
(prn "Reading feeds... Please be patient.")
|
||||
(make-html (get-feeds))
|
||||
(prn "Generated \uD83D\uDCF0 in 'dist/index.html'!"))
|
||||
9
src/rsspaper/feeds.clj
Normal file
9
src/rsspaper/feeds.clj
Normal file
@@ -0,0 +1,9 @@
|
||||
(ns rsspaper.feeds
|
||||
(:require
|
||||
[rsspaper.config :refer [config]]
|
||||
[remus :refer [parse-url]]))
|
||||
|
||||
(defn get-feeds
|
||||
[]
|
||||
;; Get all feeds from config -> feeds
|
||||
(reduce (fn [feeds feed-url] (conj feeds (parse-url feed-url {:insecure? true :throw-exceptions false}))) [] (:feeds config)))
|
||||
@@ -1 +1,18 @@
|
||||
(ns rsspaper.html)
|
||||
(ns rsspaper.html
|
||||
(:require
|
||||
[clojure.java.io :as io]
|
||||
[rsspaper.config :refer [config]]
|
||||
[selmer.parser :as s]))
|
||||
|
||||
(defn make-html
|
||||
[data]
|
||||
;; Render html in dist/index.html
|
||||
(let [dir "dist"
|
||||
path (str dir "/index.html")]
|
||||
;; Remove old index.html
|
||||
(when (.exists (io/file path)) (io/delete-file path))
|
||||
;; Make dir dist
|
||||
(.mkdir (java.io.File. dir))
|
||||
;; Make dist/index.html
|
||||
(with-open [wrtr (io/writer path)]
|
||||
(.write wrtr (s/render-file (str "themes/" (:theme config) ".html") {:data data})))))
|
||||
@@ -1,20 +0,0 @@
|
||||
(ns rsspaper.urls
|
||||
(:require
|
||||
[compojure.core :refer [defroutes GET]]
|
||||
[compojure.route :as route]
|
||||
[rsspaper.views.public :as view-public]))
|
||||
|
||||
(defroutes public
|
||||
;; Urls public pages
|
||||
(GET "/" [] view-public/index)
|
||||
(GET "/api" [] view-public/api))
|
||||
|
||||
|
||||
(defroutes resources-routes
|
||||
;; Resources (statics)
|
||||
(route/resources "/")
|
||||
(route/not-found view-public/page-404))
|
||||
|
||||
(def all-routes
|
||||
;; Wrap routers. "resources-routes" should always be the last.
|
||||
(compojure.core/routes public resources-routes))
|
||||
@@ -1,20 +0,0 @@
|
||||
;;;; Views public web
|
||||
(ns rsspaper.views.public
|
||||
(:require
|
||||
[tadam.templates :refer [render-HTML render-JSON render-404]]
|
||||
))
|
||||
|
||||
(defn index
|
||||
;; View HTML
|
||||
[req]
|
||||
(render-HTML req "public/welcome.html" {}))
|
||||
|
||||
(defn api
|
||||
;; View JSON
|
||||
[req]
|
||||
(render-JSON req {:result true}))
|
||||
|
||||
(defn page-404
|
||||
;; View page 404
|
||||
[req]
|
||||
(render-404 req "public/404.html" {}))
|
||||
Reference in New Issue
Block a user