all repos

olexsmir.xyz @ main

my site, yes, i like lua

olexsmir.xyz/lua/blog/pages.lua(view raw)

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
local a = require "lego.html.attribute"
local c = require "blog.config"
local h = require "lego.html"
local pages = {}

local function themeSwitcherScript()
  local s = [[
    const root = document.documentElement;
    root.dataset.theme = localStorage.theme || 'dark';
    document.getElementById('theme-toggle').onclick = () => {
      root.dataset.theme = root.dataset.theme === 'dark' ? 'light' : 'dark';
      localStorage.theme = root.dataset.theme;
    };
  ]]
  s = s:gsub("  ", "")
  s = vim.split(s, "\n") ---@diagnostic disable-line: cast-local-type
  s = table.concat(s, "")
  return h.el("script", {}, { h.text(s) })
end

---@param o {title:string, desc:string, has_code:boolean, body:lego.HtmlNode[]}
---@return lego.HtmlNode
local function with_page(o)
  return h.el("html", { a.attr("lang", "en") }, {
    h.el("head", {}, {
      h.title({}, { h.text(o.title) }),
      h.meta { a.attr("charset", "utf-8") },
      h.meta {
        a.attr("name", "viewport"),
        a.attr("content", "width=device-width, initial-scale=1.0, viewport-fit=cover"),
      },
      h.link {
        a.attr("rel", "alternate"),
        a.attr("type", "application/atom+xml"),
        a.attr("title", c.feed.subtitle),
        a.href(c.feed.url),
      },
      h.link { a.attr("rel", "stylesheet"), a.href "style.css" },
      o.has_code and h.link { a.attr("rel", "stylesheet"), a.href "chroma.css" } or {},
      h.link { a.attr("rel", "icon"), a.href "favicon.svg" },
      h.meta { a.attr("name", "description"), a.attr("content", o.desc) },
      h.meta { a.attr("property", "og:description"), a.attr("content", o.desc) },
      h.meta { a.attr("property", "og:site_name"), a.attr("content", o.title) },
      h.meta { a.attr("property", "og:title"), a.attr("content", o.title) },
      h.meta { a.attr("property", "og:type"), a.attr("content", "website") },
    }),
    h.el("body", { a.class "home" }, {
      -- h.el("header", {}, {
      --   h.nav({}, {
      --     h.p({}, {
      --       h.a({ a.class "visual-hidden", a.href "#main" }, { "Skip to content" }),
      --       h.a({ a.href "/" }, { h.text "home" }),
      --       h.a({ a.href "/posts" }, { h.text "posts" }),
      --       h.a({ a.href "/feed.xml" }, { h.text "feed" }),
      --       h.el("button", { a.id "theme-toggle" }, { h.text "🌓" }),
      --     }),
      --   }),
      -- }),
      h.main({ a.id "main" }, o.body),
      themeSwitcherScript(),
    }),
  })
end

function pages.home()
  return with_page {
    title = "olexsmir.xyz",
    desc = "olexsmir.xyz home page",
    body = {
      h.h2({}, { "TODO make the site" }),
    },
  }
end

function pages.not_found()
  return with_page {
    title = "Not found",
    desc = "Page you're looking for, not found",
    body = {
      h.h1({}, { h.text "There's nothing here!" }),
      h.p({}, {
        h.text "Go pack to the ",
        h.a({ a.href "/" }, { h.text "home page" }),
      }),
    },
  }
end

function pages.gopkg(name, repo, branch)
  local gomod = c.cname .. "/" .. name
  local go_import = gomod .. " git " .. repo
  local go_source = table.concat({
    gomod,
    repo,
    repo .. "/tree/" .. branch .. "{/dir}",
    repo .. "/blob/" .. branch .. "{/dir}/{file}#L{line}",
  }, " ")

  return h.el("html", {}, {
    h.el("head", {}, {
      h.meta { a.attr("name", "go-import"), a.attr("content", go_import) },
      h.meta { a.attr("name", "go-source"), a.attr("content", go_source) },
    }),
    h.el("body", {}, {
      h.p({}, { "Source: ", h.a({ a.href(repo) }, { repo }) }),
      h.el("code", {}, { "$ go get " .. gomod }),
    }),
  })
end

return pages