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 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 |
"2024" "meta-year" : "0.3.0" "meta-release" : "web/assets" "d-assets" : "web/templates" "d-templates" : "web/contents" "d-contents" : "web/out2" "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" "while" "+" "*" "-" "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 <) ( highlight-delimiters t-count get "t-delimiter" : 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 "_releases_count" : ; Reverse releases order (_releases_count 0x0 >) ( releases _releases_count 0x1 - get "id-release" : ; Update releases-content d-releases "/" id-release cat cat read releases-content swap cat "releases-content" : _releases_count 0x1 - "_releases_count" : ) while ;"_releases_count" # ;"id-release" # ) "process-releases" :: ; Create changelog toc ( "" "changelog-toc" : ; external releases len "_gct_count" : ; Reverse releases order (_gct_count 0x0 >) ( releases _gct_count 0x1 - get ".html" "" replace "id-release" : changelog-toc ("<li><a href=\"#v" id-release "\">v" id-release "</a></li>\n") () map "" join cat "changelog-toc" : _gct_count 0x1 - "_gct_count" : ) while "<ul>\n" changelog-toc "</ul>\n" cat cat "changelog-toc" : ;"_gct_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" : 0x0 "_c" : (_c symbol-links len <) ( changelog-content symbol-links _c get process-symbol "changelog-content" : _c 0x1 + "_c" : ) while ;"_c" # ; Write CHANGELOG.md changelog-content "CHANGELOG.md" write "*** Done!" puts ;;;;; Write web site contents "*** Generating hex web site..." puts 0x0 "_c" : (_c contents len <) ( contents _c get "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 0x0 "_i" : (_i symbol-links len <) ( new-content symbol-links _i get process-symbol "new-content" : _i 0x1 + "_i" : ) while ;"_i" # ; 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" : ("sh -c \"mkdir -p " d-out "/" id-content "\"") () map "" join exec ) if " - Writing: " dst-file cat puts new-content dst-file write _c 0x1 + "_c" : ) while ;"_c" # ; Write assets ("sh -c \"mkdir -p " d-out "/assets\"") () map "" join exec 0x0 "_c" : (_c assets len <) ( assets _c get "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 _c 0x1 + "_c" : ) while ;"_c" # "*** Done!" puts |