├── .dockerignore ├── .gitignore ├── Dockerfile ├── LICENSE ├── Procfile ├── README.md ├── _posts ├── post_a.edn ├── post_b.edn └── post_c.edn ├── _tags └── tags.cljs ├── docs ├── css │ └── site.css ├── index.html ├── post_a.html ├── post_b.html └── post_c.html ├── env ├── dev │ ├── bengine │ │ └── app.cljs │ └── user.clj ├── prod │ └── bengine │ │ └── app.cljs └── test │ └── bengine │ └── app.cljs ├── package.json ├── project.clj ├── public ├── css │ └── site.css ├── index.html ├── post_a.html ├── post_b.html └── post_c.html ├── src └── bengine │ ├── config.cljs │ ├── core.cljs │ ├── files.cljs │ ├── specs.cljs │ └── tags.cljs ├── system.properties └── test └── bengine └── core_test.cljs /.dockerignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | npm-debug.log 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | /target 3 | /classes 4 | /checkouts 5 | profiles.clj 6 | pom.xml 7 | pom.xml.asc 8 | *.jar 9 | *.class 10 | /.lein-* 11 | /.nrepl-port 12 | /resources/public/js 13 | /out 14 | /.repl 15 | *.log 16 | /.env 17 | /node_modules 18 | /public/* 19 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM mhart/alpine-node:latest 2 | 3 | MAINTAINER Your Name 4 | 5 | # Create app directory 6 | RUN mkdir -p /bengine 7 | WORKDIR /bengine 8 | 9 | # Install app dependencies 10 | COPY package.json /bengine 11 | RUN npm install pm2 -g 12 | RUN npm install 13 | 14 | # Bundle app source 15 | COPY target/release/bengine.js /bengine/bengine.js 16 | COPY public /bengine/public 17 | 18 | ENV HOST 0.0.0.0 19 | 20 | EXPOSE 3000 21 | CMD [ "pm2-docker", "/bengine/bengine.js" ] 22 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE PUBLIC 2 | LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THE PROGRAM 3 | CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT. 4 | 5 | 1. DEFINITIONS 6 | 7 | "Contribution" means: 8 | 9 | a) in the case of the initial Contributor, the initial code and 10 | documentation distributed under this Agreement, and 11 | 12 | b) in the case of each subsequent Contributor: 13 | 14 | i) changes to the Program, and 15 | 16 | ii) additions to the Program; 17 | 18 | where such changes and/or additions to the Program originate from and are 19 | distributed by that particular Contributor. A Contribution 'originates' from 20 | a Contributor if it was added to the Program by such Contributor itself or 21 | anyone acting on such Contributor's behalf. Contributions do not include 22 | additions to the Program which: (i) are separate modules of software 23 | distributed in conjunction with the Program under their own license 24 | agreement, and (ii) are not derivative works of the Program. 25 | 26 | "Contributor" means any person or entity that distributes the Program. 27 | 28 | "Licensed Patents" mean patent claims licensable by a Contributor which are 29 | necessarily infringed by the use or sale of its Contribution alone or when 30 | combined with the Program. 31 | 32 | "Program" means the Contributions distributed in accordance with this 33 | Agreement. 34 | 35 | "Recipient" means anyone who receives the Program under this Agreement, 36 | including all Contributors. 37 | 38 | 2. GRANT OF RIGHTS 39 | 40 | a) Subject to the terms of this Agreement, each Contributor hereby grants 41 | Recipient a non-exclusive, worldwide, royalty-free copyright license to 42 | reproduce, prepare derivative works of, publicly display, publicly perform, 43 | distribute and sublicense the Contribution of such Contributor, if any, and 44 | such derivative works, in source code and object code form. 45 | 46 | b) Subject to the terms of this Agreement, each Contributor hereby grants 47 | Recipient a non-exclusive, worldwide, royalty-free patent license under 48 | Licensed Patents to make, use, sell, offer to sell, import and otherwise 49 | transfer the Contribution of such Contributor, if any, in source code and 50 | object code form. This patent license shall apply to the combination of the 51 | Contribution and the Program if, at the time the Contribution is added by the 52 | Contributor, such addition of the Contribution causes such combination to be 53 | covered by the Licensed Patents. The patent license shall not apply to any 54 | other combinations which include the Contribution. No hardware per se is 55 | licensed hereunder. 56 | 57 | c) Recipient understands that although each Contributor grants the licenses 58 | to its Contributions set forth herein, no assurances are provided by any 59 | Contributor that the Program does not infringe the patent or other 60 | intellectual property rights of any other entity. Each Contributor disclaims 61 | any liability to Recipient for claims brought by any other entity based on 62 | infringement of intellectual property rights or otherwise. As a condition to 63 | exercising the rights and licenses granted hereunder, each Recipient hereby 64 | assumes sole responsibility to secure any other intellectual property rights 65 | needed, if any. For example, if a third party patent license is required to 66 | allow Recipient to distribute the Program, it is Recipient's responsibility 67 | to acquire that license before distributing the Program. 68 | 69 | d) Each Contributor represents that to its knowledge it has sufficient 70 | copyright rights in its Contribution, if any, to grant the copyright license 71 | set forth in this Agreement. 72 | 73 | 3. REQUIREMENTS 74 | 75 | A Contributor may choose to distribute the Program in object code form under 76 | its own license agreement, provided that: 77 | 78 | a) it complies with the terms and conditions of this Agreement; and 79 | 80 | b) its license agreement: 81 | 82 | i) effectively disclaims on behalf of all Contributors all warranties and 83 | conditions, express and implied, including warranties or conditions of title 84 | and non-infringement, and implied warranties or conditions of merchantability 85 | and fitness for a particular purpose; 86 | 87 | ii) effectively excludes on behalf of all Contributors all liability for 88 | damages, including direct, indirect, special, incidental and consequential 89 | damages, such as lost profits; 90 | 91 | iii) states that any provisions which differ from this Agreement are offered 92 | by that Contributor alone and not by any other party; and 93 | 94 | iv) states that source code for the Program is available from such 95 | Contributor, and informs licensees how to obtain it in a reasonable manner on 96 | or through a medium customarily used for software exchange. 97 | 98 | When the Program is made available in source code form: 99 | 100 | a) it must be made available under this Agreement; and 101 | 102 | b) a copy of this Agreement must be included with each copy of the Program. 103 | 104 | Contributors may not remove or alter any copyright notices contained within 105 | the Program. 106 | 107 | Each Contributor must identify itself as the originator of its Contribution, 108 | if any, in a manner that reasonably allows subsequent Recipients to identify 109 | the originator of the Contribution. 110 | 111 | 4. COMMERCIAL DISTRIBUTION 112 | 113 | Commercial distributors of software may accept certain responsibilities with 114 | respect to end users, business partners and the like. While this license is 115 | intended to facilitate the commercial use of the Program, the Contributor who 116 | includes the Program in a commercial product offering should do so in a 117 | manner which does not create potential liability for other Contributors. 118 | Therefore, if a Contributor includes the Program in a commercial product 119 | offering, such Contributor ("Commercial Contributor") hereby agrees to defend 120 | and indemnify every other Contributor ("Indemnified Contributor") against any 121 | losses, damages and costs (collectively "Losses") arising from claims, 122 | lawsuits and other legal actions brought by a third party against the 123 | Indemnified Contributor to the extent caused by the acts or omissions of such 124 | Commercial Contributor in connection with its distribution of the Program in 125 | a commercial product offering. The obligations in this section do not apply 126 | to any claims or Losses relating to any actual or alleged intellectual 127 | property infringement. In order to qualify, an Indemnified Contributor must: 128 | a) promptly notify the Commercial Contributor in writing of such claim, and 129 | b) allow the Commercial Contributor tocontrol, and cooperate with the 130 | Commercial Contributor in, the defense and any related settlement 131 | negotiations. The Indemnified Contributor may participate in any such claim 132 | at its own expense. 133 | 134 | For example, a Contributor might include the Program in a commercial product 135 | offering, Product X. That Contributor is then a Commercial Contributor. If 136 | that Commercial Contributor then makes performance claims, or offers 137 | warranties related to Product X, those performance claims and warranties are 138 | such Commercial Contributor's responsibility alone. Under this section, the 139 | Commercial Contributor would have to defend claims against the other 140 | Contributors related to those performance claims and warranties, and if a 141 | court requires any other Contributor to pay any damages as a result, the 142 | Commercial Contributor must pay those damages. 143 | 144 | 5. NO WARRANTY 145 | 146 | EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS PROVIDED ON 147 | AN "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER 148 | EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY WARRANTIES OR 149 | CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A 150 | PARTICULAR PURPOSE. Each Recipient is solely responsible for determining the 151 | appropriateness of using and distributing the Program and assumes all risks 152 | associated with its exercise of rights under this Agreement , including but 153 | not limited to the risks and costs of program errors, compliance with 154 | applicable laws, damage to or loss of data, programs or equipment, and 155 | unavailability or interruption of operations. 156 | 157 | 6. DISCLAIMER OF LIABILITY 158 | 159 | EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT NOR ANY 160 | CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT, INCIDENTAL, 161 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING WITHOUT LIMITATION 162 | LOST PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 163 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 164 | ARISING IN ANY WAY OUT OF THE USE OR DISTRIBUTION OF THE PROGRAM OR THE 165 | EXERCISE OF ANY RIGHTS GRANTED HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY 166 | OF SUCH DAMAGES. 167 | 168 | 7. GENERAL 169 | 170 | If any provision of this Agreement is invalid or unenforceable under 171 | applicable law, it shall not affect the validity or enforceability of the 172 | remainder of the terms of this Agreement, and without further action by the 173 | parties hereto, such provision shall be reformed to the minimum extent 174 | necessary to make such provision valid and enforceable. 175 | 176 | If Recipient institutes patent litigation against any entity (including a 177 | cross-claim or counterclaim in a lawsuit) alleging that the Program itself 178 | (excluding combinations of the Program with other software or hardware) 179 | infringes such Recipient's patent(s), then such Recipient's rights granted 180 | under Section 2(b) shall terminate as of the date such litigation is filed. 181 | 182 | All Recipient's rights under this Agreement shall terminate if it fails to 183 | comply with any of the material terms or conditions of this Agreement and 184 | does not cure such failure in a reasonable period of time after becoming 185 | aware of such noncompliance. If all Recipient's rights under this Agreement 186 | terminate, Recipient agrees to cease use and distribution of the Program as 187 | soon as reasonably practicable. However, Recipient's obligations under this 188 | Agreement and any licenses granted by Recipient relating to the Program shall 189 | continue and survive. 190 | 191 | Everyone is permitted to copy and distribute copies of this Agreement, but in 192 | order to avoid inconsistency the Agreement is copyrighted and may only be 193 | modified in the following manner. The Agreement Steward reserves the right to 194 | publish new versions (including revisions) of this Agreement from time to 195 | time. No one other than the Agreement Steward has the right to modify this 196 | Agreement. The Eclipse Foundation is the initial Agreement Steward. The 197 | Eclipse Foundation may assign the responsibility to serve as the Agreement 198 | Steward to a suitable separate entity. Each new version of the Agreement will 199 | be given a distinguishing version number. The Program (including 200 | Contributions) may always be distributed subject to the version of the 201 | Agreement under which it was received. In addition, after a new version of 202 | the Agreement is published, Contributor may elect to distribute the Program 203 | (including its Contributions) under the new version. Except as expressly 204 | stated in Sections 2(a) and 2(b) above, Recipient receives no rights or 205 | licenses to the intellectual property of any Contributor under this 206 | Agreement, whether expressly, by implication, estoppel or otherwise. All 207 | rights in the Program not expressly granted under this Agreement are 208 | reserved. 209 | 210 | This Agreement is governed by the laws of the State of New York and the 211 | intellectual property laws of the United States of America. No party to this 212 | Agreement will bring a legal action under this Agreement more than one year 213 | after the cause of action arose. Each party waives its rights to a jury trial 214 | in any resulting litigation. 215 | -------------------------------------------------------------------------------- /Procfile: -------------------------------------------------------------------------------- 1 | web: node main.js 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Welcome to bengine! 2 | 3 | [Demo](http://escherize.com/bengine/public) 4 | 5 | The data oriented static site generator. 6 | 7 | ## Why bengine? 8 | 9 | This could be the most _simple_ blog framework you can find. 10 | 11 | Static site generators (take some meaty source material (usually text) in, and spit out a carefully crafted website. 12 | 13 | With bengine, you will write easy, simple, and powerful tags for your thoughts to turn them into a killer blog. 14 | 15 | No waiting around with bengine -- It's running on clojurescript on node, so re-renders are _fast_. 16 | 17 | ### Origin story 18 | 19 | I really wanted to use Matthew Butterick's amazing [pollen](http://docs.racket-lang.org/pollen/) to build a blog for myself. But I found nesting radcket's x-expressions too unweidly, and didn't want to learn how to make it work. Based on the advice of a friend, I decided to see if I could clone pollen's key ideas into a clojurescript-on-node based site generator. 20 | 21 | ### Philosophy 22 | 23 | There are not a lot of moving parts here, folks. 24 | 25 | 1. Posts 26 | 27 | Posts look like the [hiccup](http://hiccup.space) style of html. Hiccup is not verbose and stays out of your way so you can think clearly. 28 | 29 | Example: 30 | ``` clojure 31 | [:article 32 | [:h1 "Welcome to Fight Club. ^_^"] 33 | "I hope you have a fantastic time! :)" 34 | "Glad you could join us today."] 35 | ``` 36 | 37 | 2. Tags 38 | 39 | Posts can contain tags (a few are included). You are free to create any tag function you want in `_tags/tags.cljs`, and use it in your posts. 40 | 41 | #### Example 1 42 | 43 | In `_tags/tags.cljs`: 44 | ``` clojure 45 | (defn heading [s] [:h1 s]) 46 | ``` 47 | 48 | In one of your posts in `_posts/any_post_name.edn`: 49 | ``` clojure 50 | (my/heading "Hello") 51 | ``` 52 | 53 | Compile your blog, and see: 54 | ``` clojure 55 | "

Hello

" 56 | ``` 57 | 58 | #### Example 2 59 | 60 | In your tags: 61 | ```clojure 62 | (defn rules [& rs] 63 | (into [:ol] (map #(vector :li %) rs))) 64 | ``` 65 | 66 | Then, in your post: 67 | ```clojure 68 | [:article 69 | [:h1 "Hey friend!"] 70 | (rules 71 | "The first rule of Fight Club is: you do not talk about Fight Club." 72 | "The second rule of Fight Club is: you DO NOT talk about Fight Club!" 73 | "Third rule of Fight Club: if someone yells “stop!”, goes limp, or taps out, the fight is over." 74 | "Fourth rule: only two guys to a fight. " 75 | "Fifth rule: one fight at a time, fellas." 76 | "Sixth rule: the fights are bare knuckle. No shirt, no shoes, no weapons." 77 | "Seventh rule: fights will go on as long as they have to." 78 | "And the eighth and final rule: if this is your first time at Fight Club, you have to fight.")] 79 | ``` 80 | 81 | 3. Templates (optional) 82 | 83 | There are 2 templates that you can use to customize how *posts* and your *index* page look. They're in `_tags/tags.cljs` and called `post-template` and `index-template` respectively, and can be edited like any other tag. 84 | 85 | Protip: don't remove those functions. 86 | 87 | ### Prequisites 88 | 89 | [Node.js](https://nodejs.org/en/) needs to be installed to run the application. 90 | 91 | ### running in development mode 92 | 93 | run the following command in the terminal to install NPM modules and start Figwheel: 94 | 95 | ``` 96 | lein build 97 | ``` 98 | 99 | run `node` in another terminal: 100 | 101 | ``` 102 | npm start 103 | ``` 104 | 105 | #### configuring the REPL 106 | 107 | Once Figwheel and node are running, you can connect to the remote REPL at `localhost:7000`. 108 | 109 | Type `(cljs)` in the REPL to connect to Figwheel ClojureScript REPL. 110 | 111 | 112 | ### building the release version 113 | 114 | ``` 115 | lein package 116 | ``` 117 | 118 | Run the release version: 119 | 120 | ``` 121 | npm start 122 | ``` 123 | -------------------------------------------------------------------------------- /_posts/post_a.edn: -------------------------------------------------------------------------------- 1 | [:article 2 | [:h1 "Hello World"] 3 | [:p "I'm post A."]] 4 | -------------------------------------------------------------------------------- /_posts/post_b.edn: -------------------------------------------------------------------------------- 1 | [:article 2 | [:h3 "Hello, I'm post b."] 3 | [:p "Let's make something using a normal clojure function!"] 4 | [:hr] 5 | [:pre 6 | "(->> (range 1 10) 7 | (map (fn [n] [:li \"hi from line #\" n])) 8 | (into [:ol]))"] 9 | [:hr] 10 | (->> (range 1 10) 11 | (map (fn [n] [:li "hi from line #" n])) 12 | (into [:ol]))] 13 | -------------------------------------------------------------------------------- /_posts/post_c.edn: -------------------------------------------------------------------------------- 1 | [:article 2 | (my/title "Hello World") 3 | [:p "I'm post C and I just used a tag function called my/title,"] 4 | [:p "located in " 5 | [:code {:style "color: red;"} "_tags/tags.cljs"]] 6 | [:p "Its job is to make a heading. That way all the headings can be the same."]] 7 | -------------------------------------------------------------------------------- /_tags/tags.cljs: -------------------------------------------------------------------------------- 1 | ../src/bengine/tags.cljs -------------------------------------------------------------------------------- /docs/css/site.css: -------------------------------------------------------------------------------- 1 | /* my css */ 2 | -------------------------------------------------------------------------------- /docs/index.html: -------------------------------------------------------------------------------- 1 |

My Blog

Welcome or some-such.

-------------------------------------------------------------------------------- /docs/post_a.html: -------------------------------------------------------------------------------- 1 |

Post A

Posted on: Sun May 21 2017 13:37:15 GMT-0500 (CDT)

Hello World

I'm post A.

back--> -------------------------------------------------------------------------------- /docs/post_b.html: -------------------------------------------------------------------------------- 1 |

Post B

Posted on: Sun May 21 2017 13:38:27 GMT-0500 (CDT)

Hello, I'm post b.

Let's make something using a normal clojure function!


(->> (range 1 10)
2 |      (map (fn [n] [:li "hi from line #" n]))
3 |      (into [:ol]))

  1. hi from line #1
  2. hi from line #2
  3. hi from line #3
  4. hi from line #4
  5. hi from line #5
  6. hi from line #6
  7. hi from line #7
  8. hi from line #8
  9. hi from line #9
<--back--> -------------------------------------------------------------------------------- /docs/post_c.html: -------------------------------------------------------------------------------- 1 |

Post C

Posted on: Sun May 21 2017 14:13:05 GMT-0500 (CDT)

Hello World

I'm post C and I just used a tag function called bengine.tags/title,

located in _tags/tags.cljs

Its job is to make a heading. That way all the headings can be the same.

<--back -------------------------------------------------------------------------------- /env/dev/bengine/app.cljs: -------------------------------------------------------------------------------- 1 | (ns ^:figwheel-always bengine.app 2 | (:require 3 | [bengine.core :as core] 4 | [cljs.nodejs :as node] 5 | [mount.core :as mount])) 6 | 7 | (enable-console-print!) 8 | (mount/in-cljc-mode) 9 | (cljs.nodejs/enable-util-print!) 10 | 11 | (.on js/process "uncaughtException" #(js/console.error %)) 12 | 13 | (set! *main-cli-fn* core/main) 14 | -------------------------------------------------------------------------------- /env/dev/user.clj: -------------------------------------------------------------------------------- 1 | (ns user 2 | (:require [figwheel-sidecar.repl-api :as ra])) 3 | 4 | (defn start-fw [] 5 | (ra/start-figwheel!)) 6 | 7 | (defn stop-fw [] 8 | (ra/stop-figwheel!)) 9 | 10 | (defn cljs [] 11 | (ra/cljs-repl)) 12 | -------------------------------------------------------------------------------- /env/prod/bengine/app.cljs: -------------------------------------------------------------------------------- 1 | (ns bengine.app 2 | (:require 3 | [bengine.core :as core] 4 | [cljs.nodejs] 5 | [mount.core :as mount])) 6 | 7 | (enable-console-print!) 8 | 9 | (mount/in-cljc-mode) 10 | 11 | (cljs.nodejs/enable-util-print!) 12 | 13 | (set! *main-cli-fn* core/main) 14 | -------------------------------------------------------------------------------- /env/test/bengine/app.cljs: -------------------------------------------------------------------------------- 1 | (ns bengine.app 2 | (:require 3 | [doo.runner :refer-macros [doo-tests]] 4 | [bengine.core-test])) 5 | 6 | (doo-tests 'bengine.core-test) 7 | 8 | 9 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "private" : true, 3 | "name" : "bengine", 4 | "description" : "FIXME: write this!", 5 | "version" : "0.1.0-SNAPSHOT", 6 | "dependencies" : { 7 | "random-bytes" : "1.0.0", 8 | "multiparty" : "4.1.2", 9 | "source-map-support" : "0.4.6", 10 | "ws" : "1.1.1", 11 | "cookies" : "0.6.2", 12 | "etag" : "1.7.0", 13 | "lru" : "3.1.0", 14 | "qs" : "6.3.0", 15 | "content-type" : "1.0.2", 16 | "url" : "0.11.0", 17 | "simple-encryptor" : "1.1.0", 18 | "concat-stream" : "1.5.2" 19 | }, 20 | "main" : "target/out/bengine.js", 21 | "scripts" : { 22 | "start" : "node target/out/bengine.js" 23 | } 24 | } -------------------------------------------------------------------------------- /project.clj: -------------------------------------------------------------------------------- 1 | (defproject bengine "0.1.0-SNAPSHOT" 2 | :description "FIXME: write this!" 3 | :url "http://example.com/FIXME" 4 | :dependencies [[bidi "2.1.1"] 5 | [com.cemerick/piggieback "0.2.1"] 6 | [com.taoensso/timbre "4.10.0"] 7 | [hiccups "0.3.0"] 8 | [macchiato/core "0.1.8"] 9 | [macchiato/env "0.0.6"] 10 | [mount "0.1.11"] 11 | [org.clojure/clojure "1.8.0"] 12 | [org.clojure/clojurescript "1.9.542"] 13 | [macchiato/fs "0.0.7"] 14 | [org.clojure/tools.reader "0.10.0"] 15 | [org.clojure/test.check "0.9.0"]] 16 | :jvm-opts ^:replace ["-Xmx1g" "-server"] 17 | :plugins [[lein-doo "0.1.7"] 18 | [macchiato/lein-npm "0.6.3"] 19 | [lein-figwheel "0.5.10"] 20 | [lein-cljsbuild "1.1.5"] 21 | [cider/cider-nrepl "0.15.0-SNAPSHOT"] 22 | [refactor-nrepl "2.3.0-SNAPSHOT"]] 23 | :npm {:dependencies [[source-map-support "0.4.6"]] 24 | :write-package-json true} 25 | :source-paths ["src" "target/classes"] 26 | :clean-targets ["target"] 27 | :target-path "target" 28 | :profiles 29 | {:dev 30 | {:npm {:package {:main "target/out/bengine.js" 31 | :scripts {:start "node target/out/bengine.js"}}} 32 | :cljsbuild 33 | {:builds {:dev 34 | {:source-paths ["env/dev" "src"] 35 | :figwheel true 36 | :compiler {:main bengine.app 37 | :output-to "target/out/bengine.js" 38 | :output-dir "target/out" 39 | :target :nodejs 40 | :optimizations :none 41 | :pretty-print true 42 | :source-map true 43 | :source-map-timestamp false}}}} 44 | :figwheel 45 | {:http-server-root "public" 46 | :nrepl-port 7000 47 | :reload-clj-files {:clj false :cljc true} 48 | :nrepl-middleware [cemerick.piggieback/wrap-cljs-repl 49 | refactor-nrepl.middleware/wrap-refactor 50 | cider.nrepl/cider-middleware]} 51 | :source-paths ["env/dev"] 52 | :repl-options {:init-ns user}} 53 | :test 54 | {:cljsbuild 55 | {:builds 56 | {:test 57 | {:source-paths ["env/test" "src" "test"] 58 | :compiler {:main bengine.app 59 | :output-to "target/test/bengine.js" 60 | :target :nodejs 61 | :optimizations :none 62 | :pretty-print true 63 | :source-map true}}}} 64 | :doo {:build "test"}} 65 | :release 66 | {:npm {:package {:main "target/release/bengine.js" 67 | :scripts {:start "node target/release/bengine.js"}}} 68 | :cljsbuild 69 | {:builds 70 | {:release 71 | {:source-paths ["env/prod" "src"] 72 | :compiler {:main bengine.app 73 | :output-to "target/release/bengine.js" 74 | :language-in :ecmascript5 75 | :target :nodejs 76 | :optimizations :simple 77 | :pretty-print false}}}}}} 78 | :aliases 79 | {"build" ["do" 80 | ["clean"] 81 | ["npm" "install"] 82 | ["figwheel" "dev"]] 83 | "package" ["do" 84 | ["clean"] 85 | ["npm" "install"] 86 | ["with-profile" "release" "npm" "init" "-y"] 87 | ["with-profile" "release" "cljsbuild" "once"]] 88 | "test" ["do" 89 | ["npm" "install"] 90 | ["with-profile" "test" "doo" "node"]]}) 91 | -------------------------------------------------------------------------------- /public/css/site.css: -------------------------------------------------------------------------------- 1 | /* my css */ 2 | -------------------------------------------------------------------------------- /public/index.html: -------------------------------------------------------------------------------- 1 |

My Blog

Welcome or some-such.

-------------------------------------------------------------------------------- /public/post_a.html: -------------------------------------------------------------------------------- 1 |

Post A

Posted on: Sun May 21 2017 13:37:15 GMT-0500 (CDT)

Hello World

I'm post A.

back--> -------------------------------------------------------------------------------- /public/post_b.html: -------------------------------------------------------------------------------- 1 |

Post B

Posted on: Sun May 21 2017 13:38:27 GMT-0500 (CDT)

Hello, I'm post b.

Let's make something using a normal clojure function!


(->> (range 1 10)
2 |      (map (fn [n] [:li "hi from line #" n]))
3 |      (into [:ol]))

  1. hi from line #1
  2. hi from line #2
  3. hi from line #3
  4. hi from line #4
  5. hi from line #5
  6. hi from line #6
  7. hi from line #7
  8. hi from line #8
  9. hi from line #9
<--back--> -------------------------------------------------------------------------------- /public/post_c.html: -------------------------------------------------------------------------------- 1 |

Post C

Posted on: Sun May 21 2017 14:13:05 GMT-0500 (CDT)

Hello World

I'm post C and I just used a tag function called bengine.tags/title,

located in _tags/tags.cljs

Its job is to make a heading. That way all the headings can be the same.

<--back -------------------------------------------------------------------------------- /src/bengine/config.cljs: -------------------------------------------------------------------------------- 1 | (ns bengine.config 2 | (:require [macchiato.env :as config] 3 | [mount.core :refer [defstate]])) 4 | 5 | (defstate env :start 6 | (merge 7 | {:posts-dir "_posts" 8 | :out-dir "public"} 9 | (config/env))) 10 | 11 | (defn posts-dir [] (:posts-dir @env)) 12 | (defn out-dir [] (:out-dir @env)) 13 | -------------------------------------------------------------------------------- /src/bengine/core.cljs: -------------------------------------------------------------------------------- 1 | (ns bengine.core 2 | (:require [macchiato.fs :as fs] 3 | [bengine.config :refer [posts-dir out-dir]] 4 | [bengine.files :as bf] 5 | [bengine.tags] 6 | [clojure.string :as str])) 7 | 8 | (enable-console-print!) 9 | 10 | (defn super-print 11 | ([s] (super-print s ";")) 12 | ([s c] 13 | (let [margin 4 14 | length (+ (* 2 margin) (count s))] 15 | (println (str/join "" (repeat length c))) 16 | (println (str c c " " s " " c c)) 17 | (println (str/join "" (repeat length c))) 18 | (println "")))) 19 | 20 | (defn main [] 21 | (super-print "Compiling your blog!" (rand-nth ["X" "!" ";" "*" "o" "O" "." "\""])) 22 | (bf/compile-blog (posts-dir) (out-dir)) 23 | (super-print " Success! " ";")) 24 | 25 | ;; to trigger blog re-compiling, just re-save this file 26 | ;; (->> (main) time) 27 | -------------------------------------------------------------------------------- /src/bengine/files.cljs: -------------------------------------------------------------------------------- 1 | (ns bengine.files 2 | (:require [macchiato.fs :as fs] 3 | [cljs.nodejs :as node] 4 | [hiccups.runtime :as hiccupsrt] 5 | [cljs.repl :as repl] 6 | [cljs.tools.reader :refer [read-string]] 7 | [cljs.js :refer [empty-state eval js-eval]] 8 | [clojure.string :as str] 9 | [bengine.config :as c] 10 | [bengine.tags :as my] ;; <-- load this for evalling templates 11 | ) 12 | (:require-macros [hiccups.core :as hiccups])) 13 | 14 | (defn- get-file-name [file-path] 15 | (last (last (re-seq #"/(.[^/|*].+)" file-path)))) 16 | 17 | (defn- eval-str [s] 18 | (eval (empty-state) 19 | (read-string 20 | (str "(do (enable-console-print!)" s ")")) 21 | {:eval js-eval 22 | :source-map true 23 | :context :expr} 24 | (fn [result] 25 | (println "got result: " (pr-str result)) 26 | (:value result ::no-value)))) 27 | 28 | (defn- posts [path] 29 | {:pre [(fs/exists? path)]} 30 | (let [edn-file? #(str/ends-with? % ".edn") 31 | normalize-path #(str path "/" %)] 32 | (->> path fs/read-dir-sync (filter edn-file?) (map normalize-path) vec))) 33 | 34 | (defn ->title [file-path] 35 | (as-> file-path $ 36 | (get-file-name $) 37 | (str/replace $ ".edn" "") 38 | (str/replace $ "_" " ") 39 | (str/split $ " ") 40 | (map str/capitalize $) 41 | (str/join " " $))) 42 | 43 | (defn- process-post [file-path] 44 | (println "processing: " file-path) 45 | (println "reading --> " file-path) 46 | (let [process-hiccup (comp eval-str 47 | ;; ;; evil stuff ------v -------v 48 | #(str/replace % "my/" "bengine.tags/") 49 | fs/slurp)] 50 | {:content (process-hiccup file-path) 51 | :file-path file-path 52 | :here (-> file-path 53 | get-file-name 54 | (str/replace "edn" "html")) 55 | :title (->title file-path) 56 | :creation-time (:birthtime (fs/stat file-path))})) 57 | 58 | (defn add-next-prev [posts] 59 | (vec 60 | (map-indexed 61 | (fn [idx p] 62 | (let [next-file (:here (get posts (inc idx))) 63 | prev-file (:here (get posts (dec idx)))] 64 | (assoc p :next next-file :prev prev-file))) 65 | posts))) 66 | 67 | (defn- process-posts [path] 68 | (->> (posts path) 69 | (mapv process-post) 70 | (sort-by :file-path) 71 | vec 72 | add-next-prev)) 73 | 74 | (defn- write-post [out-dir in-dir {:keys [content file-path here title creation-time prev next]}] 75 | (println "writing post -> " file-path) 76 | (fs/spit (str out-dir "/" here) 77 | (hiccups/html 78 | (my/post content {:title title 79 | :creation-time creation-time 80 | :here here 81 | :next next 82 | :prev prev 83 | :up "index.html"})))) 84 | 85 | (defn- write-posts [processed-posts out-dir in-dir] 86 | (doseq [post-info processed-posts] 87 | (write-post out-dir in-dir post-info))) 88 | 89 | (defn- write-index [processed-posts out-dir] 90 | (let [out-str (-> processed-posts my/index hiccups/html) 91 | out-file (str out-dir "/index.html")] 92 | (println "writing index -> " out-file) 93 | (fs/spit out-file out-str))) 94 | 95 | (defn compile-blog [in-dir out-dir] 96 | (println "in-dir: " in-dir) 97 | (let [processed-posts (process-posts in-dir)] 98 | (println "writing posts...") 99 | (write-posts processed-posts out-dir in-dir) 100 | (println "writing index...") 101 | (write-index processed-posts out-dir))) 102 | 103 | ;; (bengine.core/main) 104 | -------------------------------------------------------------------------------- /src/bengine/specs.cljs: -------------------------------------------------------------------------------- 1 | (ns bengine.specs 2 | (:require 3 | [clojure.test.check.generators] 4 | [clojure.spec.alpha :as s] 5 | [clojure.string :as str])) 6 | 7 | (s/def :post/title string?) 8 | (s/def :post/next-url (s/and 9 | string? 10 | #(str/starts-with? % "/") 11 | #(str/ends-with? % ".html"))) 12 | (s/def :post/prev-url (s/and 13 | string? 14 | #(str/starts-with? % "/") 15 | #(str/ends-with? % ".html"))) 16 | (s/def :post/my-url (s/and 17 | string? 18 | #(str/starts-with? % "/") 19 | #(str/ends-with? % ".html"))) 20 | 21 | (s/def :post/creation-time inst?) 22 | 23 | 24 | (s/def ::post 25 | (s/keys :req [:post/title 26 | :post/creation-time 27 | :post/here 28 | :post/next 29 | :post/prev])) 30 | -------------------------------------------------------------------------------- /src/bengine/tags.cljs: -------------------------------------------------------------------------------- 1 | (ns bengine.tags 2 | (:require [clojure.string :as str])) 3 | 4 | (def moment (js/require "moment")) 5 | 6 | (defn ->date [js-date] 7 | (.format (moment creation-time) "LL")) 8 | 9 | ;; common wrapper for all pages 10 | (defn html [& forms] 11 | [:html 12 | [:head 13 | [:meta {:charset "utf-8"}] 14 | [:meta {:name "viewport" 15 | :content "width=device-width, initial-scale=1"}] 16 | [:link {:rel "stylesheet" 17 | :href "https://cdnjs.cloudflare.com/ajax/libs/tufte-css/1.1/tufte.min.css"}]] 18 | [:body forms]]) 19 | 20 | ;; wrapper for the index page (home page) 21 | (defn index [post-infos] 22 | (html 23 | [:article 24 | [:h1 "My Blog"] 25 | [:p "Welcome or some-such."] 26 | (into 27 | [:ul] 28 | ;; Example post info: 29 | (for [{:keys [here title creation-time]} 30 | post-infos] 31 | [:li 32 | [:a {:href here} title] 33 | [:span " - (posted on: " (->date creation-time) ")"]]))])) 34 | 35 | ;; wrapper common to all posts 36 | (defn post [content {:keys [title creation-time here next prev up]}] 37 | (html 38 | [:h1 [:a {:href here} title]] 39 | [:span "Posted on: " (->date creation-time)] 40 | content 41 | (when prev 42 | [:a {:href prev} "<--"]) 43 | [:span {:style "margin: auto 10px;"} 44 | [:a {:href up} "back"]] 45 | (when next 46 | [:a {:href next} "-->"]))) 47 | 48 | ;; user's own tags: 49 | (defn title [s] [:h1 s]) 50 | 51 | (defn p [& xs] 52 | [:p (str/join \newline xs)]) 53 | -------------------------------------------------------------------------------- /system.properties: -------------------------------------------------------------------------------- 1 | java.runtime.version=1.8 2 | -------------------------------------------------------------------------------- /test/bengine/core_test.cljs: -------------------------------------------------------------------------------- 1 | (ns bengine.core-test 2 | (:require 3 | [cljs.test :refer-macros [is are deftest testing use-fixtures]] 4 | [bengine.core])) 5 | 6 | (deftest test-core 7 | (is (= true true))) 8 | 9 | 10 | --------------------------------------------------------------------------------