Dernière activité 4 days ago

Révision d371d5bfb8f1be166c39088906f9ab5926746736

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