Switch branches/tags
Nothing to show
Find file Copy path
ce34e80 Sep 8, 2018
1 contributor

Users who have contributed to this file

112 lines (92 sloc) 3.99 KB
;; main page for my clojure static website.
;; based on
(ns website-clj.web
"main namespace for building and exporting the website"
(:require [optimus.assets :as assets]
[ :as link]
[optimus.optimizations :as optimizations]
[ :as optimus]
[optimus.strategies :refer [serve-live-assets]]
[ :as io]
[clojure.string :as str]
[stasis.core :as stasis]
[website-clj.export-helpers :as helpers]
[website-clj.process-pages :as process]))
;; define page maps and link maps
(def programming-map
"constant for all links holding programming pages"
(process/html-pages "/programming"
(stasis/slurp-directory "resources/programming" #".*\.(html|css|js)")))
(def programming-metadata
"constant for all programming-metadata"
(process/make-edn-page-map "/programming" programming-map))
(def programming-links
"constant for all programming links"
(process/format-html-links programming-metadata))
(def science-map
"constant for all science pages"
(process/html-pages "/science"
(stasis/slurp-directory "resources/science" #".*\.(html|css|js)")))
(def science-metadata
"constant for all science metadata"
(process/make-edn-page-map "/science" science-map))
(def science-links
"constant for all science links"
(process/format-html-links science-metadata))
(def first-five-links
"first five links to put on home page"
(process/format-html-links (process/merge-maps-sort-take-five science-metadata programming-metadata)))
(def site-map
"Generate site map urls"
(apply str (for [x (keys (merge programming-metadata science-metadata))] (str "" x "/\n" "" x "/\n"))))
;; load all assets
(defn get-assets
"get all static assets from the public directory."
(assets/load-assets "public" [#".*"]))
;; main get pages function for render and export
(defn get-pages
"Gathers all website pages and resources, including sitemap and robots.txt."
{:public (stasis/slurp-directory "resources/public" #".*\.(html|css|js)$")
:landing (let [home-map (process/home-page (stasis/slurp-directory "resources/home" #".*\.(html|css|js)$"))]
(zipmap (keys home-map)
(map #(process/add-links % first-five-links :#recentPosts)
(vals home-map))))
:programming (zipmap (keys programming-map)
(map #(process/add-links % programming-links :#pageListDiv)
(vals programming-map)))
:science (zipmap (keys science-map)
(map #(process/add-links % science-links :#pageListDiv)
(vals science-map)))
:robots (hash-map "/robots.txt" "User-agent: *\nDisallow:\nSITEMAP:")
:sitemap (hash-map "/sitemap.txt" site-map)}))
;; for test rendering
(def app
"renders the website for experimentation"
(stasis/serve-pages get-pages)
;; constants for exporting
(def export-dir "target/")
(def safe-dir "target")
;; main export function, called by lein build-site
(defn export
"main export function for static site. See docs for functions included.
(helpers/save-git safe-dir export-dir)
(let [assets (optimizations/all (get-assets) {})]
(stasis/empty-directory! export-dir)
(optimus.export/save-assets assets export-dir)
(stasis/export-pages (get-pages) export-dir {:optimus-assets assets}))
(helpers/cp-cname export-dir)
(helpers/cp-gitignore export-dir)
(helpers/replace-git safe-dir export-dir))