mirror of
https://github.com/tanrax/RSSPAPER.git
synced 2025-04-10 22:48:02 -04:00
Render posts
This commit is contained in:
parent
997aebb204
commit
1524602e6d
4
.gitignore
vendored
Normal file
4
.gitignore
vendored
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
dist/
|
||||||
|
target/
|
||||||
|
/.lein-repl-history
|
||||||
|
/.nrepl-port
|
@ -1,8 +1,8 @@
|
|||||||
title: RSSPaper
|
title: RSSPaper
|
||||||
# Options: light or dark
|
# Options: light or dark
|
||||||
theme: dark
|
theme: light
|
||||||
# Options: daily, yesterday, weekly or all
|
# Options: daily, yesterday, weekly or all
|
||||||
edition: yesterday
|
edition: all
|
||||||
feeds:
|
feeds:
|
||||||
- https://programadorwebvalencia.com/feed/
|
- https://programadorwebvalencia.com/feed/
|
||||||
- https://republicaweb.es/feed/
|
- https://republicaweb.es/feed/
|
||||||
|
19
project.clj
19
project.clj
@ -1,21 +1,10 @@
|
|||||||
(defproject rsspaper "0.1.0"
|
(defproject rsspaper "1.0.0"
|
||||||
:description "RSSpaper"
|
:description "RSSpaper"
|
||||||
:url "https://github.com/tanrax/RSSpaper"
|
:url "https://github.com/tanrax/RSSpaper"
|
||||||
:license {:name "EPL-2.0 OR GPL-2.0-or-later WITH Classpath-exception-2.0"
|
:license {:name "EPL-2.0 OR GPL-2.0-or-later WITH Classpath-exception-2.0"
|
||||||
:url "https://www.eclipse.org/legal/epl-2.0/"}
|
:url "https://www.eclipse.org/legal/epl-2.0/"}
|
||||||
:dependencies [;; Clojure
|
:dependencies [;; Clojure
|
||||||
[org.clojure/clojure "1.10.1"]
|
[org.clojure/clojure "1.10.3"]
|
||||||
;; Tadam core
|
|
||||||
[tadam-core "0.3.2"]
|
|
||||||
;; HTTP Server
|
|
||||||
[ring "1.8.0"]
|
|
||||||
;; Ring middleware that prevents CSRF attacks
|
|
||||||
[ring/ring-defaults "0.3.2"]
|
|
||||||
[ring/ring-anti-forgery "1.3.0"]
|
|
||||||
;; Routing
|
|
||||||
[compojure "1.6.1"]
|
|
||||||
;; Cors
|
|
||||||
[ring-cors "0.1.13"]
|
|
||||||
;; Templates
|
;; Templates
|
||||||
[selmer "1.12.12"]
|
[selmer "1.12.12"]
|
||||||
;; Yaml
|
;; Yaml
|
||||||
@ -23,7 +12,7 @@
|
|||||||
;; JSON encoding
|
;; JSON encoding
|
||||||
[cheshire "5.9.0"]
|
[cheshire "5.9.0"]
|
||||||
;; Parse RSS/Atom feeds
|
;; Parse RSS/Atom feeds
|
||||||
[ccxx.cx/feedparser-clj "0.6.0"]
|
[remus "0.2.1"]
|
||||||
;; Make RSS/Atom feeds
|
;; Make RSS/Atom feeds
|
||||||
[clj-rss "0.2.6"]]
|
[clj-rss "0.2.6"]]
|
||||||
:plugins [;; DEV TOOLS
|
:plugins [;; DEV TOOLS
|
||||||
@ -33,8 +22,6 @@
|
|||||||
[lein-cljfmt "0.6.4"]
|
[lein-cljfmt "0.6.4"]
|
||||||
;;; Generate documentation
|
;;; Generate documentation
|
||||||
[lein-codox "0.10.7"]]
|
[lein-codox "0.10.7"]]
|
||||||
;; Map configuration for Ring
|
|
||||||
:ring {:handler rsspaper.core.wrapped-handler}
|
|
||||||
;; ALIAS
|
;; ALIAS
|
||||||
:aliases {"check-idiomatic" ["kibit" "src"]
|
:aliases {"check-idiomatic" ["kibit" "src"]
|
||||||
"check-format" ["cljfmt" "check"]}
|
"check-format" ["cljfmt" "check"]}
|
||||||
|
@ -32,12 +32,28 @@
|
|||||||
</style>
|
</style>
|
||||||
<style media="all and (min-width: 601px)">
|
<style media="all and (min-width: 601px)">
|
||||||
body {
|
body {
|
||||||
background: green;
|
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
<!-- End CSS -->
|
<!-- End CSS -->
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
<main>
|
||||||
|
<h1>RSSPaper</h1>
|
||||||
|
{% for item in data %}
|
||||||
|
<h2>{{ item.feed.title }}</h2>
|
||||||
|
<section>
|
||||||
|
{% for article in item.feed.entries %}
|
||||||
|
<article>
|
||||||
|
<header>
|
||||||
|
<h3>{{ article.title }}</h3>
|
||||||
|
</header>
|
||||||
|
<main>
|
||||||
|
{{ article.description.value|safe }}
|
||||||
|
</main>
|
||||||
|
</article>
|
||||||
|
{% endfor %}
|
||||||
|
</section>
|
||||||
|
{% endfor %}
|
||||||
|
</main>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
54
rsspaper.iml
Normal file
54
rsspaper.iml
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module cursive.leiningen.project.LeiningenProjectsManager.displayName="rsspaper:1.0.0" cursive.leiningen.project.LeiningenProjectsManager.isLeinModule="true" type="JAVA_MODULE" version="4">
|
||||||
|
<component name="NewModuleRootManager">
|
||||||
|
<output url="file://$MODULE_DIR$/target/classes" />
|
||||||
|
<output-test url="file://$MODULE_DIR$/target/classes" />
|
||||||
|
<exclude-output />
|
||||||
|
<content url="file://$MODULE_DIR$">
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/dev-resources" isTestSource="false" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/resources" isTestSource="false" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/target" />
|
||||||
|
</content>
|
||||||
|
<orderEntry type="inheritedJdk" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
<orderEntry type="library" name="Leiningen: cheshire:5.9.0" level="project" />
|
||||||
|
<orderEntry type="library" name="Leiningen: clj-http:3.10.2" level="project" />
|
||||||
|
<orderEntry type="library" name="Leiningen: clj-rss:0.2.6" level="project" />
|
||||||
|
<orderEntry type="library" name="Leiningen: clj-tuple:0.2.2" level="project" />
|
||||||
|
<orderEntry type="library" name="Leiningen: clj-yaml:0.4.0" level="project" />
|
||||||
|
<orderEntry type="library" name="Leiningen: clojure-complete:0.2.5" level="project" />
|
||||||
|
<orderEntry type="library" name="Leiningen: com.fasterxml.jackson.core/jackson-core:2.9.9" level="project" />
|
||||||
|
<orderEntry type="library" name="Leiningen: com.fasterxml.jackson.dataformat/jackson-dataformat-cbor:2.9.9" level="project" />
|
||||||
|
<orderEntry type="library" name="Leiningen: com.fasterxml.jackson.dataformat/jackson-dataformat-smile:2.9.9" level="project" />
|
||||||
|
<orderEntry type="library" name="Leiningen: com.rometools/rome-utils:1.15.0" level="project" />
|
||||||
|
<orderEntry type="library" name="Leiningen: com.rometools/rome:1.15.0" level="project" />
|
||||||
|
<orderEntry type="library" name="Leiningen: commons-codec:1.11" level="project" />
|
||||||
|
<orderEntry type="library" name="Leiningen: commons-io:2.6" level="project" />
|
||||||
|
<orderEntry type="library" name="Leiningen: commons-logging:1.2" level="project" />
|
||||||
|
<orderEntry type="library" name="Leiningen: hiccup:1.0.5" level="project" />
|
||||||
|
<orderEntry type="library" name="Leiningen: json-html:0.4.4" level="project" />
|
||||||
|
<orderEntry type="library" name="Leiningen: nrepl:0.6.0" level="project" />
|
||||||
|
<orderEntry type="library" name="Leiningen: org.apache.httpcomponents/httpasyncclient:4.1.4" level="project" />
|
||||||
|
<orderEntry type="library" name="Leiningen: org.apache.httpcomponents/httpclient-cache:4.5.10" level="project" />
|
||||||
|
<orderEntry type="library" name="Leiningen: org.apache.httpcomponents/httpclient:4.5.10" level="project" />
|
||||||
|
<orderEntry type="library" name="Leiningen: org.apache.httpcomponents/httpcore-nio:4.4.10" level="project" />
|
||||||
|
<orderEntry type="library" name="Leiningen: org.apache.httpcomponents/httpcore:4.4.12" level="project" />
|
||||||
|
<orderEntry type="library" name="Leiningen: org.apache.httpcomponents/httpmime:4.5.10" level="project" />
|
||||||
|
<orderEntry type="library" name="Leiningen: org.clojure/clojure:1.10.3" level="project" />
|
||||||
|
<orderEntry type="library" name="Leiningen: org.clojure/core.specs.alpha:0.2.56" level="project" />
|
||||||
|
<orderEntry type="library" name="Leiningen: org.clojure/data.codec:0.1.0" level="project" />
|
||||||
|
<orderEntry type="library" name="Leiningen: org.clojure/data.xml:0.2.0-alpha6" level="project" />
|
||||||
|
<orderEntry type="library" name="Leiningen: org.clojure/spec.alpha:0.2.194" level="project" />
|
||||||
|
<orderEntry type="library" name="Leiningen: org.jdom/jdom2:2.0.6" level="project" />
|
||||||
|
<orderEntry type="library" name="Leiningen: org.slf4j/slf4j-api:1.7.16" level="project" />
|
||||||
|
<orderEntry type="library" name="Leiningen: org.yaml/snakeyaml:1.5" level="project" />
|
||||||
|
<orderEntry type="library" name="Leiningen: potemkin:0.4.5" level="project" />
|
||||||
|
<orderEntry type="library" name="Leiningen: remus:0.2.1" level="project" />
|
||||||
|
<orderEntry type="library" name="Leiningen: riddley:0.1.12" level="project" />
|
||||||
|
<orderEntry type="library" name="Leiningen: selmer:1.12.12" level="project" />
|
||||||
|
<orderEntry type="library" name="Leiningen: slingshot:0.12.2" level="project" />
|
||||||
|
<orderEntry type="library" name="Leiningen: tigris:0.1.1" level="project" />
|
||||||
|
</component>
|
||||||
|
</module>
|
@ -1,5 +1,5 @@
|
|||||||
(ns rsspaper.config
|
(ns rsspaper.config
|
||||||
(:require
|
(:require
|
||||||
[clj-yaml.core :as yaml]))
|
[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
|
(ns rsspaper.core
|
||||||
(:require
|
(:require
|
||||||
[rsspaper.config :refer [config]]
|
[rsspaper.feeds :refer [get-feeds]]
|
||||||
[ring.middleware.defaults :refer [site-defaults wrap-defaults]]
|
[rsspaper.html :refer [make-html]]) (:gen-class))
|
||||||
[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 %) %))))
|
|
||||||
|
|
||||||
(defn -main [& args]
|
(defn -main [& args]
|
||||||
;; Main
|
;; Main
|
||||||
;; Welcome
|
(prn "Reading feeds... Please be patient.")
|
||||||
(prn (str "Open " (config :domain) ":" (config :port)))
|
(make-html (get-feeds))
|
||||||
;; Run web server
|
(prn "Generated \uD83D\uDCF0 in 'dist/index.html'!"))
|
||||||
(run-jetty wrapped-handler {:port (config :port)}))
|
|
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" {}))
|
|
Loading…
x
Reference in New Issue
Block a user