aboutsummaryrefslogtreecommitdiffstats
path: root/root
diff options
context:
space:
mode:
authors-ol <s+removethis@s-ol.nu>2020-12-03 16:38:43 +0000
committers-ol <s+removethis@s-ol.nu>2020-12-03 16:38:43 +0000
commite0a0b25f6586cdf1b1284d97bedadfce5535ba96 (patch)
tree50cf646dc673faeda648e7135d84e46f2dbd5262 /root
parentfix typo break text/html+interactive (diff)
downloadmmm-e0a0b25f6586cdf1b1284d97bedadfce5535ba96.tar.gz
mmm-e0a0b25f6586cdf1b1284d97bedadfce5535ba96.zip
move plugins into root
Diffstat (limited to 'root')
-rw-r--r--root/$mmm/plugins/cites/converts: text$moonscript -> table.moon73
-rw-r--r--root/$mmm/plugins/code/converts: text$moonscript -> table.moon90
-rw-r--r--root/$mmm/plugins/code/scripts: text$html+frag.html5
-rw-r--r--root/$mmm/plugins/gltf/converts: text$moonscript -> table.moon16
-rw-r--r--root/$mmm/plugins/gltf/scripts: text$html+frag.html2
-rw-r--r--root/$mmm/plugins/json/converts: text$moonscript -> table.moon54
-rw-r--r--root/$mmm/plugins/markdown/converts: text$moonscript -> table.moon67
-rw-r--r--root/$mmm/plugins/markdown/scripts: text$html+frag.html1
-rw-r--r--root/$mmm/plugins/mermaid/converts: text$moonscript -> table.moon29
-rw-r--r--root/$mmm/plugins/mermaid/scripts: text$html+frag.html1
-rw-r--r--root/$mmm/plugins/static/converts: text$moonscript -> table.moon34
-rw-r--r--root/$mmm/plugins/twitter/converts: text$moonscript -> table.moon21
-rw-r--r--root/$mmm/plugins/youtube/converts: text$moonscript -> table.moon25
-rw-r--r--root/$order2
14 files changed, 419 insertions, 1 deletions
diff --git a/root/$mmm/plugins/cites/converts: text$moonscript -> table.moon b/root/$mmm/plugins/cites/converts: text$moonscript -> table.moon
new file mode 100644
index 0000000..73a6580
--- /dev/null
+++ b/root/$mmm/plugins/cites/converts: text$moonscript -> table.moon
@@ -0,0 +1,73 @@
+import div, span, sup, a, i, b from require 'mmm.dom'
+
+parse_bibtex = (src) ->
+ type, key, kv = src\match '@(%w+){(.-),(.*)}'
+ with info = { _type: type, _key: key }
+ for key, val in kv\gmatch '([a-z]-)%s*=%s*(%b{})'
+ val\sub 2, -2
+ info[key] = val\gsub '[{}]', ''
+ for key, val in kv\gmatch '([a-z]-)%s*=%s*(%d+)'
+ info[key] = val
+
+title = () =>
+ assert @title, "cite doesn't have title"
+ inner = i @title
+ if @url
+ a inner, href: @url, style: display: 'inline'
+ else
+ b inner
+
+format_full = () =>
+ tt = title @
+ dot, com = if @title\match '[.?!]$' then '', '' else '.', ','
+
+ @author or= 'N. N.'
+
+ switch @_type
+ when 'book', 'article'
+ span with setmetatable {}, __index: table
+ \insert "#{@author} (#{@year}), "
+ \insert tt
+ if @journal
+ \insert "#{dot} "
+ \insert i @journal
+ \insert ", volume #{@volume}" if @volume
+ else if @series
+ \insert "#{dot} "
+ \insert i @series
+ \insert ", No. #{@number}" if @number
+ \insert ", pages #{@pages}" if @pages
+ \insert "#{dot} #{@publisher}" if @publisher
+ if @doi
+ \insert "#{dot} "
+ \insert a "doi:#{@doi}", href: "https://doi.org/#{@doi}"
+ when 'web', 'online'
+ span with setmetatable {}, __index: table
+ \insert "#{@author}"
+ \insert " (#{@year})" if @year
+ \insert ", "
+ \insert tt
+ \insert "#{com} #{@url}"
+ \insert " from #{@visited}" if @visited
+ else
+ span with setmetatable {}, __index: table
+ \insert "#{@author} (#{@year}), "
+ \insert tt
+ \insert "#{dot} #{@publisher}" if @publisher
+ span tbl
+{
+ {
+ inp: 'cite/doi'
+ out: 'URL -> text/bibtex'
+ cost: 0.1
+ transform: (doi) =>
+ doi = doi\match '(10%.%d%d%d%d%d?%d?%d?%d?%d?/[%d%w%.%-_:;%(%)]+)'
+ "http://api.crossref.org/works/#{doi}/transform/application/x-bibtex"
+ }
+ {
+ inp: 'text/bibtex'
+ out: 'mmm/dom'
+ cost: 1
+ transform: (bib) => format_full parse_bibtex bib
+ }
+}
diff --git a/root/$mmm/plugins/code/converts: text$moonscript -> table.moon b/root/$mmm/plugins/code/converts: text$moonscript -> table.moon
new file mode 100644
index 0000000..851efba
--- /dev/null
+++ b/root/$mmm/plugins/code/converts: text$moonscript -> table.moon
@@ -0,0 +1,90 @@
+import pre, div, button from require 'mmm.dom'
+import languages from require 'mmm.highlighting'
+
+class Editor
+ o = if MODE == 'CLIENT'
+ mkobj = window\eval "(function () { return {}; })"
+ (tbl) ->
+ with obj = mkobj!
+ for k,v in pairs(tbl)
+ obj[k] = v
+
+ EDITOR: true
+
+ new: (value, mode, @fileder, @key) =>
+ @node = div class: 'editor'
+
+ @saveBtn = with button 'save'
+ .disabled = true
+ .onclick = (_, e) -> @save e
+
+ @cm = window\CodeMirror @node, o {
+ :value
+ :mode
+ lineNumber: true
+ lineWrapping: true
+ autoRefresh: true
+ theme: 'hybrid'
+ }
+
+ @lastSave = @cm\getDoc!\changeGeneration true
+
+ @cm\on 'changes', (_, mirr) ->
+ doc = @cm\getDoc!
+ @saveBtn.disabled = doc\isClean @lastSave
+
+ window\clearTimeout @timeout if @timeout
+ @timeout = window\setTimeout (-> @change!), 300
+
+ change: =>
+ @timeout = nil
+ doc = @cm\getDoc!
+
+ if @lastPreview and doc\isClean @lastPreview
+ -- no changes since last event
+ return
+
+ @lastPreview = doc\changeGeneration!
+ value = doc\getValue!
+
+ @fileder.facets[@key] = value
+ BROWSER\refresh!
+
+ save: (e) =>
+ e\preventDefault!
+
+ doc = @cm\getDoc!
+ @fileder\set @key, doc\getValue!
+ @lastSave = doc\changeGeneration true
+
+[[
+ editors: if MODE == 'CLIENT' then {
+ {
+ inp: 'text/([^ ]*).*'
+ out: 'mmm/dom'
+ cost: 0
+ transform: (value, fileder, key) =>
+ mode = @from\match @convert.inp
+ Editor value, mode, fileder, key
+ }
+ {
+ inp: 'URL.*'
+ out: 'mmm/dom'
+ cost: 0
+ transform: (value, fileder, key) =>
+ Editor value, nil, fileder, key
+ }
+ }
+]]
+
+-- syntax-highlighted code
+{
+ {
+ inp: 'text/([^ ]*).*'
+ out: 'mmm/dom'
+ cost: 5
+ transform: (val) =>
+ lang = @from\match @convert.inp
+ pre languages[lang] val
+ }
+}
diff --git a/root/$mmm/plugins/code/scripts: text$html+frag.html b/root/$mmm/plugins/code/scripts: text$html+frag.html
new file mode 100644
index 0000000..68d780b
--- /dev/null
+++ b/root/$mmm/plugins/code/scripts: text$html+frag.html
@@ -0,0 +1,5 @@
+ <link rel="stylesheet" type="text/css" href="//unpkg.com/codemirror@5.49.2/lib/codemirror.css" />
+ <script type="text/javascript" src="//unpkg.com/codemirror@5.49.2/lib/codemirror.js"></script>
+ <script type="text/javascript" src="//unpkg.com/codemirror@5.49.2/mode/lua/lua.js"></script>
+ <script type="text/javascript" src="//unpkg.com/codemirror@5.49.2/mode/markdown/markdown.js"></script>
+ <script type="text/javascript" src="//unpkg.com/codemirror@5.49.2/addon/display/autorefresh.js"></script>
diff --git a/root/$mmm/plugins/gltf/converts: text$moonscript -> table.moon b/root/$mmm/plugins/gltf/converts: text$moonscript -> table.moon
new file mode 100644
index 0000000..1036eee
--- /dev/null
+++ b/root/$mmm/plugins/gltf/converts: text$moonscript -> table.moon
@@ -0,0 +1,16 @@
+dom = require 'mmm.dom'
+
+{
+ {
+ inp: 'URL -> model/gltf-binary'
+ out: 'mmm/dom'
+ cost: 1
+ transform: (href) =>
+ dom['model-viewer'] {
+ src: href
+ 'auto-rotate': true
+ 'camera-controls': true
+ 'camera-orbit': "548.2deg 117deg 282.4m"
+ }
+ }
+}
diff --git a/root/$mmm/plugins/gltf/scripts: text$html+frag.html b/root/$mmm/plugins/gltf/scripts: text$html+frag.html
new file mode 100644
index 0000000..d2b1e44
--- /dev/null
+++ b/root/$mmm/plugins/gltf/scripts: text$html+frag.html
@@ -0,0 +1,2 @@
+ <script type="module" src="https://unpkg.com/@google/model-viewer/dist/model-viewer.min.js"></script>
+ <script nomodule src="https://unpkg.com/@google/model-viewer/dist/model-viewer-legacy.js"></script>
diff --git a/root/$mmm/plugins/json/converts: text$moonscript -> table.moon b/root/$mmm/plugins/json/converts: text$moonscript -> table.moon
new file mode 100644
index 0000000..7b150a5
--- /dev/null
+++ b/root/$mmm/plugins/json/converts: text$moonscript -> table.moon
@@ -0,0 +1,54 @@
+encode = (obj) ->
+ switch type obj
+ when 'string'
+ string.format '%q', obj
+ when 'table'
+ if obj[1] or not next obj
+ "[#{table.concat [encode c for c in *obj], ','}]"
+ else
+ "{#{table.concat ["#{encode k}: #{encode v}" for k,v in pairs obj], ', '}}"
+ when 'number'
+ tostring obj
+ when 'boolean'
+ tostring obj
+ when 'nil'
+ 'null'
+ else
+ error "unknown type '#{type obj}'"
+
+decode = if MODE == 'CLIENT'
+ import Array, Object, JSON from js.global
+
+ fix = (val) ->
+ switch type val
+ when 'userdata'
+ if Array\isArray val
+ [fix x for x in js.of val]
+ else
+ {(fix e[0]), (fix e[1]) for e in js.of Object\entries(val)}
+ else
+ val
+
+ encode
+ decode = (str) -> fix JSON\parse str
+else if cjson = require 'cjson'
+ cjson.decode
+else
+ warn 'only partial JSON support, please install cjson'
+
+
+{
+ {
+ inp: 'table',
+ out: 'text/json',
+ cost: 2
+ transform: (val) => encode val
+ }
+ if decode
+ {
+ inp: 'text/json'
+ out: 'table'
+ cost: 1
+ transform: (val) => decode val
+ }
+}
diff --git a/root/$mmm/plugins/markdown/converts: text$moonscript -> table.moon b/root/$mmm/plugins/markdown/converts: text$moonscript -> table.moon
new file mode 100644
index 0000000..4e0da31
--- /dev/null
+++ b/root/$mmm/plugins/markdown/converts: text$moonscript -> table.moon
@@ -0,0 +1,67 @@
+markdown = if MODE == 'SERVER'
+ success, discount = pcall require, 'discount'
+ assert success, "couldn't require 'discount'"
+
+ (md) ->
+ res = assert discount.compile md, 'githubtags', 'fencedcode'
+ res.body
+else
+ assert window and window.marked, "marked.js not found"
+
+ o = do
+ mkobj = window\eval "(function () { return {}; })"
+ (tbl) ->
+ with obj = mkobj!
+ for k,v in pairs(tbl)
+ obj[k] = v
+
+ trim = (str) -> str\match '^ *(..-) *$'
+
+ window.marked\setOptions o {
+ gfm: true
+ smartypants: true
+ langPrefix: 'lang-'
+ highlight: (code, lang) =>
+ code = trim code
+ result = if lang and #lang > 0
+ window.hljs\highlight lang, code, true
+ else
+ window.hljs\highlightAuto code
+
+ result.value
+ }
+
+ window\marked
+
+assert markdown, "no markdown implementation found"
+
+{
+ {
+ inp: 'text/markdown'
+ out: 'text/html+frag'
+ cost: 1
+ transform: (md) => "<div class=\"markdown\">#{markdown md}</div>"
+ }
+ {
+ inp: 'text/markdown%+sidenotes'
+ out: 'text/html+frag'
+ cost: 1
+ transform: (md) => "<div class=\"markdown sidenote-container\">#{markdown md}</div>"
+ }
+ {
+ inp: 'text/markdown%+wide'
+ out: 'text/html+frag'
+ cost: 1
+ transform: (md) => "<div class=\"markdown wide\">#{markdown md}</div>"
+ }
+ {
+ inp: 'text/markdown%+span'
+ out: 'text/html+frag'
+ cost: 1
+ transform: (source) =>
+ html = markdown source
+ html = html\gsub '^%s*<p>%s*', '<span>'
+ html = html\gsub '%s*</p>%s*$', '</span>'
+ html
+ }
+}
diff --git a/root/$mmm/plugins/markdown/scripts: text$html+frag.html b/root/$mmm/plugins/markdown/scripts: text$html+frag.html
new file mode 100644
index 0000000..5bfb275
--- /dev/null
+++ b/root/$mmm/plugins/markdown/scripts: text$html+frag.html
@@ -0,0 +1 @@
+ <script type="text/javascript" src="//unpkg.com/marked@0.7.0/marked.min.js"></script>
diff --git a/root/$mmm/plugins/mermaid/converts: text$moonscript -> table.moon b/root/$mmm/plugins/mermaid/converts: text$moonscript -> table.moon
new file mode 100644
index 0000000..1eb695e
--- /dev/null
+++ b/root/$mmm/plugins/mermaid/converts: text$moonscript -> table.moon
@@ -0,0 +1,29 @@
+-- assert window and window.mermaid, "mermaid.js not found"
+if not (window and window.mermaid)
+ return
+
+window.mermaid\initialize {
+ startOnLoad: false
+ fontFamily: 'monospace'
+}
+
+id_counter = 1
+
+{
+ {
+ inp: 'text/mermaid-graph'
+ out: 'mmm/dom'
+ cost: 1
+ transform: (source, fileder, key) =>
+ id_counter += 1
+ id = "mermaid-#{id_counter}"
+ with container = document\createElement 'div'
+ cb = (svg) =>
+ .innerHTML = svg
+ .firstElementChild.style.width = '100%'
+ .firstElementChild.style.height = 'auto'
+
+ window\setImmediate (_) ->
+ window.mermaid\render id, source, cb, container
+ }
+}
diff --git a/root/$mmm/plugins/mermaid/scripts: text$html+frag.html b/root/$mmm/plugins/mermaid/scripts: text$html+frag.html
new file mode 100644
index 0000000..282fbd5
--- /dev/null
+++ b/root/$mmm/plugins/mermaid/scripts: text$html+frag.html
@@ -0,0 +1 @@
+ <script type="text/javascript" src="//unpkg.com/mermaid@8.4.0/dist/mermaid.min.js"></script>
diff --git a/root/$mmm/plugins/static/converts: text$moonscript -> table.moon b/root/$mmm/plugins/static/converts: text$moonscript -> table.moon
new file mode 100644
index 0000000..e230856
--- /dev/null
+++ b/root/$mmm/plugins/static/converts: text$moonscript -> table.moon
@@ -0,0 +1,34 @@
+if not STATIC
+ return
+
+extensions = {
+ 'image/jpeg': 'jpg'
+ 'image/png': 'png'
+ 'image/svg+xml': 'svg'
+
+ 'video/webm': 'webm'
+ 'video/mp4': 'mp4'
+
+ 'text/javascript': 'js'
+ 'text/css': 'css'
+
+ 'model/gltf-binary': 'glb'
+}
+
+{
+ {
+ inp: '(.+)',
+ out: 'URL -> %1',
+ cost: 5
+ transform: (val, fileder, key) =>
+ escaped_from = @from\gsub '/', '_'
+ if ext = extensions[@from]
+ escaped_from ..= ".#{ext}"
+
+ prefix = STATIC.root or ''
+
+ prefix .. with url = "#{fileder.path}/#{key.name}:#{escaped_from}"
+ print " rendering asset #{url}"
+ STATIC.spit url, val
+ }
+}
diff --git a/root/$mmm/plugins/twitter/converts: text$moonscript -> table.moon b/root/$mmm/plugins/twitter/converts: text$moonscript -> table.moon
new file mode 100644
index 0000000..4821823
--- /dev/null
+++ b/root/$mmm/plugins/twitter/converts: text$moonscript -> table.moon
@@ -0,0 +1,21 @@
+import div, blockquote, a from require 'mmm.dom'
+import iframe from require 'mmm.dom'
+
+{
+ {
+ inp: 'URL -> twitter/tweet'
+ out: 'mmm/dom'
+ cost: -4
+ transform: (href) =>
+ user, id = assert (href\match 'twitter.com/([^/]-)/status/(%d*)'), "couldn't parse twitter/tweet URL: '#{href}'"
+
+ iframe {
+ width: 550
+ height: 560
+ border: 0
+ frameBorder: 0
+ allowfullscreen: true
+ src: "//twitframe.com/show?url=https%3A%2F%2Ftwitter.com%2F#{user}%2F#{id}"
+ }
+ }
+}
diff --git a/root/$mmm/plugins/youtube/converts: text$moonscript -> table.moon b/root/$mmm/plugins/youtube/converts: text$moonscript -> table.moon
new file mode 100644
index 0000000..8983730
--- /dev/null
+++ b/root/$mmm/plugins/youtube/converts: text$moonscript -> table.moon
@@ -0,0 +1,25 @@
+import iframe from require 'mmm.dom'
+
+{
+ {
+ inp: 'URL -> youtube/video'
+ out: 'mmm/dom'
+ cost: -4
+ transform: (link) =>
+ id = link\match 'youtu%.be/([^/]+)'
+ id or= link\match 'youtube.com/watch.*[?&]v=([^&]+)'
+ id or= link\match 'youtube.com/[ev]/([^/]+)'
+ id or= link\match 'youtube.com/embed/([^/]+)'
+
+ assert id, "couldn't parse youtube URL: '#{link}'"
+
+ iframe {
+ width: 560
+ height: 315
+ border: 0
+ frameborder: 0
+ allowfullscreen: true
+ src: "//www.youtube.com/embed/#{id}"
+ }
+ }
+}
diff --git a/root/$order b/root/$order
index 23c4745..4d1bfa6 100644
--- a/root/$order
+++ b/root/$order
@@ -6,5 +6,5 @@ games
projects
experiments
meta
-static
portfolio
+static