aboutsummaryrefslogtreecommitdiff
path: root/themes/simple/layouts/_default/notes.html
blob: 616234e911391b2e025b2c8b691523bb83e1525e (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
{{ define "main" }}
<main role="main" class="container-blog mx-auto px-6 md:p-0">

  <section class="mb-6">
    <h1 class="text-2xl font-bold mb-2">Notes, notes and notes</h1>
    <p class="text-gray-600 italic">
      Notes about things I learn, things I do, things I want to remember,
      but never do. You can subscribe to this
      <a href="/notes.xml" class="underline hover:bg-yellow-100">RSS feed</a>
      which contains only the notes without the blog posts.
    </p>
  </section>

  <hr class="border-2 border-gray-100 mb-8">

  <select id="jump-to-note" class="px-3 py-2 rounded mb-2 bg-gray-100 w-full md:w-auto">
    <option>Jump to note</option>
  </select>

  <!-- List of all notes -->
  <nav itemscope itemtype="https://schema.org/SiteNavigationElement" class="mb-12" role="feed">
    <meta itemprop="name" content="Article list">
    <section>
      {{ range (where .Site.RegularPages "Section" "notes") }}
      <div class="mb-10">
        <article class="mb-5 single note" itemscope itemtype="http://schema.org/Article">
          <h2 class="text-xl font-medium notes-heading">{{.Title}}</h2>
          <p class="text-gray-600 _italic text-sm flex flex-col md:flex-row gap-1">
            <time datetime="{{ .Date.Format "2006-01-02" }}" itemprop="datePublished">
              {{ .Date.Format "Monday Jan 2, 2006" }}
            </time>

            {{ if .Params.tags }}
            <span class="hidden md:inline-block">
              <span>with tags</span>
              <span class="inline-flex flex-row gap-1">
                <span>(</span>
                {{ range .Params.tags }}
                  <span>{{ . }}</span>
                {{ end }}
                <span>)</span>
              </span>
            </span>
            {{ end }}
          <div class="content">
            {{ .Content | safeHTML }}
          </div>
        </article>
      </div>
      {{ end }}
    </section>
  </nav>

  <script>
    try {
      const notes = document.querySelectorAll('h2');
      const select = document.querySelector('#jump-to-note');

      notes.forEach(note => {
        const id = note.innerText.toLowerCase().replace(/ /g, '-').replace(/[^\w-]+/g, '');
        note.id = id;
        note.innerHTML = `<a href="#${id}"></a>${note.innerHTML}`;

        const option = document.createElement('option');
        option.value = id;
        option.innerText = note.innerText;
        select.appendChild(option);

        select.addEventListener('change', () => {
          window.location.hash = select.value;
        });
      });
    } catch (error) {
      console.error(error);
    }
  </script>

</main>
{{ end }}