Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add about section #86

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions profiles/dev/user.clj
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,11 @@
[:message-page :cache-time]
(constantly new-cache-time))
true)

(comment
(go)
(reset)
(reset-all)
(use 'clojurians-log.repl)
(load-demo-data! "../clojurians-log-demo-data")
#_:end)
Comment on lines +40 to +46
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Useful snippets for repl-driven development in Sapcemacs. Question: is there a better place to put this? Or do you bind those to some keystrokes in your IDE? Or in general: which keystrokes do you bind to which commands for repl-driven development?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's fine to have it in a comment here. Alternatively you can put it in a file in the repl/ directory.

I also use Spacemacs, with standard bindings like , e e to eval. I also have some leader key bindings myself.

(defun plexus-clojure-extras/cider-pprint-register (register)
  (interactive (list (register-read-with-preview "Eval register: ")))
  (cider--pprint-eval-form (get-register register)))

(dolist (m '(clojure-mode
               clojurec-mode
               clojurescript-mode
               clojurex-mode
               cider-repl-mode
               cider-clojure-interaction-mode))

    (spacemacs/set-leader-keys-for-major-mode m
      "ep" 'cider-pprint-eval-last-sexp
      "eP" 'cider-pprint-eval-last-sexp-to-comment
      "en" 'cider-eval-ns-form
      "er" 'cider-eval-last-sexp-and-replace
      ","  'plexus-clojure-extras/cider-pprint-register
      "lp" 'sesman-link-with-project
      "lb" 'sesman-link-with-buffer
      "lb" 'sesman-link-with-directory
      "ll" 'sesman-link-with-least-specific
      "ss" (if (eq m 'cider-repl-mode)
               'cider-switch-to-last-clojure-buffer
             'cider-switch-to-repl-buffer)
      "'"  'cider-jack-in-clj
      "\"" 'cider-jack-in-cljs
      "\&" 'cider-jack-in-clj&cljs
      "sq" 'cider-quit
      ))

I use , e p a lot. , e P will insert the result in the buffer in a comment, or you can use SPC u , e e to insert directly.

The bottom ones are to undo the recent keybinding changes in the spacemacs clojure layer.

I also have a special , , <register> binding, so I can put snippets in a register and eval them from anywhere. I don't use it a lot, but sometimes it's very handy.

5 changes: 4 additions & 1 deletion src/clojurians_log/db/queries.clj
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,10 @@

(defn channel-days [db chan-name]
(when-let [indexes @!indexes]
(let [{:keys [chan-day-cnt chan-name->id] :as index} @!indexes]
(let [{:keys [chan-day-cnt chan-name->id] :as index}
(if (seq @!indexes)
@!indexes
{:chan-day-cnt {} :chan-name->id {}})]
Comment on lines +85 to +88
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a hack to solve #61. I'd like to find a clean solution. But the suggested (defonce !indexes (atom {:chan-name->id {} ,,,})) does not work, because after calling (go) at the repl, !indexes is reset to empty map {}. Question: which code is actually called when I type (go) at the repl?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

!indexes is already dereferenced on line 84, so instead of @!indexes just use indexes. I should have done that too on line 85. But this doesn't seem like the right solution, the when-let means that this function may return nil if there are no indexes, so the consumer should be able to work with that.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(go) calls (user/go), which calls (reloaded.repl/go). This initializes the system (see user.clj:15) and starts it, so it starts all the components you see clojurians-log.application/prod-system + garden-watcher.

I would approach this differently, and make sure the indexes are nil when they are not built yet, or are built but there is no data. so change clojurians-log.db.queries so that (def !indexes (atom nil)), and on line 26 in the reduce replace the empty map with nil. This is fine because (assoc-in nil [...] ...) will return a map. This means channel-days will just work, either it returns a value, or nil. Then it's a matter of making sure the views work with that. Having a quick look I think we need an (if channel-days ...) branch in log-page-header

(when index
(some->> chan-name
chan-name->id
Expand Down
20 changes: 20 additions & 0 deletions src/clojurians_log/routes.clj
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,29 @@
views/channel-page
response/render)))

(defn about-route [request]
(-> request
context
views/about
response/render))

(defn sitemap-route [{:keys [endpoint] :as request}]
(let [db (db-from-endpoint endpoint)]
(-> request
context
(assoc :data/channel-day-tuples
(for [{:channel/keys [name] :as channel} (queries/channel-list db)]
[channel (queries/channel-days db name)]))
views/sitemap
response/render)))

(def routes
[["/" {:name :clojurians-log.routes/index
:get index-route}]
["/x/x/x/about" {:name :clojurians-log.routes/about
:get about-route}]
["/x/x/x/sitemap" {:name :clojurians-log.routes/sitemap
:get sitemap-route}]
["/x/x/x/healthcheck" {:name :clojurians-log.routes/healthcheck,
:get healthcheck-route}]
["/{channel}" {:name :clojurians-log.routes/channel,
Expand Down
62 changes: 55 additions & 7 deletions src/clojurians_log/views.clj
Original file line number Diff line number Diff line change
Expand Up @@ -220,14 +220,22 @@
[:body
[:div.main
(fork-me-badge)
[:p
[:a {:href (path-for context :clojurians-log.routes/about)}
"About Clojurians Slack Log"]]
[:p
[:a {:href (path-for context :clojurians-log.routes/sitemap)}
"Sitemap"]]
[:h1 "Channels"]
[:ul
(for [{:channel/keys [name]} channels]
[:li
[:a {:href (path-for context
:clojurians-log.routes/channel
{:channel name})}
"# " name]])]]]])
(if (seq channels)
[:ul
(for [{:channel/keys [name]} channels]
[:li
[:a {:href (path-for context
:clojurians-log.routes/channel
{:channel name})}
"# " name]])]
[:p "no data loaded"])]]])
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix for #61. Question: is there a more suitable text than "no data loaded", especially for the production environment?


(defn log-page [context]
(assoc context :response/html (log-page-html context)))
Expand All @@ -237,3 +245,43 @@

(defn channel-list-page [context]
(assoc context :response/html (channel-list-page-html context)))

(defn- about-html [context]
[:html
(page-head context)
[:body
[:div.main
(fork-me-badge)
[:h1 "About Clojurians Slack Log"]
[:p "One of the main on-line hangouts for Clojure people is the "
[:a {:href "http://clojurians.net"} "Clojurians Slack community"]
". Unfortunately it suffers from its popularity. Slack will only retain the last 10,000 messages of history, that is less than two weeks of logs. A lot of valuable information is in that chat history. The Clojureverse team has decided to set up this service so that the logs aren’t lost in time."
[:p "If some channel is not logging, it's probably because @logbot isn't receiving its messages. Feel free to invite @logbot to a channel to start logging"]
[:p "The source code is in "
[:a {:href "https://github.com/clojureverse/clojurians-log-app"}
"this"] " github repo, you are welcome to contribute."]]
[:p "The hosting of Clojurians Slack Log is kindly donated by " [:a {:href "https://www.exoscale.com"} "Exoscale."]]]]])

(defn about [context]
(assoc context :response/html (about-html context)))

(defn- sitemap-html [{:data/keys [channel-day-tuples] :as context}]
[:html
(page-head context)
[:body
[:div.main
(fork-me-badge)
[:h1 "Sitemap"]
(if (seq channel-day-tuples)
[:ul
(for [[{:channel/keys [name]} channel-days] channel-day-tuples]
(for [[day cnt] channel-days]
[:li [:a {:href (path-for context
:clojurians-log.routes/channel-date
{:channel name
:date day})}
"# " name " " day " (" cnt ")"]]))]
Comment on lines +276 to +283
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Attempt to solve #50

[:p "no data loaded"])]]])

(defn sitemap [context]
(assoc context :response/html (sitemap-html context)))