Last active 3 days ago

sitegen_no_content.st Raw Playground
1site: cmd[
2 Array .new >pages
3 "**/*.pstk" Directory .glob each[
4 if[ dup .file? :then pages .push :else void ]
5 ]
6 #page: module/extend[ static/style.css: File .slurp >style ]
7 source-of: fn[ .[ Path .[ "." of[ path name ] relative ] ] ]
8 dest-of: fn[ .[
9 Path .[
10 "." of[ path name Path .parse .name ".html" + ] relative
11 "content/" "site/" String .replace ] ] ]
12 Directory .[
13 try[ site: rmr :catch void ]
14 static: site: copy ]
15 File .[ NB[ Files I don't have a better way to copy in atm ]
16 "../../stvm.js" site/stvm.js: copy
17 "../../stkweb.js" "site/stkweb.js" copy
18 "../../lib/browser/browser.stk" "site/browser.stk" copy
19 "../../lib/core/core.stk" "site/core.stk" copy
20 ]
21 Set .of[ pages each[ dest-of Path .parse .dir ] ] >destFolders
22
23 destFolders each[ Directory .ensure ]
24 pages each[ >p p. dest-of p> source-of /t StackTalk .load-file ]
25]
26
27#page: module[
28
29 "" >title
30 "" >contents
31 "" >imports
32 "" >script
33
34 @: fn[ write ]
35 @title: fn[ @ title @ ]
36 @style: fn[ @ style @ ]
37 @contents: fn[ @ contents @ ]
38 @imports: fn[ @ imports @ ]
39 @script: fn[ @ script @ ]
40
41 @header: fn[
42"<!DOCTYPE html>
43<html lang='en'>
44<head>
45 <meta charset='utf-8'>
46 <meta http-equiv='X-UA-Compatile' cotent='IE=edge'/>
47 <meta name='viewport' content=''/>
48 <title>" @title "</title>
49</head>
50" @
51 ]
52 @body: fn[
53 "<body>
54 <style>
55 " @style
56 "</style>
57 <h2><a href='./'>" @title "</a></h2>
58 <main role='main' class='conatainer'>"
59 @contents
60 "</main>
61 "
62 @imports
63 "<script type='module'>"
64 @script
65 "</script>
66 </body>" @
67 ]
68 render: fn[
69 @header @body "</html>" @
70 ]
71]
72
73#markup: module[
74 nl: fn[ /nl @ ]
75
76 proc-tag: fn[
77 >#tag >#proc
78 "<" @ #tag. @ " " @
79 #proc. Proc .blocks each[ >#attr
80 #attr. @ "=\"" @
81 #proc. #attr. Proc .run? escape @
82 "\"" @
83 ]
84 ">" @
85
86 temp[ #tag #proc done did ]
87 false >done
88 [ done: [ void true ] change ] >did
89
90 #proc. proc: Proc .run?
91
92 if[ $: #proc. has-flag? :then $ did ]
93 if[ done. ~: #proc. has-flag? or not :then @ ]
94
95 "</" @ #tag. @ ">" @
96 ]
97
98 $: fn[ "<code>" @ escape @ "</code>" @ ]
99 quot-tag: fn[ >#tag >q "<" @ #tag. @ ">" @ q> run @ "</" @ #tag> @ ">" @ ]
100
101 tag: fn[ >#tag >#def
102 if[ #def. proc?
103 :then #def> #tag> proc-tag
104 :else #def> #tag> quot-tag ] ]
105
106 escape: fn[ "<" "&lt;" String .replace ">" "&gt;" String .replace ]
107
108 ---: fn[ "<hr/>" @ ]
109 %w[ h1 h2 h3 h4 p ul ol li code ] each[ dup fry[ _ tag ] fn ]
110
111 br: fn[ [ :~ ] br: tag ]
112 link: fn[ >q "<a href='" @ q. to: "link needs :to" Proc .run! @ "'>" @ q> proc: "link needs text!" Proc .run! @ "</a>" @ ]
113 code-block: fn[ "<pre><code>" @ run @ "</code></pre>" @ ]
114]
115
116page: fn[
117 >q w: File .open ask[ use[ #page #markup ] your[ q> ] run render close ]
118]