all repos — h3 @ baf92f563fc1fda4a3b4178a97197ab655171a36

A tiny, extremely minimalist JavaScript microframework.

docs/js/app.js

 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
import h3 from "./h3.js";
import marked from "./vendor/marked.js";
import Prism from "./vendor/prism.js";

const labels = {
  overview: "Overview",
  "quick-start": "Quick Start",
  "key-concepts": "Key Concepts",
  tutorial: "Tutorial",
  api: "API",
  about: "About",
};

const badges = {
  "https://img.shields.io/npm/v/@h3rald/h3": "https://www.npmjs.com/package/@h3rald/h3",
  "https://img.shields.io/github/license/h3rald/h3":
    "https://github.com/h3rald/h3/blob/master/LICENSE",
  "https://img.shields.io/travis/h3rald/h3":
    "https://travis-ci.org/github/h3rald/h3",
  "https://img.shields.io/coveralls/github/h3rald/h3":
    "https://coveralls.io/github/h3rald/h3?branch=master",
};

const pages = {};

const fetchPage = async (pages, id, md) => {
  if (!pages[id]) {
    const response = await fetch(md);
    const text = await response.text();
    pages[id] = marked(text);
    h3.redraw();
  }
};

const Page = () => {
  const id = h3.route.path.slice(1);
  const ids = Object.keys(labels);
  const md = ids.includes(id) ? `md/${id}.md` : `md/overview.md`;
  fetchPage(pages, id, md);
  return h3("div.page", [
    Header,
    h3("div.row", [
      h3("input#drawer-control.drawer", { type: "checkbox" }),
      Navigation(id, ids),
      Content(pages[id]),
      Footer,
    ]),
  ]);
};

const Header = () => {
  return h3("header.row.sticky", [
    h3("a.logo.col-sm-1", { href: "#/" }, [
      h3("img", { alt: "H3", src: "images/h3.svg" }),
    ]),
    h3("div.version.col-sm.col-md", [
      h3("div.version-number", "v0.1.0"),
      h3("div.version-label", "“Audacious Andorian“"),
    ]),
    h3("label.drawer-toggle.button.col-sm-last", { for: "drawer-control" }),
  ]);
};

const Footer = () => {
  const images = Object.keys(badges).map((img) =>
    h3("a.badge", { href: badges[img], target: "_blank" }, h3("img", { src: img }))
  );
  return h3("footer", [
    h3("div", [
      "© 2020 Fabio Cevasco · ",
      h3(
        "a",
        {
          href: "H3_DeveloperGuide.htm",
          target: "_blank",
        },
        "Download the Guide"
      ),
    ]),
    h3("div", images),
  ]);
};

const Navigation = (id, ids) => {
  const menu = ids.map((p) =>
    h3(`a${p === id ? ".active" : ""}`, { href: `#/${p}` }, labels[p])
  );
  return h3("nav#navigation.col-md-3", [
    h3("label.drawer-close", { for: "drawer-control" }),
    ...menu,
  ]);
};

const Content = (html) => {
  const content = html
    ? h3("div.content", { $html: html })
    : h3("div.spinner-container", h3("span.spinner"));
  return h3("main.col-sm-12.col-md-9", [
    h3("div.card.fluid", h3("div.section", content)),
  ]);
};

h3.init(Page);
h3.on("$redraw", () => Prism.highlightAll());