Added sitemap.
continuous-integration/drone/push Build is failing
Details
continuous-integration/drone/push Build is failing
Details
This commit is contained in:
parent
9d48364cee
commit
23e6aa60b2
|
@ -30,9 +30,11 @@
|
|||
[sci.configs.reagent.reagent :as sci-reagent]
|
||||
[sci.configs.tonsky.datascript :as sci-datascript]
|
||||
[sci.core :as sci]
|
||||
[clojure-demo.routes :refer [site-data routes]]
|
||||
[spec-tools.data-spec :as ds]
|
||||
[clojure-demo.sitemap :as sm #_#_:refer [spit-pwa-sitemap]]
|
||||
[tick.core :as t])
|
||||
(:require-macros [clojure-demo.sitemap :refer [spit-pwa-sitemap]]))
|
||||
#_(:require-macros [clojure-demo.sitemap :as sm #_#_:refer [spit-pwa-sitemap]]))
|
||||
|
||||
(def languages
|
||||
{"clojure" {:mode "clojure"}
|
||||
|
@ -144,6 +146,7 @@
|
|||
children
|
||||
;(into [:<>] children)
|
||||
))})))
|
||||
|
||||
(defn code-editor
|
||||
[{:keys [exports class results]} content]
|
||||
(let [language class
|
||||
|
@ -249,103 +252,6 @@
|
|||
:HEADER6 (fn [v _] [:li.list-decimal.ml-30 [:a.hover:decoration-blue-400 {:href (str "#" (slugify v))}
|
||||
[:span.text-xs.fw6.f5-ns.lh-title.mt0.mb2 v]]])}))
|
||||
|
||||
;; put constant data here
|
||||
(def site-data
|
||||
{:homepage {:intro "Clojure tutorials examples and exploration"}
|
||||
:dslpage {:intro "A domain-specific language (DSL) is a language designed to be used for a specific task or domain, clojure has a rich set of DSL some popular DSL's are listed on this page with example's on usage. "}
|
||||
:lorem "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum."
|
||||
:pages {:dialects {:title "Dialects & Interop"
|
||||
:intro "Clojure has the ability to run on multiple technology stacks, this allows code reuse and consistency regardless of which eco system you want to make use of."
|
||||
:key ::dialects
|
||||
:demos [{:title "Clojure"
|
||||
:description "The original language running on the jvm with access to the java eco system"
|
||||
:icon-image "https://clojure.org/images/clojure-logo-120b.png"
|
||||
:page "clojure-info"}
|
||||
{:title "Clojurescript"
|
||||
:description "Clojure running in the browser or on top of node, with access to the js eco system."
|
||||
:icon-image "https://clojurescript.org/images/cljs-logo-60b.png"
|
||||
:page "clojurescript-info"}
|
||||
{:title "ClojureCLR"
|
||||
:description "Clojure running on microsofts CLR with access to .net ecosystem"
|
||||
:icon-image "https://clojure.org/images/clojure-logo-120b.png"
|
||||
|
||||
:page "clojureclr-info"}
|
||||
{:title "ClojureDart"
|
||||
:description "Clojure for dart, use clojure to build apps using flutter"
|
||||
:page "clojuredart-info"}]}
|
||||
:dsl {:title "DSL's"
|
||||
:key ::dsl
|
||||
:intro "A domain-specific language (DSL) is a language designed to be used for a specific task or domain, clojure has a rich set of DSL some popular DSL's are listed on this page with example's on usage. "
|
||||
:demos [{:title "Hiccup HTML Demo"
|
||||
:page "hiccup-dsl-demo"
|
||||
:description "Hiccup is a DSL for generating HTML it uses data structures over strings to generate html, this makes it far easier to dynamically generate html by using the language constructs to manipulate the tree."
|
||||
; :link (rfe/href ::demo {:page "hiccup-dsl-demo"})
|
||||
:icon-image "https://miro.medium.com/max/1400/1*CEYFj5R57UFyCXts2nsBqA.png"}
|
||||
{:title "Honey SQL Demo"
|
||||
:page "honey-sql-demo"
|
||||
:description "Similar to honey but for SQL allows you to split apart your complex queries into parts and compose them together."
|
||||
; :link (rfe/href ::demo {:page "honey-dsl-demo"})
|
||||
:icon-image "https://miro.medium.com/max/1400/1*CEYFj5R57UFyCXts2nsBqA.png"}
|
||||
{:title "Datalog Demo"
|
||||
:page "datalog-demo"
|
||||
:description "Datalog is a popular DSL with in the clojure for querying deductive database system's"
|
||||
; :link (rfe/href ::demo {:page "datalog-demo"})
|
||||
:icon-image "https://raw.githubusercontent.com/tonsky/datascript/master/extras/logo.svg"}]}
|
||||
:devops {:title "Deployment & testing"
|
||||
:intro "Running, Testing and deploying your software in a CI pipeline"
|
||||
:key ::devops
|
||||
:demos [{:title "CI Demo"
|
||||
:description "Clojure in a CI pipeline, building artifacts running tests & deploying"
|
||||
:page "ci-demo"
|
||||
;;:link (rfe/href ::demo {:page "ci-demo"})
|
||||
:icon-image "https://avatars.githubusercontent.com/u/2181346?s=200&v=4"}]}
|
||||
:examples {:title "Examples"
|
||||
:intro "Some example applications"
|
||||
:key ::examples
|
||||
:demos [{:title "Maps"
|
||||
:description "Some quick examples using frontend map api's like google maps."
|
||||
:page "example-maps"
|
||||
:icon-image "https://avatars.githubusercontent.com/u/2181346?s=200&v=4"}
|
||||
{:title "XML sitemap"
|
||||
:description "Using data.xml to generate a sitemap"
|
||||
:page "example-xml-sitemap"
|
||||
:icon-image "https://avatars.githubusercontent.com/u/2181346?s=200&v=4"}]}
|
||||
:terminology {:title "Terminology"
|
||||
:intro ""
|
||||
:key ::terminology}}
|
||||
:demos
|
||||
{:hiccup-dsl-demo
|
||||
{:file "documents/hiccup-dsl-demo.org" :git-link "https://github.com/atomjuice/dsl-demo"}
|
||||
:datalog-demo
|
||||
{:file "documents/datalog-demo.org" :git-link "https://github.com/atomjuice/dsl-demo"}
|
||||
:honey-sql-demo
|
||||
{:file "documents/honey-sql-demo.org" :git-link "https://github.com/atomjuice/dsl-demo"}
|
||||
:reagent-demo
|
||||
{:file "documents/reagent-reitit.org" :git-link "https://github.com/atomjuice/dsl-demo"}
|
||||
:clojure-basics
|
||||
{:file "documents/clojure-basics.org" :git-link "https://github.com/atomjuice/dsl-demo"}
|
||||
:ci-demo
|
||||
{:file "documents/ci-demo.org" :git-link "https://github.com/atomjuice/dsl-demo"}
|
||||
:example-maps
|
||||
{:file "documents/examples-maps.org" :git-link ""}
|
||||
:example-xml-sitemap
|
||||
{:file "documents/examples-xml-sitemap.org" :git-link "https://github.com/atomjuice/dsl-demo"}
|
||||
:containers
|
||||
{:file "documents/containers.org" :git-link "https://github.com/atomjuice/containers"}
|
||||
:about
|
||||
{:file "documents/about.org" :git-link "https://github.com/atomjuice/containers"}}})
|
||||
|
||||
|
||||
(defn get-pages
|
||||
"Get pages from site-data map"
|
||||
[]
|
||||
(->> site-data
|
||||
:pages
|
||||
(map second)
|
||||
(map :demos)
|
||||
(map (fn cat [c] (map (fn build-url [page] (str "page/" (:page page))) c)))
|
||||
flatten))
|
||||
|
||||
|
||||
;; form one component to render an article
|
||||
(defn article [{:keys [title description tagline]}]
|
||||
|
@ -432,32 +338,30 @@
|
|||
:articles
|
||||
[{:title "Clojure Basics"
|
||||
:description "Getting started with clojure syntax datatype's sequences conditions"
|
||||
:link (rfe/href ::page {:page "clojure-basics"})
|
||||
:link (rfe/href :page {:page "clojure-basics"})
|
||||
:img-src "https://clojure.org/images/clojure-logo-120b.png"}
|
||||
{:title "Reagent Demo"
|
||||
:description "React application using reagent"
|
||||
:link (rfe/href ::page {:page "reagent-demo"})
|
||||
:link (rfe/href :page {:page "reagent-demo"})
|
||||
:img-src "https://raw.githubusercontent.com/reagent-project/reagent/master/logo/logo-text.png"}]}]])
|
||||
|
||||
(defn grouped-page [route]
|
||||
(let [group (keyword (name (:name (:data route))))]
|
||||
(swap! site-state dissoc :notification)
|
||||
(fn [route]
|
||||
[:<>
|
||||
[articles
|
||||
[:<> [articles
|
||||
{:title (-> site-data :pages group :title)
|
||||
:body (-> site-data :pages group :intro)
|
||||
:articles
|
||||
(mapv (fn fmt-map [demo]
|
||||
{:title (:title demo)
|
||||
:description (:description demo)
|
||||
:link (rfe/href ::page {:page (:page demo)})
|
||||
:link (rfe/href :page {:page (:page demo)})
|
||||
:img-src (:icon-image demo)})
|
||||
(-> site-data :pages group :demos))}]])))
|
||||
(-> site-data :pages group :demos))}]]))
|
||||
|
||||
(defn default-page [route]
|
||||
(let [demo-key (keyword (-> route :parameters :path :page))
|
||||
content (reagent/atom {})]
|
||||
(prn demo-key)
|
||||
(GET (str "/" (-> site-data :demos demo-key :file))
|
||||
{:response-format (raw-response-format)
|
||||
:handler (fn [response]
|
||||
|
@ -474,9 +378,11 @@
|
|||
[:<>]))))
|
||||
|
||||
(defn default-page-header [route]
|
||||
(let [demo-key (keyword (-> route :parameters :path :page))
|
||||
(let [demo-key (keyword (-> route :parameters :path :page name))
|
||||
org-file (-> site-data :demos demo-key :file)
|
||||
content (reagent/atom {})]
|
||||
(GET (str "/" (-> site-data :demos demo-key :file))
|
||||
(when org-file
|
||||
(GET (str "/" org-file)
|
||||
{:response-format (raw-response-format)
|
||||
:handler (fn [response]
|
||||
;;(prn (org->replacements theme (parse response) ))
|
||||
|
@ -484,7 +390,7 @@
|
|||
(->> response
|
||||
parse
|
||||
org->split2
|
||||
(reset! content)))})
|
||||
(reset! content)))}))
|
||||
(fn [route]
|
||||
(if @content
|
||||
[:main
|
||||
|
@ -504,7 +410,7 @@
|
|||
"Download Code"]
|
||||
[:div
|
||||
(into [:div] (org->replacements theme (:body @content)))]]
|
||||
[:<>]))))
|
||||
[:<> "Sorry page not found"]))))
|
||||
|
||||
;; form one render about page component
|
||||
(defn about-page []
|
||||
|
@ -517,57 +423,38 @@
|
|||
:description (-> site-data :lorem)
|
||||
:tagline "https://tachyons.io/components/"}]]])
|
||||
|
||||
;; define our page routes passed into reitit later on
|
||||
(def routes
|
||||
[["/"
|
||||
{:name ::frontpage
|
||||
:view home-page}]
|
||||
|
||||
["/page/{page}"
|
||||
{:name ::page
|
||||
:sitemap {:vec get-pages}
|
||||
:view default-page-header
|
||||
:parameters {:path {:page string?}
|
||||
:query {(ds/opt :foo) keyword?}}}]
|
||||
|
||||
["/terminology/"
|
||||
{:name ::terminology
|
||||
:view grouped-page}]
|
||||
|
||||
["/dialects/"
|
||||
{:name ::dialects
|
||||
:view grouped-page}]
|
||||
|
||||
["/examples/"
|
||||
{:name ::examples
|
||||
:view grouped-page}]
|
||||
|
||||
["/devops/"
|
||||
{:name ::devops
|
||||
:view grouped-page}]
|
||||
|
||||
["/dsl/"
|
||||
{:name ::dsl
|
||||
:view grouped-page}]
|
||||
|
||||
["/about/"
|
||||
{:name ::about
|
||||
:view about-page}]])
|
||||
(defn render-view
|
||||
"We lookup the view render, this keeps our routes as pure data"
|
||||
[view]
|
||||
(case view
|
||||
:homepage home-page
|
||||
:grouped-page grouped-page
|
||||
:default-page-header default-page-header
|
||||
:about-page about-page
|
||||
grouped-page))
|
||||
|
||||
;; top level component contains nav and adds in the select page into a containing element
|
||||
;; we are adding in a style sheet but this will often be done in index.html
|
||||
(defn current-page []
|
||||
(let [route (reagent/cursor site-state [:current-route])]
|
||||
(swap! site-state dissoc :notification)
|
||||
(fn []
|
||||
[:div
|
||||
[notification]
|
||||
[navbar (concat
|
||||
[{:href (rfe/href ::frontpage) :title "title here" :text "home" :key "homepage"}]
|
||||
(mapv (fn build-nav [[key page]] {:href (rfe/href (:key page)) :text (:title page)}) (-> site-data :pages))
|
||||
[;;{:href (rfe/href ::dsl) :text "DSL's" :key "dsl"}
|
||||
{:title "Domain Specific Languages" :href (rfe/href ::about) :text "About" :key "about"}
|
||||
[{:href (rfe/href :frontpage) :title "title here" :text "home" :key "homepage"}]
|
||||
(mapv (fn build-nav [[_ page]]
|
||||
{:href (rfe/href (:key page))
|
||||
:text (:title page)})
|
||||
(-> site-data :pages))
|
||||
[{:title "About page" :href (rfe/href :about) :text "About" :key "about"}
|
||||
#_{:href (rfe/href ::i-do-not-exist) :text "missing"}])]
|
||||
[:main.m-auto {:class "w-3/5"}
|
||||
(when-let [view (-> @site-state :current-route :data :view)] [view (-> @site-state :current-route)])]
|
||||
[footer]])
|
||||
(when-let [view (-> @route :data :view render-view)]
|
||||
[:div
|
||||
[view @route]])]
|
||||
[footer]])))
|
||||
|
||||
;; This simply calls reagent render and puts the result in a div with the id of app
|
||||
;; you can create your own index.html or figwheel provides one with the app id which will replace the default data
|
||||
|
@ -602,22 +489,22 @@
|
|||
result))))})
|
||||
(render-site))
|
||||
|
||||
|
||||
;; Generate the sitemap at start, routes are stored as plain data in cljc files
|
||||
;; this means cljs and clj can read and manipulate them
|
||||
(sm/spit-pwa-sitemap
|
||||
"resources/public/sitemap.xml"
|
||||
"https://clojure-demos.digitaloctave.com/")
|
||||
|
||||
|
||||
#_(macroexpand '(sm/spit-pwa-sitemap
|
||||
"resources/public/sitemap.xml"
|
||||
"https://clojure-demos.digitaloctave.com/"
|
||||
routes))
|
||||
|
||||
;; we defonce the startup so that hot reloading does not reinitialize the state of the site
|
||||
(def launch (do (startup!) true))
|
||||
|
||||
(defn build-sitemap-urls []
|
||||
(->> routes
|
||||
(reduce (fn handle-sitemap [result [route route-map]]
|
||||
(if (-> route-map :sitemap :vec)
|
||||
(conj result ((-> route-map :sitemap :vec)))
|
||||
(conj result route)
|
||||
)) [])
|
||||
flatten))
|
||||
|
||||
(spit-pwa-sitemap
|
||||
"resources/public/sitemap.xml"
|
||||
"https://clojure-demos.digitaloctave.com/"
|
||||
(build-sitemap-urls))
|
||||
|
||||
(comment
|
||||
@site-state
|
||||
|
|
|
@ -0,0 +1,137 @@
|
|||
(ns clojure-demo.routes
|
||||
(:require [spec-tools.data-spec :as ds]))
|
||||
|
||||
|
||||
;; put constant data here
|
||||
(def site-data
|
||||
{:homepage {:intro "Clojure tutorials examples and exploration"}
|
||||
:dslpage {:intro "A domain-specific language (DSL) is a language designed to be used for a specific task or domain, clojure has a rich set of DSL some popular DSL's are listed on this page with example's on usage. "}
|
||||
:lorem "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum."
|
||||
:pages {:dialects {:title "Dialects & Interop"
|
||||
:intro "Clojure has the ability to run on multiple technology stacks, this allows code reuse and consistency regardless of which eco system you want to make use of."
|
||||
:key :dialects
|
||||
:demos [{:title "Clojure"
|
||||
:description "The original language running on the jvm with access to the java eco system"
|
||||
:icon-image "https://clojure.org/images/clojure-logo-120b.png"
|
||||
:page "clojure-basics"}
|
||||
{:title "Clojurescript"
|
||||
:description "Clojure running in the browser or on top of node, with access to the js eco system."
|
||||
:icon-image "https://clojurescript.org/images/cljs-logo-60b.png"
|
||||
:page "clojurescript-basics"}
|
||||
{:title "ClojureCLR"
|
||||
:description "Clojure running on microsofts CLR with access to .net ecosystem"
|
||||
:icon-image "https://clojure.org/images/clojure-logo-120b.png"
|
||||
:page "clojureclr-basics"}
|
||||
{:title "ClojureDart"
|
||||
:description "Clojure for dart, use clojure to build apps using flutter"
|
||||
:page "clojuredart-info"}]}
|
||||
:dsl {:title "DSL's"
|
||||
:key :dsl
|
||||
:intro "A domain-specific language (DSL) is a language designed to be used for a specific task or domain, clojure has a rich set of DSL some popular DSL's are listed on this page with example's on usage. "
|
||||
:demos [{:title "Hiccup HTML Demo"
|
||||
:page "hiccup-dsl-demo"
|
||||
:description "Hiccup is a DSL for generating HTML it uses data structures over strings to generate html, this makes it far easier to dynamically generate html by using the language constructs to manipulate the tree."
|
||||
; :link (rfe/href ::demo {:page "hiccup-dsl-demo"})
|
||||
:icon-image "https://miro.medium.com/max/1400/1*CEYFj5R57UFyCXts2nsBqA.png"}
|
||||
{:title "Honey SQL Demo"
|
||||
:page "honey-sql-demo"
|
||||
:description "Similar to honey but for SQL allows you to split apart your complex queries into parts and compose them together."
|
||||
; :link (rfe/href ::demo {:page "honey-dsl-demo"})
|
||||
:icon-image "https://miro.medium.com/max/1400/1*CEYFj5R57UFyCXts2nsBqA.png"}
|
||||
{:title "Datalog Demo"
|
||||
:page "datalog-demo"
|
||||
:description "Datalog is a popular DSL with in the clojure for querying deductive database system's"
|
||||
; :link (rfe/href ::demo {:page "datalog-demo"})
|
||||
:icon-image "https://raw.githubusercontent.com/tonsky/datascript/master/extras/logo.svg"}]}
|
||||
:devops {:title "Deployment & testing"
|
||||
:intro "Running, Testing and deploying your software in a CI pipeline"
|
||||
:key :devops
|
||||
:demos [{:title "CI Demo"
|
||||
:description "Clojure in a CI pipeline, building artifacts running tests & deploying"
|
||||
:page "ci-demo"
|
||||
;;:link (rfe/href ::demo {:page "ci-demo"})
|
||||
:icon-image "https://avatars.githubusercontent.com/u/2181346?s=200&v=4"}]}
|
||||
:examples {:title "Examples"
|
||||
:intro "Some example applications"
|
||||
:key :examples
|
||||
:demos [{:title "Maps"
|
||||
:description "Some quick examples using frontend map api's like google maps."
|
||||
:page "example-maps"
|
||||
:icon-image "https://avatars.githubusercontent.com/u/2181346?s=200&v=4"}
|
||||
{:title "XML sitemap"
|
||||
:description "Using data.xml to generate a sitemap"
|
||||
:page "example-xml-sitemap"
|
||||
:icon-image "https://avatars.githubusercontent.com/u/2181346?s=200&v=4"}]}
|
||||
:terminology {:title "Terminology"
|
||||
:intro ""
|
||||
:key :terminology}}
|
||||
:demos
|
||||
{:hiccup-dsl-demo
|
||||
{:file "documents/hiccup-dsl-demo.org" :git-link "https://github.com/atomjuice/dsl-demo"}
|
||||
:datalog-demo
|
||||
{:file "documents/datalog-demo.org" :git-link "https://github.com/atomjuice/dsl-demo"}
|
||||
:honey-sql-demo
|
||||
{:file "documents/honey-sql-demo.org" :git-link "https://github.com/atomjuice/dsl-demo"}
|
||||
:reagent-demo
|
||||
{:file "documents/reagent-reitit.org" :git-link "https://github.com/atomjuice/dsl-demo"}
|
||||
:clojure-basics
|
||||
{:file "documents/clojure-basics.org" :git-link "https://github.com/atomjuice/dsl-demo"}
|
||||
:ci-demo
|
||||
{:file "documents/ci-demo.org" :git-link "https://github.com/atomjuice/dsl-demo"}
|
||||
:example-maps
|
||||
{:file "documents/examples-maps.org" :git-link ""}
|
||||
:example-xml-sitemap
|
||||
{:file "documents/examples-xml-sitemap.org" :git-link "https://github.com/atomjuice/dsl-demo"}
|
||||
:containers
|
||||
{:file "documents/containers.org" :git-link "https://github.com/atomjuice/containers"}
|
||||
:about
|
||||
{:file "documents/about.org" :git-link "https://github.com/atomjuice/containers"}}})
|
||||
|
||||
|
||||
(defn get-pages
|
||||
"Get pages from site-data map"
|
||||
[]
|
||||
(->> site-data
|
||||
:pages
|
||||
(map second)
|
||||
(map :demos)
|
||||
(map (fn cat [c] (map (fn build-url [page] (str "page/" (:page page))) c)))
|
||||
flatten))
|
||||
|
||||
|
||||
;; define our page routes passed into reitit later on
|
||||
(def routes
|
||||
[["/"
|
||||
{:name :frontpage
|
||||
:view :homepage}]
|
||||
|
||||
["/page/{page}"
|
||||
{:name :page
|
||||
:sitemap {:vec get-pages}
|
||||
:view :default-page-header
|
||||
:parameters {:path {:page string?}
|
||||
:query {(ds/opt :foo) keyword?}}}]
|
||||
|
||||
["/terminology/"
|
||||
{:name :terminology
|
||||
:view :grouped-page}]
|
||||
|
||||
["/dialects/"
|
||||
{:name :dialects
|
||||
:view :grouped-page}]
|
||||
|
||||
["/examples/"
|
||||
{:name :examples
|
||||
:view :grouped-page}]
|
||||
|
||||
["/devops/"
|
||||
{:name :devops
|
||||
:view :grouped-page}]
|
||||
|
||||
["/dsl/"
|
||||
{:name :dsl
|
||||
:view :grouped-page}]
|
||||
|
||||
["/about/"
|
||||
{:name :about
|
||||
:view :about-page}]])
|
|
@ -0,0 +1,70 @@
|
|||
(ns clojure-demo.sitemap
|
||||
(:require [clojure.data.xml :as xml]
|
||||
[clojure-demo.routes :refer [routes]]
|
||||
|
||||
))
|
||||
|
||||
|
||||
(defn pwa-sitemap [domain routes]
|
||||
(xml/emit-str
|
||||
{:tag :urlset
|
||||
:attrs {:xmlns "http://www.sitemaps.org/schemas/sitemap/0.9"}
|
||||
:content
|
||||
(mapv (fn [r]
|
||||
{:tag :url
|
||||
:attrs {}
|
||||
:content [{:tag :loc :attrs {} :content [(str domain r)]}]}
|
||||
) routes)}))
|
||||
|
||||
(defn build-sitemap-urls [routes]
|
||||
(->> routes
|
||||
(reduce (fn handle-sitemap [result [route route-map]]
|
||||
(if (-> route-map :sitemap :vec)
|
||||
(conj result ((-> route-map :sitemap :vec)))
|
||||
(conj result route)
|
||||
)) [])
|
||||
flatten))
|
||||
|
||||
|
||||
|
||||
(defn spit-pwa-sitemap2
|
||||
"Generate the sitemap and outut to the provided path"
|
||||
[path domain urls]
|
||||
`(clojure.core/spit ~path (pwa-sitemap ~domain ~urls)))
|
||||
|
||||
(defmacro spit-pwa-sitemap-test
|
||||
"Generate the sitemap and outut to the provided path"
|
||||
[path domain urls]
|
||||
(clojure.core/spit
|
||||
path
|
||||
(pwa-sitemap
|
||||
domain
|
||||
urls)))
|
||||
|
||||
(defmacro spit-pwa-sitemap
|
||||
"Generate the sitemap and outut to the provided path"
|
||||
[path domain ]
|
||||
(clojure.core/spit
|
||||
path
|
||||
(pwa-sitemap
|
||||
domain
|
||||
(build-sitemap-urls routes))))
|
||||
|
||||
(comment
|
||||
(defn test-urls []
|
||||
["a" "b" "c"])
|
||||
|
||||
(spit-pwa-sitemap
|
||||
"resources/public/sitemap.xml"
|
||||
"https://clojure-demos.digitaloctave.com/"
|
||||
["1" "2"])
|
||||
|
||||
(spit-pwa-sitemap
|
||||
"resources/public/sitemap.xml"
|
||||
"https://clojure-demos.digitaloctave.com/"
|
||||
(test-urls))
|
||||
|
||||
(macroexpand '(spit-pwa-sitemap
|
||||
"resources/public/sitemap.xml"
|
||||
"https://clojure-demos.digitaloctave.com/"
|
||||
(test-urls))))
|
|
@ -1,29 +0,0 @@
|
|||
(ns clojure-demo.sitemap
|
||||
(:require [clojure.data.xml :as xml]))
|
||||
|
||||
(defn pwa-sitemap [domain routes]
|
||||
#?(:cljs (xml/emit-str
|
||||
{:tag :urlset
|
||||
:attrs {#_#_:xmlns "http://www.sitemaps.org/schemas/sitemap/0.9"}
|
||||
:content
|
||||
(mapv (fn [r]
|
||||
{:tag :url
|
||||
:attrs {}
|
||||
:content [{:tag :loc :attrs {} :content [(str domain r)]}]}
|
||||
) routes)})
|
||||
:clj (xml/indent-str
|
||||
{:tag :urlset
|
||||
:attrs {:xmlns "http://www.sitemaps.org/schemas/sitemap/0.9"}
|
||||
:content
|
||||
(mapv (fn [r]
|
||||
{:tag :url
|
||||
:attrs {}
|
||||
:content [{:tag :loc :attrs {} :content [(str domain r)]}]}
|
||||
) routes)})))
|
||||
|
||||
(defmacro spit-pwa-sitemap
|
||||
"Generate the sitemap and outut to the provided path"
|
||||
{:arglists '([body] [options & body]), :style/indent 0}
|
||||
[path domain urls]
|
||||
#?(:clj (spit path (pwa-sitemap domain urls))
|
||||
:cljs nil))
|
|
@ -0,0 +1,13 @@
|
|||
(ns clojure-demo.sitemap
|
||||
#_(:require [clojure.data.xml :as xml])
|
||||
(:require-macros [clojure-demo.sitemap]))
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#_(defmacro spit-pwa-sitemap
|
||||
"Generate the sitemap and outut to the provided path"
|
||||
[path domain urls]
|
||||
`(io/spit ~path (pwa-sitemap ~domain ~urls)))
|
Loading…
Reference in New Issue