Ultima attività 3 days ago

yumaikas's Avatar yumaikas ha revisionato questo gist 3 days ago. Vai alla revisione

1 file changed, 26 insertions, 27 deletions

sitegen_no_content.stk rinominato come sitegen_no_content.st

@@ -1,27 +1,29 @@
1 - site: fn[
2 - Array .new >pages
1 + site: 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
3 22
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
23 + destFolders each[ Directory .ensure ]
24 + pages each[ >p p. dest-of p> source-of /t StackTalk .load-file ]
24 25 ]
26 +
25 27 #page: module[
26 28
27 29 "" >title
@@ -110,10 +112,7 @@ site: fn[
110 112 link: fn[ >q "<a href='" @ q. to: "link needs :to" Proc .run! @ "'>" @ q> proc: "link needs text!" Proc .run! @ "</a>" @ ]
111 113 code-block: fn[ "<pre><code>" @ run @ "</code></pre>" @ ]
112 114 ]
115 +
113 116 page: fn[
114 117 >q w: File .open ask[ use[ #page #markup ] your[ q> ] run render close ]
115 - ]
116 - pages: 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 - ]
118 + ]

yumaikas's Avatar yumaikas ha revisionato questo gist 3 days ago. Vai alla revisione

1 file changed, 119 insertions

sitegen_no_content.stk(file creato)

@@ -0,0 +1,119 @@
1 + site: 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 + ]
113 + page: fn[
114 + >q w: File .open ask[ use[ #page #markup ] your[ q> ] run render close ]
115 + ]
116 + pages: 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 + ]
Più nuovi Più vecchi