all repos — hex @ 62f3370435f3f45ba3633ca2b84d441374050be6

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

; 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-templates "/page.html" cat "t-page" :

; 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
) "process-tag" :

"*** Generating hex web site..." puts
; Write contents
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 .
    "new-content" :
    (fn-content "home.html" ==)
        (d-out "/index.html" cat "dst-file" :) 
        (
            ("sh -c \"mkdir -p " d-out "/" id-content "\"") () map "" join exec
            (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