rules.min
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 |
'hastysite import () =TAGS () =TAG-COLUMNS () =ARCHIVES () =ARCHIVE-COLUMNS () =ARTICLES () =HOME ; Populates the ARCHIVE-COLUMNS array containing tags in groups ; of four, suitable for the creation of the archives page. ( ARCHIVES dsort reverse #ARCHIVES 0 :count () =archcolumn ARCHIVES size :acount ARCHIVES ( =archive acount pred @acount archive last =arch arch /id :archid arch /articles size :archcount arch /month :month () archcount %count archid %id month %month =archdata count succ @count archdata archcolumn append #archcolumn (count 4 == acount 0 == or) ( () archcolumn %archives ARCHIVE-COLUMNS append #ARCHIVE-COLUMNS 0 @count () #archcolumn ) when ) foreach ) :prepare-archive-data ; Populates the TAG-COLUMNS array containing tags in groups ; of four, suitable for the creation of the tags page. ( TAGS dsort #TAGS 0 :count () =tagcolumn TAGS size :tcount TAGS ( =tag tcount pred @tcount tag first :tagname tag last size :tagcount () tagname %tag tagcount %count =tagdata count succ @count tagdata tagcolumn append #tagcolumn (count 4 == tcount 0 == or) ( () tagcolumn %tags TAG-COLUMNS append #TAG-COLUMNS 0 @count () #tagcolumn ) when ) foreach ) :prepare-tag-data ; Utility operator to format a timestamp into a date ( int "dddd, d MMMM yyyy" tformat ) :to-date ; Create the Archives page. ( () "archives/index" %id "archives.html" %path ".html" %ext "Archives" %title "page" %content-type ARCHIVE-COLUMNS %archive-columns dup "_archives" swap mustache %contents dup "page" swap mustache %contents output-fwrite ) :create-archives-page ; Create the Tags page. ( () "tags/index" %id "tags.html" %path ".html" %ext "Tags" %title "page" %content-type TAG-COLUMNS %tag-columns dup "_tags" swap mustache %contents dup "page" swap mustache %contents output-fwrite ) :create-tags-page ; Create a page for a specific archive ( (quot) expect -> =archive archive last =archdata archdata /month :month archdata /articles =articles archdata /id :id articles articles ( ((/timestamp swap /timestamp >) sort) ((dup /timestamp to-date %date) map) ) tap #articles articles size :count (count 1 ==) ("1 article was written") ("$1 articles were written" (count) => %) if :articles-written () "archives/$1/index" (id) => % %id "archives/$1.html" (id) => % %path ".html" %ext "page" %content-type "Archive: $1" (month) => % %title month %month articles-written %articles-written articles %articles dup "_archive" swap mustache %contents dup "page" swap mustache %contents output-fwrite ) :create-archive-page ; Create a page for a specific tag ( (quot) expect -> =tagdata tagdata first :tag tagdata last =articles articles articles ( ((/timestamp swap /timestamp >) sort) ((dup /timestamp to-date %date) map) ) tap #articles articles size :count (count 1 ==) ("1 article is tagged") ("$1 articles are tagged" (count) => %) if :articles-tagged () "tags/$1/index" (tag) => % %id "tags/$1.html" (tag) => % %path tag %tag ".html" %ext "page" %content-type "Tag: $1" (tag) => % %title articles-tagged %articles-tagged articles %articles dup "_tag" swap mustache %contents dup "page" swap mustache %contents output-fwrite ) :create-tag-page ; Group articles by month ( (dict) expect -> =content (content ?timestamp) ( content /timestamp :ts ts to-date :date ts int "yyyyMM" tformat :code ts int "MMMM yyyy" tformat :month ts int "MMMM-yyyy" tformat lowercase :id ; Add to articles content date %date content ARTICLES append #ARTICLES (ARCHIVES code dhas?) ( ; Add article to existing archive content ("id" "title" "timestamp") dpick =article ARCHIVES code dget =archivedata archivedata /articles =articles article articles append #articles archivedata articles %articles #archivedata ARCHIVES archivedata code dset #ARCHIVES ) ( ; Create new monthly archive content ("id" "title" "timestamp") dpick ' =article () month %month article %articles id %id =archive ARCHIVES archive code dset #ARCHIVES ) if ) when content ) :process-timestamp ; Group articles by tags ( (dict) expect -> =content (content ?tags) ( content /tags "|" split =tags tags ( :tag (TAGS tag dhas?) ( ; Add article to existing tag content ("id" "title" "timestamp") dpick =article TAGS tag dget =tagdata article tagdata append #tagdata TAGS tagdata tag dset #TAGS ) ( ; Create new tag content ("id" "title" "timestamp") dpick ' =article TAGS article tag dset #TAGS ) if ) foreach ) when content ) :process-tags ; Copy PDF files saved in asset folder ; to the corresponding article output folder. ( (dict) expect -> =asset asset /id :id id "^pdf\/(.+)$" search 1 get :name asset "output/articles/$1/$1" (name) => % %id #asset asset output-cp ) :copy-pdf-article-asset ; Process a content file applying the appropriate template ; and compiling markdown to HTML if necessary. ( (dict) expect -> =content content /id :id content /content-type :ct "page" :tpl (ct "article" ==) ("article" @tpl) when (id "index" ==) (content #HOME "home" @tpl) when "" :page "" :contents content ( (input-fread @contents content) ((/ext ".md" ==) (=temp contents temp markdown @contents temp) when) (contents %contents) (=temp tpl temp mustache @page temp) (page %contents) ((id "index" !=)("$1/index" (id) => % %id ".html" %ext) when) ) tap ) :process-content ; Process and generate home page ( ; Sort articles by timestamp ARTICLES (/timestamp swap /timestamp >) sort #ARTICLES ARTICLES first =latest ARTICLES 1 4 slice =recents ; Process summary latest input-fread "/(.+)?<hr/ms" regex 1 get latest markdown :summary latest summary %summary #latest latest dup /timestamp to-date %date #latest ; Process top tags TAGS ( dup first :tag last size :total (tag total) => ) map (last swap last >) sort 0 9 slice ( =data () data first %tag data last %total ) map =tags HOME ( (latest %latest) (recents %recents) (tags %tags) (=temp temp "home" temp mustache %contents) (output-fwrite) ) tap! ) :generate-home ;;;;; MAIN ;;;;; ; Process all contents contents ( =content content /id :id content process-tags process-timestamp process-content (id "index" !=) 'output-fwrite when ) foreach ; Generate tag pages prepare-tag-data create-tags-page TAGS 'create-tag-page foreach ; Generate archive pages prepare-archive-data create-archives-page ARCHIVES 'create-archive-page foreach ; Generate home page generate-home ; Process all assets. assets ( dup ( ((/id "^pdf\/" match) (copy-pdf-article-asset)) ;((/ext ".css" match) (process-css-asset)) ((true) (output-cp)) ) case ) foreach |