diff options
| author | s-ol <s+removethis@s-ol.nu> | 2022-05-08 19:14:58 +0000 |
|---|---|---|
| committer | s-ol <s+removethis@s-ol.nu> | 2022-05-20 08:38:41 +0000 |
| commit | b615a7cf0fc9d81b4b905a9d4e1db0beebdebd3d (patch) | |
| tree | 2bf24f2da1aa80df2534637de10e0fe45aeb80f0 /$mmm/plugins/layout | |
| download | hw.s-ol.nu-b615a7cf0fc9d81b4b905a9d4e1db0beebdebd3d.tar.gz hw.s-ol.nu-b615a7cf0fc9d81b4b905a9d4e1db0beebdebd3d.zip | |
initial commit
Diffstat (limited to '$mmm/plugins/layout')
| -rw-r--r-- | $mmm/plugins/layout/converts: text$lua -> table.lua | 193 | ||||
| -rw-r--r-- | $mmm/plugins/layout/converts: text$moonscript -> table.moon | 164 |
2 files changed, 357 insertions, 0 deletions
diff --git a/$mmm/plugins/layout/converts: text$lua -> table.lua b/$mmm/plugins/layout/converts: text$lua -> table.lua new file mode 100644 index 0000000..2acf8b7 --- /dev/null +++ b/$mmm/plugins/layout/converts: text$lua -> table.lua @@ -0,0 +1,193 @@ +local header, aside, footer, nav, div, svg, script, g, path, ul, li, h1, span, b, a, img +do + local _obj_0 = require('mmm.dom') + header, aside, footer, nav, div, svg, script, g, path, ul, li, h1, span, b, a, img = _obj_0.header, _obj_0.aside, _obj_0.footer, _obj_0.nav, _obj_0.div, _obj_0.svg, _obj_0.script, _obj_0.g, _obj_0.path, _obj_0.ul, _obj_0.li, _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 unpack = unpack or table.unpack +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 0 1 1', + xmlns = 'http://www.w3.org/2000/svg', + baseProfile = 'full', + version = '1.1', + g({ + transform = 'translate(0.5, 0.52)', + g({ + class = 'circle out', + path({ + fill = 'none', + ['stroke-width'] = 0.053, + d = 'M 0.5 0.15625 C 0.44839986 0.15625 0.22697194 0.28343797 0.20117188 0.328125 C 0.17537181 0.37281203 0.1753718 0.62718797 0.20117188 0.671875 C 0.22697195 0.71656203 0.44839986 0.84375 0.5 0.84375 C 0.55160014 0.84375 0.77302806 0.71656203 0.79882812 0.671875 C 0.82462819 0.62718797 0.8246282 0.37281203 0.79882812 0.328125 C 0.77302805 0.28343797 0.55160014 0.15625 0.5 0.15625 z', + transform = 'translate(-0.5, -0.5)' + }) + }), + g({ + class = 'circle in', + path({ + stroke = 'none', + d = 'M 0.50195312 0.38476562 C 0.4851293 0.38476563 0.41466191 0.42683639 0.40625 0.44140625 C 0.39783809 0.45597611 0.39783809 0.53816452 0.40625 0.55273438 C 0.41466191 0.56730423 0.4851293 0.609375 0.50195312 0.609375 C 0.51877695 0.609375 0.59119746 0.56730423 0.59960938 0.55273438 C 0.60802129 0.53816452 0.60802129 0.45597611 0.59960938 0.44140625 C 0.59119746 0.42683639 0.51877695 0.38476562 0.50195312 0.38476562 z', + transform = 'translate(-0.5, -0.5)' + }) + }) + }) +}) +local gen_header +gen_header = function(self) + return header({ + div({ + h1({ + navigate_to('', logo), + span({ + span('kb', { + class = 'bold' + }), + '​', + '.s‑ol.nu' + }) + }), + "low-profile hexagon keyboards." + }) + }) +end +footer = footer({ + span({ + 'made with \xe2\x98\xbd by ', + a('s-ol', { + href = 'https://s-ol.nu' + }), + ", " .. 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') + }) +}) +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 <meta charset=\"UTF-8\">\n <title>" .. tostring(l(title)) .. "</title>\n " + do + local page_meta = self:get('_meta: mmm/dom') + if page_meta then + meta = meta .. page_meta + else + meta = meta .. "\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n\n <meta property=\"og:title\" content=" .. tostring(e(title)) .. " />\n <meta property=\"og:type\" content=\"website\" />\n <meta property=\"og:url\" content=\"https://kb.s-ol.nu" .. tostring(self.path) .. "/\" />\n <meta property=\"og:site_name\" content=\"mmm\" />" + do + local desc = self:get('description: text/plain') + if desc then + meta = meta .. "\n <meta property=\"og:description\" content=" .. tostring(e(desc)) .. " />" + 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 = [[ <div class="view main"> + <div class="content"> + ]] .. content .. [[ </div> + </div> + ]] + end + local buf = [[<!DOCTYPE html> +<html> + <head>]] + buf = buf .. (function() + if STATIC then + return STATIC.style + else + return "<link rel=\"stylesheet\" type=\"text/css\" href=\"/static/style/:text/css\" />" + end + end)() + buf = buf .. [[<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:200,400,600" />]] + buf = buf .. "\n " .. tostring(opts.meta) .. "\n " .. tostring(get_scripts(fileder)) .. "\n </head>\n <body>\n " .. tostring(gen_header(fileder)) .. "\n\n " .. tostring(content) .. "\n\n " .. tostring(footer) + buf = buf .. (function() + if STATIC then + return '' + else + return [[ <script type="text/javascript" src="/static/highlight-pack/:text/javascript"></script> + <script type="text/javascript">hljs.initHighlighting()</script>]] + end + end)() + buf = buf .. opts.scripts + if STATIC then + buf = buf .. STATIC.scripts + end + buf = buf .. "\n </body>\n</html>" + 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/$mmm/plugins/layout/converts: text$moonscript -> table.moon b/$mmm/plugins/layout/converts: text$moonscript -> table.moon new file mode 100644 index 0000000..cde34a4 --- /dev/null +++ b/$mmm/plugins/layout/converts: text$moonscript -> table.moon @@ -0,0 +1,164 @@ +import header, aside, footer, nav, div, svg, script, g, path, ul, li, 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' + +unpack or= table.unpack + +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 0 1 1' + xmlns: 'http://www.w3.org/2000/svg' + baseProfile: 'full' + version: '1.1' + + g { + transform: 'translate(0.5, 0.52)' + g { + class: 'circle out', + path fill: 'none', 'stroke-width': 0.053, d: 'M 0.5 0.15625 C 0.44839986 0.15625 0.22697194 0.28343797 0.20117188 0.328125 C 0.17537181 0.37281203 0.1753718 0.62718797 0.20117188 0.671875 C 0.22697195 0.71656203 0.44839986 0.84375 0.5 0.84375 C 0.55160014 0.84375 0.77302806 0.71656203 0.79882812 0.671875 C 0.82462819 0.62718797 0.8246282 0.37281203 0.79882812 0.328125 C 0.77302805 0.28343797 0.55160014 0.15625 0.5 0.15625 z', transform: 'translate(-0.5, -0.5)' + } + + g { + class: 'circle in', + path stroke: 'none', d: 'M 0.50195312 0.38476562 C 0.4851293 0.38476563 0.41466191 0.42683639 0.40625 0.44140625 C 0.39783809 0.45597611 0.39783809 0.53816452 0.40625 0.55273438 C 0.41466191 0.56730423 0.4851293 0.609375 0.50195312 0.609375 C 0.51877695 0.609375 0.59119746 0.56730423 0.59960938 0.55273438 C 0.60802129 0.53816452 0.60802129 0.45597611 0.59960938 0.44140625 C 0.59119746 0.42683639 0.51877695 0.38476562 0.50195312 0.38476562 z', transform: 'translate(-0.5, -0.5)' + } + } +} + +gen_header = => + header { + div { + h1 { + navigate_to '', logo + span { + span 'kb', class: 'bold' + '​' + '.s‑ol.nu' + } + } + "low-profile hexagon keyboards." + }, + } + +footer = footer { + span { + 'made with \xe2\x98\xbd by ' + a 's-ol', href: 'https://s-ol.nu' + ", #{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' + } +} + +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 = " + <meta charset=\"UTF-8\"> + <title>#{l title}</title> + " + + if page_meta = @get '_meta: mmm/dom' + meta ..= page_meta + else + meta ..= " + <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\"> + + <meta property=\"og:title\" content=#{e title} /> + <meta property=\"og:type\" content=\"website\" /> + <meta property=\"og:url\" content=\"https://kb.s-ol.nu#{@path}/\" /> + <meta property=\"og:site_name\" content=\"mmm\" />" + + if desc = @get 'description: text/plain' + meta ..= " + <meta property=\"og:description\" content=#{e desc} />" + + 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 = [[ + <div class="view main"> + <div class="content"> + ]] .. content .. [[ + </div> + </div> + ]] + + buf = [[ +<!DOCTYPE html> +<html> + <head>]] + buf ..= if STATIC then STATIC.style else "<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 ..= " + #{opts.meta} + #{get_scripts fileder} + </head> + <body> + #{gen_header fileder} + + #{content} + + #{footer}" + buf ..= if STATIC then '' else [[ + <script type="text/javascript" src="/static/highlight-pack/:text/javascript"></script> + <script type="text/javascript">hljs.initHighlighting()</script>]] + + buf ..= opts.scripts + buf ..= STATIC.scripts if STATIC + buf ..= " + </body> +</html>" + + 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 + } +} |
