From 6e568c6a75d8f94a87fa9520cf073d1512753c10 Mon Sep 17 00:00:00 2001 From: s-ol Date: Mon, 28 Mar 2022 15:45:38 +0200 Subject: move layout into user content --- build/server.moon | 4 +- mmm/mmmfs/builtins.moon | 9 - mmm/mmmfs/layout.moon | 167 ---------------- .../plugins/layout/converts: text$lua -> table.lua | 209 +++++++++++++++++++++ .../layout/converts: text$moonscript -> table.moon | 180 ++++++++++++++++++ 5 files changed, 391 insertions(+), 178 deletions(-) delete mode 100644 mmm/mmmfs/layout.moon create mode 100644 root/$mmm/plugins/layout/converts: text$lua -> table.lua create mode 100644 root/$mmm/plugins/layout/converts: text$moonscript -> table.moon diff --git a/build/server.moon b/build/server.moon index 7c03efd..5dc4eed 100644 --- a/build/server.moon +++ b/build/server.moon @@ -15,7 +15,6 @@ UNSAFE = true import dir_base, Key, Fileder from require 'mmm.mmmfs.fileder' import convert, MermaidDebugger from require 'mmm.mmmfs.conversion' import get_store from require 'mmm.mmmfs.stores' -import render from require 'mmm.mmmfs.layout' import Browser from require 'mmm.mmmfs.browser' import init_cache from require 'mmm.mmmfs.cache' import decodeURI from require 'http.util' @@ -63,7 +62,7 @@ class Server root = @root or Fileder @store browser = Browser root, fileder.path, facet.name - render browser\todom!, fileder, noview: true, scripts: " + scripts = " @@ -85,6 +84,7 @@ class Server if not ok then error(browser) end end) " + convert 'mmm/dom+noview', 'text/html', scripts .. browser\todom!, fileder, facet.name handle_debug: (fileder, facet) => debugger = MermaidDebugger! diff --git a/mmm/mmmfs/builtins.moon b/mmm/mmmfs/builtins.moon index 9bff97a..763c722 100644 --- a/mmm/mmmfs/builtins.moon +++ b/mmm/mmmfs/builtins.moon @@ -1,6 +1,5 @@ import div, pre, code, img, video, span, source from require 'mmm.dom' import find_fileder, link_to, embed from (require 'mmm.mmmfs.util') require 'mmm.dom' -import render from require 'mmm.mmmfs.layout' import tohtml from require 'mmm.component' -- fix JS null values @@ -71,14 +70,6 @@ converts = { cost: 3 transform: (node) => if MODE == 'SERVER' then node else node.outerHTML } - { - -- inp: 'text/html%+frag', - -- @TODO: this doesn't feel right... maybe mmm/dom has to go? - inp: 'mmm/dom', - out: 'text/html', - cost: 3 - transform: (html, fileder) => render html, fileder - } { inp: 'text/html%+frag', out: 'mmm/dom', diff --git a/mmm/mmmfs/layout.moon b/mmm/mmmfs/layout.moon deleted file mode 100644 index 20b5b72..0000000 --- a/mmm/mmmfs/layout.moon +++ /dev/null @@ -1,167 +0,0 @@ -import header, aside, footer, div, svg, script, g, circle, h1, span, b, a, img from require 'mmm.dom' -import navigate_to from (require 'mmm.mmmfs.util') require 'mmm.dom' -import get_plugins from require 'mmm.mmmfs.meta' - -pick = (...) -> - num = select '#', ... - i = math.ceil math.random! * num - (select i, ...) - -iconlink = (href, src, alt, style) -> a { - class: 'iconlink', - target: '_blank', - rel: 'me', - :href, - img :src, :alt, :style -} - -logo = svg { - class: 'sun' - viewBox: '-0.75 -1 1.5 2' - xmlns: 'http://www.w3.org/2000/svg' - baseProfile: 'full' - version: '1.1' - - g { - transform: 'translate(0 .18)' - - g { class: 'circle out', circle r: '.6', fill: 'none', 'stroke-width': '.12' } - g { class: 'circle in', circle r: '.2', stroke: 'none' } - } -} - -gen_header = -> - header { - div { - h1 { - navigate_to '', logo - span { - span 'mmm', class: 'bold' - '​' - '.s‑ol.nu' - } - } - -- span "fun stuff with code and wires" - table.concat { - pick 'fun', 'cool', 'weird', 'interesting', 'new', 'pleasant' - pick 'stuff', 'things', 'projects', 'experiments', 'visuals', 'ideas' - pick "with", 'and' - pick 'mostly code', 'code and wires', 'silicon', 'electronics', 'shaders', - 'oscilloscopes', 'interfaces', 'hardware', 'FPGAs' - }, ' ' - } - aside { - navigate_to '/about', 'about me' - navigate_to '/portfolio', 'portfolio' - navigate_to '/games', 'games' - navigate_to '/projects', 'other' - a { - href: 'mailto:s%20[removethis]%20[at]%20s-ol.nu' - 'contact' - script " - var l = document.currentScript.parentElement; - l.href = l.href.replace('%20[at]%20', '@'); - l.href = l.href.replace('%20[removethis]', '') + '?subject=Hey there :)'; - " - } - } - } - -footer = footer { - span { - 'made with \xe2\x98\xbd by ' - a 's-ol', href: 'https://twitter.com/S0lll0s' - ", #{os.date '%Y'}" - } - div { - class: 'icons', - iconlink 'https://github.com/s-ol', 'https://cdn.jsdelivr.net/npm/simple-icons@latest/icons/github.svg', 'github' - iconlink 'https://merveilles.town/@s_ol', 'https://cdn.jsdelivr.net/npm/simple-icons@latest/icons/mastodon.svg', 'mastodon' - iconlink 'https://twitter.com/S0lll0s', 'https://cdn.jsdelivr.net/npm/simple-icons@latest/icons/twitter.svg', 'twitter' - iconlink 'https://webring.xxiivv.com/#random', 'https://webring.xxiivv.com/icon.black.svg', 'webring', - { height: '1.3em', 'margin-left': '.3em', 'margin-top': '-0.12em' } - } -} - -get_header_tags = => - title = (@get 'title: text/plain') or @gett 'name: alpha' - - l = (str) -> - str = str\gsub '[%s\n]+$', '' - str\gsub '\n', ' ' - e = (str) -> string.format '%q', l str - - meta = " - - #{l title} - " - - if page_meta = @get '_meta: mmm/dom' - meta ..= page_meta - else - meta ..= " - - - - - - " - - if desc = @get 'description: text/plain' - meta ..= " - " - - meta - -get_scripts = => - scripts = '' - for plugin in get_plugins @ - if snippet = plugin\get 'scripts: text/html+frag' - scripts ..= snippet - - scripts - -render = (content, fileder, opts={}) -> - opts.meta or= get_header_tags fileder - opts.scripts or= '' - - unless opts.noview - content = [[ -
-
- ]] .. content .. [[ -
-
- ]] - - buf = [[ - - - ]] - buf ..= if STATIC then STATIC.style else [[]] - buf ..= [[]] - buf ..= " - #{opts.meta} - #{get_scripts fileder} - - - #{gen_header!} - - #{content} - - #{footer}" - buf ..= if STATIC then '' else [[ - - ]] - - buf ..= opts.scripts - buf ..= STATIC.scripts if STATIC - buf ..= " - -" - - buf - -{ - :render -} diff --git a/root/$mmm/plugins/layout/converts: text$lua -> table.lua b/root/$mmm/plugins/layout/converts: text$lua -> table.lua new file mode 100644 index 0000000..196e39e --- /dev/null +++ b/root/$mmm/plugins/layout/converts: text$lua -> table.lua @@ -0,0 +1,209 @@ +local header, aside, footer, div, svg, script, g, circle, h1, span, b, a, img +do + local _obj_0 = require('mmm.dom') + header, aside, footer, div, svg, script, g, circle, h1, span, b, a, img = _obj_0.header, _obj_0.aside, _obj_0.footer, _obj_0.div, _obj_0.svg, _obj_0.script, _obj_0.g, _obj_0.circle, _obj_0.h1, _obj_0.span, _obj_0.b, _obj_0.a, _obj_0.img +end +local navigate_to +navigate_to = (require('mmm.mmmfs.util'))(require('mmm.dom')).navigate_to +local get_plugins +get_plugins = require('mmm.mmmfs.meta').get_plugins +local pick +pick = function(...) + local num = select('#', ...) + local i = math.ceil(math.random() * num) + return (select(i, ...)) +end +local iconlink +iconlink = function(href, src, alt, style) + return a({ + class = 'iconlink', + target = '_blank', + rel = 'me', + href = href, + img({ + src = src, + alt = alt, + style = style + }) + }) +end +local logo = svg({ + class = 'sun', + viewBox = '-0.75 -1 1.5 2', + xmlns = 'http://www.w3.org/2000/svg', + baseProfile = 'full', + version = '1.1', + g({ + transform = 'translate(0 .18)', + g({ + class = 'circle out', + circle({ + r = '.6', + fill = 'none', + ['stroke-width'] = '.12' + }) + }), + g({ + class = 'circle in', + circle({ + r = '.2', + stroke = 'none' + }) + }) + }) +}) +local gen_header +gen_header = function() + return header({ + div({ + h1({ + navigate_to('', logo), + span({ + span('mmm', { + class = 'bold' + }), + '​', + '.s‑ol.nu' + }) + }), + table.concat({ + pick('fun', 'cool', 'weird', 'interesting', 'new', 'pleasant'), + pick('stuff', 'things', 'projects', 'experiments', 'visuals', 'ideas'), + pick("with", 'and'), + pick('mostly code', 'code and wires', 'silicon', 'electronics', 'shaders', 'oscilloscopes', 'interfaces', 'hardware', 'FPGAs') + }, ' ') + }), + aside({ + navigate_to('/about', 'about me'), + navigate_to('/portfolio', 'portfolio'), + navigate_to('/games', 'games'), + navigate_to('/projects', 'other'), + a({ + href = 'mailto:s%20[removethis]%20[at]%20s-ol.nu', + 'contact', + script("\n var l = document.currentScript.parentElement;\n l.href = l.href.replace('%20[at]%20', '@');\n l.href = l.href.replace('%20[removethis]', '') + '?subject=Hey there :)';\n ") + }) + }) + }) +end +footer = footer({ + span({ + 'made with \xe2\x98\xbd by ', + a('s-ol', { + href = 'https://twitter.com/S0lll0s' + }), + ", " .. tostring(os.date('%Y')) + }), + div({ + class = 'icons', + iconlink('https://github.com/s-ol', 'https://cdn.jsdelivr.net/npm/simple-icons@latest/icons/github.svg', 'github'), + iconlink('https://merveilles.town/@s_ol', 'https://cdn.jsdelivr.net/npm/simple-icons@latest/icons/mastodon.svg', 'mastodon'), + iconlink('https://twitter.com/S0lll0s', 'https://cdn.jsdelivr.net/npm/simple-icons@latest/icons/twitter.svg', 'twitter'), + iconlink('https://webring.xxiivv.com/#random', 'https://webring.xxiivv.com/icon.black.svg', 'webring', { + height = '1.3em', + ['margin-left'] = '.3em', + ['margin-top'] = '-0.12em' + }) + }) +}) +local get_header_tags +get_header_tags = function(self) + local title = (self:get('title: text/plain')) or self:gett('name: alpha') + local l + l = function(str) + str = str:gsub('[%s\n]+$', '') + return str:gsub('\n', ' ') + end + local e + e = function(str) + return string.format('%q', l(str)) + end + local meta = "\n \n " .. tostring(l(title)) .. "\n " + do + local page_meta = self:get('_meta: mmm/dom') + if page_meta then + meta = meta .. page_meta + else + meta = meta .. "\n \n\n \n \n \n " + do + local desc = self:get('description: text/plain') + if desc then + meta = meta .. "\n " + end + end + end + end + return meta +end +local get_scripts +get_scripts = function(self) + local scripts = '' + for plugin in get_plugins(self) do + do + local snippet = plugin:get('scripts: text/html+frag') + if snippet then + scripts = scripts .. snippet + end + end + end + return scripts +end +local render +render = function(content, fileder, opts) + if opts == nil then + opts = { } + end + opts.meta = opts.meta or get_header_tags(fileder) + opts.scripts = opts.scripts or '' + if not (opts.noview) then + content = [[
+
+ ]] .. content .. [[
+
+ ]] + end + local buf = [[ + + ]] + buf = buf .. (function() + if STATIC then + return STATIC.style + else + return [[]] + end + end)() + buf = buf .. [[]] + buf = buf .. "\n " .. tostring(opts.meta) .. "\n " .. tostring(get_scripts(fileder)) .. "\n \n \n " .. tostring(gen_header()) .. "\n\n " .. tostring(content) .. "\n\n " .. tostring(footer) + buf = buf .. (function() + if STATIC then + return '' + else + return [[ + ]] + end + end)() + buf = buf .. opts.scripts + if STATIC then + buf = buf .. STATIC.scripts + end + buf = buf .. "\n \n" + return buf +end +return { + { + inp = 'mmm/dom', + out = 'text/html', + cost = 3, + transform = function(self, html, fileder) + return render(html, fileder) + end + }, + { + inp = 'mmm/dom%+noview', + out = 'text/html', + cost = 3, + transform = function(self, html, fileder) + return render(html, fileder, { noview = true }) + end + } +} diff --git a/root/$mmm/plugins/layout/converts: text$moonscript -> table.moon b/root/$mmm/plugins/layout/converts: text$moonscript -> table.moon new file mode 100644 index 0000000..732f2ea --- /dev/null +++ b/root/$mmm/plugins/layout/converts: text$moonscript -> table.moon @@ -0,0 +1,180 @@ +import header, aside, footer, div, svg, script, g, circle, h1, span, b, a, img from require 'mmm.dom' +import navigate_to from (require 'mmm.mmmfs.util') require 'mmm.dom' +import get_plugins from require 'mmm.mmmfs.meta' + +pick = (...) -> + num = select '#', ... + i = math.ceil math.random! * num + (select i, ...) + +iconlink = (href, src, alt, style) -> a { + class: 'iconlink', + target: '_blank', + rel: 'me', + :href, + img :src, :alt, :style +} + +logo = svg { + class: 'sun' + viewBox: '-0.75 -1 1.5 2' + xmlns: 'http://www.w3.org/2000/svg' + baseProfile: 'full' + version: '1.1' + + g { + transform: 'translate(0 .18)' + + g { class: 'circle out', circle r: '.6', fill: 'none', 'stroke-width': '.12' } + g { class: 'circle in', circle r: '.2', stroke: 'none' } + } +} + +gen_header = -> + header { + div { + h1 { + navigate_to '', logo + span { + span 'mmm', class: 'bold' + '​' + '.s‑ol.nu' + } + } + -- span "fun stuff with code and wires" + table.concat { + pick 'fun', 'cool', 'weird', 'interesting', 'new', 'pleasant' + pick 'stuff', 'things', 'projects', 'experiments', 'visuals', 'ideas' + pick "with", 'and' + pick 'mostly code', 'code and wires', 'silicon', 'electronics', 'shaders', + 'oscilloscopes', 'interfaces', 'hardware', 'FPGAs' + }, ' ' + } + aside { + navigate_to '/about', 'about me' + navigate_to '/portfolio', 'portfolio' + navigate_to '/games', 'games' + navigate_to '/projects', 'other' + a { + href: 'mailto:s%20[removethis]%20[at]%20s-ol.nu' + 'contact' + script " + var l = document.currentScript.parentElement; + l.href = l.href.replace('%20[at]%20', '@'); + l.href = l.href.replace('%20[removethis]', '') + '?subject=Hey there :)'; + " + } + } + } + +footer = footer { + span { + 'made with \xe2\x98\xbd by ' + a 's-ol', href: 'https://twitter.com/S0lll0s' + ", #{os.date '%Y'}" + } + div { + class: 'icons', + iconlink 'https://github.com/s-ol', 'https://cdn.jsdelivr.net/npm/simple-icons@latest/icons/github.svg', 'github' + iconlink 'https://merveilles.town/@s_ol', 'https://cdn.jsdelivr.net/npm/simple-icons@latest/icons/mastodon.svg', 'mastodon' + iconlink 'https://twitter.com/S0lll0s', 'https://cdn.jsdelivr.net/npm/simple-icons@latest/icons/twitter.svg', 'twitter' + iconlink 'https://webring.xxiivv.com/#random', 'https://webring.xxiivv.com/icon.black.svg', 'webring', + { height: '1.3em', 'margin-left': '.3em', 'margin-top': '-0.12em' } + } +} + +get_header_tags = => + title = (@get 'title: text/plain') or @gett 'name: alpha' + + l = (str) -> + str = str\gsub '[%s\n]+$', '' + str\gsub '\n', ' ' + e = (str) -> string.format '%q', l str + + meta = " + + #{l title} + " + + if page_meta = @get '_meta: mmm/dom' + meta ..= page_meta + else + meta ..= " + + + + + + " + + if desc = @get 'description: text/plain' + meta ..= " + " + + meta + +get_scripts = => + scripts = '' + for plugin in get_plugins @ + if snippet = plugin\get 'scripts: text/html+frag' + scripts ..= snippet + + scripts + +render = (content, fileder, opts={}) -> + opts.meta or= get_header_tags fileder + opts.scripts or= '' + + unless opts.noview + content = [[ +
+
+ ]] .. content .. [[ +
+
+ ]] + + buf = [[ + + + ]] + buf ..= if STATIC then STATIC.style else [[]] + buf ..= [[]] + buf ..= " + #{opts.meta} + #{get_scripts fileder} + + + #{gen_header!} + + #{content} + + #{footer}" + buf ..= if STATIC then '' else [[ + + ]] + + buf ..= opts.scripts + buf ..= STATIC.scripts if STATIC + buf ..= " + +" + + buf + +{ + { + -- inp: 'text/html%+frag', + -- @TODO: this doesn't feel right... maybe mmm/dom has to go? + inp: 'mmm/dom', + out: 'text/html', + cost: 3 + transform: (html, fileder) => render html, fileder + }, + { + inp: 'mmm/dom%+noview', + out: 'text/html', + cost: 3 + transform: (html, fileder) => render html, fileder, noview: true + } +} -- cgit v1.2.3