aboutsummaryrefslogtreecommitdiffstats
path: root/app/init.moon
blob: 5d5f18a4b9086510b18584fb596c7b374a0089de (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
require = relative ...

union = (...) -> with res = {}
  c = 1
  for i = 1, select '#', ...
    tbl = select i, ...
    for val in *tbl
      res[c] = val
      c += 1

map = (f, list) -> [f val for val in *list]

patch_redirs = ->
  redirs =
    'center-of-mass': 'center_of_mass',
    'test-component': 'test_component',
    'play-tags': 'tags',

  { :location } = window
  if (not location.search\find '=') and #location.search > 1
    name = location.search\sub 2
    location.href = redirs[name] or name

client_goto = ->
  { :location } = window
  if module = location.search\match 'client=([%w_]+)'
    document.body.innerHTML = ''
    require "app.#{module}"

articles = {
  {
    name: 'realities'
    desc: 'exploring the nesting relationships of virtual and other realities'
  },
  {
    name: 'mmmfs'
    desc: 'a file and operating system to live in (wip)'
    render: 'client'
  },
}

animations = {
  {
    name: 'twisted'
    desc: 'pseudo 3d animation'
  },
  {
    name: 'koch'
    desc: "lil' fractal thing"
  },
}

experiments = {
  {
    name: 'center_of_mass'
    desc: 'aligning characters by their centers of mass'
  },
  {
    name: 'tags'
    desc: 'organizing files with Functional Tags'
  },
}

meta = {
  {
    name: 'todo'
    desc: 'Todo MVC with the mmm UI framework'
  },
  {
    name: 'test_component'
    desc: 'test suite for the mmm reactive UI framework'
  },
}

content = {
  { 'articles', articles }
  { 'animations', animations }
  { 'experiments', experiments }
  { 'meta', meta }
}

index = {
  name: 'index'
  route: ''
  dest: 'index.html'
  render: =>
    import h1, h3, div, b, p, a, br, ul, tt, li, img from require 'lib.html'
    import opairs from require 'lib.ordered'

    moon = '\xe2\x98\xbd'

    -- redirects for old-style URIs
    on_client patch_redirs

    iconlink = (href, src, alt, style) -> a {
      class: 'iconlink',
      :href,
      target: '_blank',
      img :src, :alt, :style
    }

    -- menu
    append h1 {
      style: {
        position: 'relative',
        'border-bottom': '1px solid #000'
      },
      'mmm',
      div {
        class: 'icons',
        iconlink 'https://github.com/s-ol/mmm', 'https://cdn.jsdelivr.net/npm/simple-icons@latest/icons/github.svg',
        iconlink 'https://twitter.com/S0lll0s', 'https://cdn.jsdelivr.net/npm/simple-icons@latest/icons/twitter.svg',
        iconlink 'https://webring.xxiivv.com/#random', 'https://webring.xxiivv.com/icon.black.svg', 'webring',
          { height: '0.9em', 'margin-left': '.04em' }
      }
    }

    append p {
      tt 'mmm'
      ' is not the '
      tt 'www'
      ', because it runs on '
      a { 'MoonScript', href: 'https://moonscript.org' }
      '.'
      br!
      'You can find the source code of everything '
      a { 'here', href: 'https://github.com/s-ol/mmm' }
      '.'
    }

    for { category, routes } in *content
      append h3 category, style: { 'margin-bottom': '-.5em' }
      append ul for { :name, :desc, :route } in *routes
        li (a name, href: route), ': ', desc

    append p {
      "made with #{moon} by "
      a { 's-ol', href: 'https://twitter.com/S0lll0s' }
    }

    on_client client_goto
}

load = (module) -> require "app.#{module}"

destify = (route) -> with route
  .route or= .name
  .dest or= "#{.route}/index.html"

  if .render == 'client'
    .render = -> on_client load, .name
  .render or= -> require '.' .. .name

routes = map destify, union articles, animations, experiments, meta, { index }
{
  :routes,
  indexed: { r.name, r for r in *routes }
  render: (name) -> require ".#{name}"
}