aboutsummaryrefslogtreecommitdiff
path: root/themes/simple/layouts/_default/notes.html
blob: 27ac958adfc4d0d463c97b7b9fd9a5677b285d9b (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
{{ 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">

  <!-- Dropdown selector to jump to note -->
  <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 all unique tags -->
  <nav itemscope itemtype="https://schema.org/SiteNavigationElement" class="mt-6 mb-10" role="feed">
    <meta itemprop="name" content="Tag list">
    <section>
      <ul class="flex flex-wrap gap-2">
        {{ range .Site.Taxonomies.tags }}
        <li>
          <a href="{{ .Page.Permalink }}" class="inline-block px-3 py-1 rounded bg-gray-100 hover:bg-yellow-100">
            {{ .Page.Title }}
          </a>
        </li>
        {{ end }}
      </ul>
    </section>
  </nav>

  <!-- 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">
          <a href="/{{ .Params.url }}">
            <h2 class="text-xl font-medium notes-heading">{{.Title}}</h2>
          </a>
          <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 }}
                  <a href="/tags/{{ . | urlize }}.html">{{ . }}</a>
                {{ 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 }}