all repos — hex @ e34b362d470a1ec58ecdc83f6578183ad2128aaa

A tiny, minimalist, slightly-esoteric concatenative programming lannguage.

scripts/web.hex

 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
"2024" "meta-year" :
"0.2.0" "meta-release" :
"web/assets" "d-assets" :
"web/templates" "d-templates" :
"web/contents" "d-contents" :
"web/out" "d-out" :
"releases" "d-releases" :

; Get all files from a directory
("ls " swap cat run 0x1 get "\n" split) "ls" :

; Get relevant files
d-contents ls . "contents" :
d-assets ls . "assets" :
d-releases ls . "releases" :
d-templates "/page.html" cat "t-page" :

; Symbols to substitute with the corresponding links 
("split" "run" "get" "puts" ":" "::" "." "#" "==" "'" "swap" "dup"
"+" "*" "-" "each" "cat" "throw" "symbols" "print" "read" "dec" "write" "append" "!" "<=" "if") "symbol-links" :

;; Syntax highlighting

; Delimiters and replacements for syntax highlighting
(
    "$;" 
    "$#|" 
    "|#$" 
    "$\"" 
    "$0x" 
    "$:" 
    "$$"
    "%:"
    "%%"
) "highlight-delimiters" :

(
    "<span class=\"hex-comment\">;" 
    "<span class=\"hex-comment\">#|" 
    "|#</span>" 
    "<span class=\"hex-string\">\""
    "<span class=\"hex-integer\">0x"
    "<span class=\"hex-symbol\">"
    "</span>"
    "<code>"
    "</code"
) "highlight-replacements" :

; Highlight syntax in text
(
    "t-text" :
    0x0 "t-count" :
    (t-count highlight-delimiters len <)
        (
            t-text highlight-delimiters t-count get "t-delimiter" :
            t-text highlight-replacements t-count get "t-replacement" :
            ; Find delimiter in text and replace it with the corresponding replacement
            (t-text t-delimiter index 0x0 >=)
                (
                    t-text t-delimiter t-replacement replace "t-text" :
                ) 
            while
            t-count 0x1 + "t-count" :
        )
    while
    ; Push highlighted text on the stack
    t-text
    ; Free temporary symbols
    "t-text" #
    "t-count" #
    "t-delimiter" #
    "t-replacement" #
) "highlight" :

; Convenience symbol for debugging
(dup puts) "_" :

; Generate tag placeholder
(
    "{{" swap "}}" cat cat
) "tag" :

; Replace tag
(
    "pt-repl" :
    "pt-tag" :
    "pt-content" :
    (pt-content pt-tag tag . index 0x0 >)
        (pt-content pt-tag tag . pt-repl replace "pt-content" :)
    while 
    pt-content
    "pt-repl"    #
    "pt-tag"     #
    "pt-content" #
) "process-tag" :


; Replace symbol placeholder with link to spec
(
    "t-symbol" :
    "t-content" :
    t-symbol "t-href" :
    ; Handle "special" symbols
    (t-symbol ":" ==)("store" "t-href" :) when
    (t-symbol "<=" ==)("lessthanequal" "t-href" :) when
    t-symbol "." ==)("i" "t-href" :) when
    (t-symbol "." ==)("i" "t-href" :) when
    (t-symbol "#" ==)("free" "t-href" :) when
    (t-symbol "!" ==)("eval" "t-href" :) when
    (t-symbol "'" ==)("quote" "t-href" :) when
    (t-symbol "+" ==)("add" "t-href" :) when
    (t-symbol "::" ==)("operator" "t-href" :) when
    (t-symbol "*" ==)("multiply" "t-href" :) when
    (t-symbol "-" ==)("subtract" "t-href" :) when
    ("<a href=\"https://hex.2c.fyi/spec#" t-href "-symbol\">" t-symbol "</a>") () map "" join "t-repl" :
    ; Push replacement content on the stack
    t-content 
    "sym-" t-symbol cat 
    t-repl 
    process-tag .
    ; Free temporary symbols
    "t-repl" #
    "t-symtag" #
    "t-href" #
    "t-symbol" #
) "process-symbol" : 

; Load releases content for changelog
"" "releases-content" :
(
    releases len 0x1 - "_count" :
    ; Reverse releases order
    (_count 0x0 <=)
        (
            releases _count get "id-release" :
            ; Update releases-content
            d-releases "/" id-release cat cat read releases-content swap cat "releases-content" : 
            _count 0x1 - "_count" :
        )
    while
    "_count"        #
    "id-release"    #
) "process-releases" :

; Create changelog toc
(
    "" "changelog-toc" : ;external
    releases len 0x1 - "_count" :
    ; Reverse releases order
    (_count 0x0 <=)
        (
            releases _count get ".html" "" replace "id-release" :
            changelog-toc
            ("<li><a href=\"#v" id-release "\">v" id-release "</a></li>\n") () map "" join 
            cat
            "changelog-toc" :
            _count 0x1 - "_count" :
        )
    while
    "<ul>\n"
    changelog-toc
    "</ul>\n" 
    cat cat
    "changelog-toc" : 
    "_count"        #
    "id-release"    #

) "generate-changelog-toc" :

generate-changelog-toc .

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;; Generate CHANGELOG
"*** Updating CHANGELOG.md..." puts
process-releases .

; Read changelog template and add generated release content
d-contents "/" "changelog.html" cat cat read
"changelog-toc" changelog-toc process-tag .
"releases" releases-content process-tag .
"changelog-content" :
symbol-links (changelog-content swap process-symbol . "changelog-content" :) () map

; Write CHANGELOG.md
changelog-content
"CHANGELOG.md" write
"*** Done!" puts

;;;;; Write web site contents
"*** Generating hex web site..." puts
contents
(
    "fn-content" :
    fn-content ".html" "" replace "id-content" :
    d-contents "/" fn-content cat cat read "content" :
    t-page read
    ; Replace tags
    "content" content process-tag .
    "title" id-content process-tag .
    "release" meta-release process-tag .
    "year" meta-year process-tag .
    "changelog-toc" changelog-toc process-tag .
    "releases" releases-content process-tag .
    "new-content" :
    ; Replace symbols with links
    symbol-links (new-content swap process-symbol . "new-content" :) each
    ; Highlight syntax
    new-content highlight . "new-content" :
    (fn-content "home.html" ==)
        (
            ; Process home page
            d-out "/index.html" cat "dst-file" :
        ) 
        (
            (d-out id-content "index.html") () map "/" join "dst-file" :
        )
    if
    "  - Writing: " dst-file cat puts
    new-content dst-file write
) each


; Write assets
("sh -c \"mkdir -p " d-out "/assets\"") () map ""  join exec
assets
(
    "fn-asset" :
    (d-out "assets" fn-asset) () map "/" join "dst-file" :
    (fn-asset "robots.txt" ==)
        ((d-out fn-asset) () map "/" join "dst-file" :)
    when
    (d-assets fn-asset) () map "/" join "src-file" :
    "  - Writing: " dst-file cat puts
    ("cp" src-file dst-file) () map " " join exec  
) each

"*** Done!" puts