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
|