Jacky Zhao
2022-05-03 24d08d580d61363faab495a8a022248a7499dc26
cfg: make SPA optional
5 files modified
20 ■■■■■ changed files
assets/js/search.js 3 ●●●● patch | view | raw | blame | history
data/config.yaml 1 ●●●● patch | view | raw | blame | history
layouts/partials/backlinks.html 1 ●●●● patch | view | raw | blame | history
layouts/partials/graph.html 11 ●●●●● patch | view | raw | blame | history
layouts/partials/head.html 4 ●●●● patch | view | raw | blame | history
assets/js/search.js
@@ -35,6 +35,7 @@
      .replace(/<[^>]*>/g, '')
      .replace(/^[=\-]{2,}\s*$/g, '')
      .replace(/\[\^.+?\](\: .*?$)?/g, '')
      .replace(/(#{1,6})\s+(.+)\1?/g, '<b>$2</b>')
      .replace(/\s{0,2}\[.*?\]: .*?$/g, '')
      .replace(/\!\[(.*?)\][\[\(].*?[\]\)]/g, options.useImgAltText ? '$1' : '')
      .replace(/\[(.*?)\][\[\(].*?[\]\)]/g, '$1')
@@ -143,7 +144,7 @@
    // SPA navigation
    window.navigate(
      new URL(
        `${BASE_URL.slice(0, -1)}${id}#:~:text=${encodeURIComponent(term)}/`
        `${BASE_URL}${id}#:~:text=${encodeURIComponent(term)}/`
      ),
      '.singlePage'
    )
data/config.yaml
@@ -3,6 +3,7 @@
openToc: false
enableLinkPreview: true
enableLatex: true
enableSPA: false
description:
  Host your second brain and digital garden for free. Quartz features extremely fast full-text search,
  Wikilink support, backlinks, local graph, tags, and link previews.
layouts/partials/backlinks.html
@@ -10,6 +10,7 @@
    {{$cleanedInbound := apply (apply $inbound "index" "." "source") "replace" "." " " "-"}}
    {{- range $cleanedInbound | uniq -}}
      {{$l := printf "%s%s/" $host .}}
      {{$l = cond (eq $l "//") "/" $l}}
      {{with (index $contentTable .)}}
      <li>
          <a href="{{$l}}">{{index (index . "title")}}</a>
layouts/partials/graph.html
@@ -16,3 +16,14 @@
</style>
{{ $js := resources.Get "js/graph.js" | resources.Fingerprint "md5" }}
<script src="{{ $js.Permalink }}"></script>
<script>
drawGraph(
  {{strings.TrimRight "/" .Page.Permalink}},
  {{strings.TrimRight "/" .Site.BaseURL}},
  {{$.Site.Data.graphConfig.paths}},
  {{$.Site.Data.graphConfig.depth}},
  {{$.Site.Data.graphConfig.enableDrag}},
  {{$.Site.Data.graphConfig.enableLegend}},
  {{$.Site.Data.graphConfig.enableZoom}}
);
</script>
layouts/partials/head.html
@@ -58,6 +58,7 @@
          content,
        }))
  </script>
  {{if $.Site.Data.config.enableSPA}}
  <script type="module">
    import { router, navigate } from "https://unpkg.com/million/dist/router.mjs";
    // SPA navigation for access later
@@ -89,5 +90,8 @@
    window.addEventListener("million:navigate", callback);
    window.addEventListener("DOMContentLoaded", callback);
  </script>
  {{else}}
  <script>window.navigate = (url) => window.location.href = url</script>
  {{end}}
</head>
{{ template "_internal/google_analytics.html" . }}