aboutsummaryrefslogtreecommitdiffstats
path: root/root/$mmm/plugins/layout/converts: text$lua -> table.lua
blob: 46fa32a2e4f182b315615ccaaaca5752c7fbe489 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
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('mmmfs', {
            class = 'bold'
          }),
          '​',
          '.s‑ol.nu'
        })
      }),
      "a hypermedia information system."
    })
  })
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'),
    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    <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://mmm.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 .. "\n    " .. tostring(opts.meta) .. "\n    " .. tostring(get_scripts(fileder)) .. "\n  </head>\n  <body>\n    " .. tostring(gen_header()) .. "\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
  }
}