aboutsummaryrefslogtreecommitdiff
path: root/cgit/filters/about.sh
blob: f1c660babac0c0c750f5f7ab709f2cfcb0b30b97 (plain) (blame)
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
#!/usr/bin/env sh
# About content filter

set -eu

md_to_html() {
  render_discussions_modal
  echo '<div class="markdown">'
  md2html \
    --fpermissive-url-autolinks --fpermissive-www-autolinks \
    --flatex-math --ftasklists --ftables --funderline \
    --github -
  echo '</div>'
}

to_html() {
  case "$(printf '%s' "$1" | tr '[:upper:]' '[:lower:]')" in
    *.markdown|*.mdown|*.md|*.mkd) md_to_html ;;
    *.htm|*.html) exec cat ;;
    *) /usr/lib/cgit/filters/about-formatting.sh "$@" ;;
  esac
}

render_discussions_modal() {
  cat <<'HTML'
    <div class="discussions">
      <button type="button" class="discussions-trigger" command="show-modal" commandfor="discussions">
        Leave a comment
      </button>

      <dialog id="discussions" class="discussions-modal">
        <button type="button" class="discussions-close" command="close" commandfor="discussions">
          Close
        </button>
        <div id="discussions-comment">
          <script src="https://giscus.app/client.js"
            data-repo="phenax/ediblemonad.dev"
            data-repo-id="MDEwOlJlcG9zaXRvcnk3NTY4OTA5MQ=="
            data-category="Repo discussions"
            data-category-id="DIC_kwDOBILsg84DAnGD"
            data-mapping="url"
            data-strict="0"
            data-reactions-enabled="1"
            data-emit-metadata="0"
            data-input-position="bottom"
            data-theme="dark"
            data-lang="en"
            crossorigin="anonymous"
            async>
          </script>
        </div>
      </dialog>
    </div>
HTML
}

(to_html "$@" | /usr/lib/cgit/filters/ediblemonad/html-transform.py) || \
  (echo "<pre>Error rendering markdown</pre>" && cat)