static rendering root prefix
s-ol
3 years ago
7 | 7 |
add '?/init.server'
|
8 | 8 |
|
9 | 9 |
-- usage:
|
10 | |
-- moon render_all.moon [STORE] [output] [startpath]
|
11 | |
{ store, output, startpath } = arg
|
|
10 |
-- moon render_all.moon [STORE] [output] [URL-prefix]
|
|
11 |
{ store, output, prefix } = arg
|
12 | 12 |
|
13 | 13 |
require 'mmm'
|
14 | 14 |
import Fileder, dir_base from require 'mmm.mmmfs.fileder'
|
|
24 | 24 |
with io.open path, 'w'
|
25 | 25 |
\write val
|
26 | 26 |
\close!
|
|
27 |
|
|
28 |
root: prefix
|
27 | 29 |
}
|
28 | 30 |
|
29 | 31 |
require 'mmm.mmmfs'
|
129 | 129 |
<!DOCTYPE html>
|
130 | 130 |
<html>
|
131 | 131 |
<head>]]
|
132 | |
buf ..= STATIC.style or [[<link rel="stylesheet" type="text/css" href="/static/style/:text/css" />]]
|
|
132 |
buf ..= if STATIC then STATIC.style else [[<link rel="stylesheet" type="text/css" href="/static/style/:text/css" />]]
|
133 | 133 |
buf ..= [[<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:200,400,600" />]]
|
134 | 134 |
buf ..= "
|
135 | 135 |
#{get_meta fileder}
|
0 | 0 |
extensions = {
|
1 | 1 |
'image/jpeg': 'jpg'
|
2 | 2 |
'image/png': 'png'
|
|
3 |
'image/svg+xml': 'svg'
|
3 | 4 |
|
4 | 5 |
'video/webm': 'webm'
|
5 | 6 |
'video/mp4': 'mp4'
|
|
15 | 16 |
out: 'URL -> %1',
|
16 | 17 |
cost: 5
|
17 | 18 |
transform: (val, fileder, key) =>
|
18 | |
escaped_from = @from\gsub '/', '$'
|
|
19 |
escaped_from = @from\gsub '/', '_'
|
19 | 20 |
if ext = extensions[@from]
|
20 | 21 |
escaped_from ..= ".#{ext}"
|
21 | 22 |
|
22 | |
with url = "#{fileder.path}/#{key.name}:#{escaped_from}"
|
|
23 |
prefix = STATIC.root or ''
|
|
24 |
|
|
25 |
prefix .. with url = "#{fileder.path}/#{key.name}:#{escaped_from}"
|
23 | 26 |
print " rendering asset #{url}"
|
24 | 27 |
STATIC.spit url, val
|
25 | 28 |
}
|
5 | 5 |
attr[k] = v
|
6 | 6 |
|
7 | 7 |
tourl = (path) ->
|
8 | |
if STATIC
|
9 | |
path .. '/'
|
10 | |
else
|
11 | |
path .. '/'
|
|
8 |
path ..= '/'
|
|
9 |
if STATIC and STATIC.root
|
|
10 |
path = STATIC.root .. path
|
|
11 |
path
|
12 | 12 |
|
13 | 13 |
(elements) ->
|
14 | 14 |
import a, div, span, sup, b, pre from elements
|