all repos — hex @ 033f211f0c1b498f6f57752b760d58d496a52d81

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

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" store
"0.1.0" "meta_release" store
"web/assets" "d_assets" store
"web/templates" "d_templates" store
"web/contents" "d_contents" store
"web/out" "d_out" store

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

; Get relevant files
d_contents ls i "contents" store
d_assets ls i "assets" store
d_templates "/page.html" cat "t_page" store

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

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

; Replace tag
(
    "pt_repl" store
    "pt_tag" store
    "pt_content" store
    (pt_content pt_tag tag i index 0x0 >)
        (pt_content pt_tag tag i pt_repl replace "pt_content" store)
    while 
    pt_content
) "process-tag" store

"*** Generating hex web site..." puts
; Write contents
contents
(
    "fn_content" store
    fn_content ".html" "" replace "id_content" store
    d_contents "/" fn_content cat cat read "content" store
    t_page read
    ; Replace tags
    "content" content process-tag i
    "title" id_content process-tag i
    "release" meta_release process-tag i
    "year" meta_year process-tag i
    "new_content" store
    (fn_content "home.html" ==)
        (d_out "/index.html" cat "dst_file" store) 
        (
            ("sh -c \"mkdir -p " d_out "/" id_content "\"") () map "" join exec
            (d_out id_content "index.html") () map "/" join "dst_file" store
        )
    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" store
    (d_out "assets" fn_asset) () map "/" join "dst_file" store
    (fn_asset "robots.txt" ==)
        ((d_out fn_asset) () map "/" join "dst_file" store)
    when
    (d_assets fn_asset) () map "/" join "src_file" store
    "  - Writing: " dst_file cat puts
    ("cp" src_file dst_file) () map " " join exec  
) each

"*** Done!" puts