Skip to content

Commit

Permalink
sorting recent changes and links in rss feeds
Browse files Browse the repository at this point in the history
  • Loading branch information
interstar committed Oct 1, 2020
1 parent 26716d7 commit 51d3010
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 26 deletions.
24 changes: 12 additions & 12 deletions src/clj_ts/card_server.clj
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@


(defrecord CardServerRecord
[wiki-name site-root port-no start-page facts-db page-store page-exporter]
[wiki-name site-url port-no start-page facts-db page-store page-exporter]
ldb/IFactsDb
(raw-db [cs] (dnn cs raw-db))
(all-pages [cs] (dnn cs all-pages) )
Expand Down Expand Up @@ -119,13 +119,12 @@


(defn update-pagedir! [new-pd new-ed]
(let [
new-ps (pagestore/make-page-store
new-pd
new-ed)]
(let [new-ps
(pagestore/make-page-store
new-pd
new-ed)]
(set-page-store! new-ps)
(regenerate-db!)
))
(regenerate-db!)))

(defn page-exists? [page-name]
(-> (.page-store (server-state))
Expand Down Expand Up @@ -201,7 +200,7 @@
i "Orphan Pages" (.orphan-pages db) :orphanpages item1)

:recentchanges
(let [src (pagestore/load-recent-changes ps) ]
(let [src (.read-recentchanges ps) ]
(common/package-card
"recentchanges" :system :markdown src src))

Expand Down Expand Up @@ -359,14 +358,15 @@ Bookmarked " timestamp ",, <" url ">

;; RecentChanges as RSS

(defn rss-recent-changes []
(let [make-link (fn [s]
(defn rss-recent-changes [link-fn]
(let [ps (:page-store (server-state))
make-link (fn [s]
(let [m (re-matches #"\* \[\[(\S+)\]\] (\(.+\))" s)
[pname date] [(second m) (nth m 2)]]
{:title (str pname " changed on " date)
:link (pagestore/page-name->url (server-state) pname)}
:link (link-fn pname)}
))
rc (-> (pagestore/read-page (server-state) "systemrecentchanges")
rc (-> (.read-recentchanges ps)
string/split-lines
(#(map make-link %)))]
(rss/channel-xml {:title "RecentChanges"
Expand Down
19 changes: 12 additions & 7 deletions src/clj_ts/pagestore.clj
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,13 @@
(pages-as-new-directory-stream [this]
(java.nio.file.Files/newDirectoryStream page-path "*.md"))

(read-recentchanges [ps]
(.read-system-file ps "recentchanges") )

(write-recentchanges! [ps new-rc]
(.write-system-file! ps "recentchanges" new-rc)
)

)


Expand Down Expand Up @@ -135,18 +142,17 @@
(defn dedouble [s] (string/replace s #"\/\/" "/"))

(defn page-name->url [server-state page-name]
(dedouble (str (-> server-state .site-url) "/view/" page-name))
(dedouble (str (-> server-state :site-url) "/view/" page-name))
)




;; RecentChanges
;; We store recent-changes in a system file called "recentchanges".

(defn update-recent-changes! [ps pagename]
(let [pn "recentchanges"
rcc (.read-system-file ps pn)
(let [
rcc (.read-recentchanges ps)

filter-step (fn [xs] (filter #(not (string/includes? % (str "[[" pagename "]]"))) xs ) )
curlist (-> rcc string/split-lines filter-step )
Expand All @@ -155,12 +161,11 @@
curlist
)]
(println "Updating recentchanges ... adding " pagename)
(.write-system-file! ps pn (string/join "\n" (take 80 newlist)) )
(.write-recentchanges! ps (string/join "\n" (take 80 newlist)) )
))


(defn load-recent-changes [ps]
(.read-system-file ps "recentchanges"))



;; API for writing a file
Expand Down
5 changes: 3 additions & 2 deletions src/clj_ts/server.clj
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@
:default "HelloWorld"
:parse-fn str]

["-l" "--links LINK" "Internal Links"
["-l" "--links LINK" "Export Links"
:default "./"
:parse-fn str]

Expand All @@ -338,7 +338,8 @@
opts (get xs :options)

ps (pagestore/make-page-store (:directory opts) (:export-dir opts))
pe (export/make-page-exporter ps "" (:links opts))]
dx (println (:site opts) (:links opts))
pe (export/make-page-exporter ps (:site-url opts) (:links opts))]

(println "
Welcome to Cardigan Bay
Expand Down
26 changes: 21 additions & 5 deletions src/clj_ts/static_export.clj
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,10 @@
:export-link-pattern export-link-pattern})

(report [ex]
(str "Export Extension :\t" (ep (:export-extension ex)) "
Export Link Pattern :\t" (ep (:export-link-pattern ex))))
(str "Export Extension :\t" (ep export-extension ) "
Export Link Pattern :\t" (ep export-link-pattern) "
Example Exported Link :\t" (.page-name->exported-link ex "ExamplePage")
))

(page-name->export-file-path [ex page-name]
(-> ex .page-store .export-path
Expand All @@ -67,6 +69,8 @@ Export Link Pattern :\t" (ep (:export-link-pattern ex))))
(page-name->exported-link [ex page-id]
(str export-link-pattern page-id export-extension ))

(api-path [ex]
(.resolve (-> ex .page-store .export-path) "api"))

(load-template [ex]
(try
Expand All @@ -92,6 +96,16 @@ USING DEFAULT")
(defn make-page-exporter [page-store export-extension export-link-pattern]
(->PageExporter page-store export-extension export-link-pattern))



(defn export-recentchanges-rss [server-state]
(let [api-path (-> server-state :page-exporter .api-path)
rc-rss (.resolve api-path "rc-rss.xml")
link-fn (fn [p-name]
(str (:site-url server-state) p-name)) ]
(spit (.toString rc-rss) (card-server/rss-recent-changes link-fn))
))

(defn export-page [page-name server-state tpl]
(let [ps (:page-store server-state)
ex (:page-exporter server-state)
Expand Down Expand Up @@ -125,17 +139,19 @@ USING DEFAULT")


(defn export-all-pages [server-state]

(if (= :not-available (.all-pages server-state))
:not-exported
(let [tpl (-> server-state :page-exporter .load-template)
all (.all-pages server-state)]
(doseq [p-name (.all-pages server-state)]
(println "Exporting " p-name)
(export-page p-name server-state tpl)
))))
)
(println "Export recentchanges rss")
(export-recentchanges-rss server-state))))

(defn export-one-page [page-name server-state]
(let [tpl (-> server-state :page-exporter .load-template)]
(export-page page-name server-state tpl))
(export-page page-name server-state tpl)
(export-recentchanges-rss server-state))
)
3 changes: 3 additions & 0 deletions src/clj_ts/types.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,15 @@
(report [ps])
(similar-page-names [ps p-name])
(pages-as-new-directory-stream [ps])
(read-recentchanges [ps])
(write-recentchanges! [ps new-rc] )
)

(defprotocol IPageExporter
(as-map [ex])
(page-name->export-file-path [ex page-name])
(page-name->exported-link [ex page-name])
(load-template [ex])
(api-path [ex])
(report [ex])
)

0 comments on commit 51d3010

Please sign in to comment.