aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authors-ol <s-ol@users.noreply.github.com>2020-01-30 11:13:34 +0000
committers-ol <s-ol@users.noreply.github.com>2020-01-30 11:54:33 +0000
commita2ed63ca802ee109c1b70ceec56cf874875c37af (patch)
tree607925d859dab03254c583eadbbc2dac55afc7e8
parentadd workshops section (diff)
downloadmmm-a2ed63ca802ee109c1b70ceec56cf874875c37af.tar.gz
mmm-a2ed63ca802ee109c1b70ceec56cf874875c37af.zip
fix static rendering
-rw-r--r--.dockerignore5
-rw-r--r--build/render_all.moon49
-rw-r--r--mmm/mmmfs/layout.moon9
-rw-r--r--mmm/mmmfs/plugins/init.moon16
-rw-r--r--mmm/mmmfs/plugins/static.moon28
5 files changed, 84 insertions, 23 deletions
diff --git a/.dockerignore b/.dockerignore
index 5603375..f55d0d6 100644
--- a/.dockerignore
+++ b/.dockerignore
@@ -1,4 +1,9 @@
+db.sqlite3
+root/static/style/text$css.css
+root/static/mmm/text$lua.lua
+
.tup
Dockerfile
$bundle.lua
.bundle.lua
+mmm/**/*.lua
diff --git a/build/render_all.moon b/build/render_all.moon
index b09957e..57406be 100644
--- a/build/render_all.moon
+++ b/build/render_all.moon
@@ -7,26 +7,49 @@ add '?.server'
add '?/init'
add '?/init.server'
+-- usage:
+-- moon render_all.moon [STORE] [output] [startpath]
+{ store, output, startpath } = arg
+
require 'mmm'
-import Fileder from require 'mmm.mmmfs.fileder'
+import Fileder, dir_base from require 'mmm.mmmfs.fileder'
import get_store from require 'mmm.mmmfs.stores'
-import render from require 'mmm.mmmfs.layout'
--- usage:
--- moon render_all.moon [STORE] [startpath]
-{ store, startpath } = arg
+export UNSAFE, STATIC, BROWSER
+
+UNSAFE = true
+STATIC = {
+ spit: (path, val) ->
+ path = "#{output}/#{path}"
+ os.execute "mkdir -p '#{dir_base path}'"
+ with io.open path, 'w'
+ \write val
+ \close!
+}
-export STATIC
-STATIC = true
+require 'mmm.mmmfs'
store = get_store store
-tree = Fileder store
-tree = tree\walk startpath if startpath
+root = Fileder store
+BROWSER = :root
+
+print "rendering to #{output}"
+
+style_url = (root\walk '/static/style')\gett 'URL -> text/css'
+hljs_url = (root\walk '/static/highlight-pack')\gett 'URL -> text/javascript'
+STATIC.style = "<link rel=\"stylesheet\" type=\"text/css\" href=\"#{style_url}\" />"
+STATIC.scripts = "
+ <script type=\"text/javascript\" src=\"#{hljs_url}\"></script>
+ <script type=\"text/javascript\">hljs.initHighlighting()</script>"
+
+tree = root\walk startpath or ''
for fileder in coroutine.wrap tree\iterate
print "rendering '#{fileder.path}'..."
- os.execute "mkdir -p 'out/#{fileder.path}'"
- with io.open "out/#{fileder.path}/index.html", 'w'
- \write render (fileder\get 'text/html'), fileder
- \close!
+ ok, val = pcall fileder.gett, fileder, 'text/html'
+ if not ok
+ warn "WARN: couldn't render #{fileder}:"
+ warn val
+
+ STATIC.spit "#{fileder.path}/index.html", val
diff --git a/mmm/mmmfs/layout.moon b/mmm/mmmfs/layout.moon
index b69cf75..3694ddd 100644
--- a/mmm/mmmfs/layout.moon
+++ b/mmm/mmmfs/layout.moon
@@ -129,9 +129,9 @@ render = (content, fileder, opts={}) ->
buf = [[
<!DOCTYPE html>
<html>
- <head>
- <link rel="stylesheet" type="text/css" href="/static/style/:text/css" />
- <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:200,400,600" />]]
+ <head>]]
+ buf ..= STATIC.style or [[<link rel="stylesheet" type="text/css" href="/static/style/:text/css" />]]
+ buf ..= [[<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:200,400,600" />]]
buf ..= "
#{get_meta fileder}
</head>
@@ -141,12 +141,13 @@ render = (content, fileder, opts={}) ->
#{content}
#{footer}"
- buf ..= [[
+ buf ..= if STATIC then '' else [[
<script type="text/javascript" src="/static/highlight-pack/:text/javascript"></script>
<script type="text/javascript">hljs.initHighlighting()</script>
<script type="text/javascript" src="//platform.twitter.com/widgets.js" charset="utf-8"></script>]]
buf ..= opts.scripts
+ buf ..= if STATIC then STATIC.scripts else ''
buf ..= "
</body>
</html>"
diff --git a/mmm/mmmfs/plugins/init.moon b/mmm/mmmfs/plugins/init.moon
index 46e3203..acf96e3 100644
--- a/mmm/mmmfs/plugins/init.moon
+++ b/mmm/mmmfs/plugins/init.moon
@@ -235,12 +235,6 @@ converts = {
assert stream\get_body_as_string!
}
{
- inp: '(.+)',
- out: 'URL -> %1',
- cost: 5
- transform: (_, fileder, key) => "#{fileder.path}/#{key.name}:#{@from}"
- }
- {
inp: 'table',
out: 'mmm/dom',
cost: 5
@@ -293,6 +287,16 @@ add_converts 'twitter'
add_converts 'youtube'
add_converts 'cites'
+if STATIC
+ add_converts 'static'
+else
+ table.insert converts, {
+ inp: '(.+)',
+ out: 'URL -> %1',
+ cost: 5
+ transform: (_, fileder, key) => "#{fileder.path}/#{key.name}:#{@from}"
+ }
+
if MODE == 'SERVER'
ok, moon = pcall require, 'moonscript.base'
if ok
diff --git a/mmm/mmmfs/plugins/static.moon b/mmm/mmmfs/plugins/static.moon
new file mode 100644
index 0000000..6ba27fe
--- /dev/null
+++ b/mmm/mmmfs/plugins/static.moon
@@ -0,0 +1,28 @@
+extensions = {
+ 'image/jpeg': 'jpg'
+ 'image/png': 'png'
+
+ 'video/webm': 'webm'
+ 'video/mp4': 'mp4'
+
+ 'text/javascript': 'js'
+ 'text/css': 'css'
+}
+
+{
+ converts: {
+ {
+ inp: '(.+)',
+ out: 'URL -> %1',
+ cost: 5
+ transform: (val, fileder, key) =>
+ escaped_from = @from\gsub '/', '$'
+ if ext = extensions[@from]
+ escaped_from ..= ".#{ext}"
+
+ with url = "#{fileder.path}/#{key.name}:#{escaped_from}"
+ print " rendering asset #{url}"
+ STATIC.spit url, val
+ }
+ }
+}