all repos — h3rald @ d041f9cf66df929a4e132542a17de622365a811f

The sources of https://h3rald.com

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
'hastysite import

() =TAGS
() =TAGCOLUMNS


; Populates the TAGCOLUMNS 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
    () =tagdata
    tagdata (
      tagname %tag
      tagcount %count 
    ) tap #tagdata
    count succ @count
    tagdata tagcolumn append #tagcolumn
    (count 4 == tcount 0 == or) 
    (
      ()
      tagcolumn %tags
      TAGCOLUMNS append #TAGCOLUMNS
      0 @count
      () #tagcolumn
    ) when
  ) foreach
) :prepare-tag-data


; Create the Tags page.
(
  ()
  "tags/index"  %id
  "tags"        %path
  ".html"       %ext
  "Tags"        %title
  "page"        %content-type
  TAGCOLUMNS    %tagcolumns
  dup "_tags" swap mustache %contents
  dup "page" swap mustache %contents
  output-fwrite
) :create-tags-page


; 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" ==) ("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

;;;; MAIN ;;;;

contents (process-tags process-content output-fwrite) foreach
prepare-tag-data
create-tags-page


; Process all assets.
assets (
  dup
  (
    ((/id "^pdf\/" match) (copy-pdf-article-asset))
    ;((/ext ".css" match) (process-css-asset))
    ((true) (output-cp))
  ) case
) foreach