all repos — hex @ bf132c89d800c4ad4a435aeaef5656e72f6a6971

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
"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

"*** 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 "{{content}}" content replace "new_content" store
    (fn_content "home.html" ==)
        (d_out "/index.html" cat "dst_file" store) 
        (
            ("sh -c \"mkdir -p " d_out "/" id_content "\"") () map "" 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