aboutsummaryrefslogtreecommitdiff
path: root/layouts/partials/scripts.html
blob: a89ad89858b9ab6dc5c59ffb2e6a50f3e4d04068 (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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<!-- highlight.js -->
{{- if .Site.Params.highlightInClient -}}
  <script src="{{ "lib/highlight/highlight.pack.js?v=20171001" | relURL }}"></script>
{{- end -}}

<!-- core -->
{{- if .Site.Params.publicCDN.enable }}
  {{ .Site.Params.publicCDN.jquery | safeHTML }}
  {{ .Site.Params.publicCDN.slideout | safeHTML }}
  {{ if .Site.Params.fancybox }}{{ .Site.Params.publicCDN.fancyboxJS | safeHTML }}{{ end }}
{{- else -}}
  <script type="text/javascript" src="{{ "lib/jquery/jquery-3.2.1.min.js" | relURL }}"></script>
  <script type="text/javascript" src="{{ "lib/slideout/slideout-1.0.1.min.js" | relURL }}"></script>
  {{ if .Site.Params.fancybox }}<script type="text/javascript" src="{{ "lib/fancybox/jquery.fancybox-3.1.20.min.js" | relURL }}"></script>{{ end }}
{{- end -}}

<!-- timeago.JS -->
{{- if and (or .Params.enableOutdatedInfoWarning (and .Site.Params.outdatedInfoWarning.enable (ne .Params.enableOutdatedInfoWarning false))) (or .IsPage .IsHome) }}
  {{- if .Site.Params.publicCDN.enable }}
  {{ .Site.Params.publicCDN.timeagoJS | safeHTML }}
  {{ .Site.Params.publicCDN.timeagoLocalesJS | safeHTML }}
  {{- else }}
  <script type="text/javascript" src="{{ "lib/timeago/timeago-3.0.2.min.js" | relURL }}"></script>
  <script type="text/javascript" src="{{ "lib/timeago/timeago.locales-3.0.2.min.js" | relURL }}"></script>
  {{- end }}
<script>  // NOTE: timeago.js uses the language code format like "zh_CN" (underscore and case sensitive)
  var languageCode = {{ .Site.LanguageCode }}.replace(/-/g, '_').replace(/_(.*)/, function ($0, $1) {return $0.replace($1, $1.toUpperCase());});
  timeago().render(document.querySelectorAll('.timeago'), languageCode);
  timeago.cancel();  // stop update
</script>
{{- end }}

<!-- flowchart -->
{{- if and (or .Params.flowchartDiagrams.enable (and .Site.Params.flowchartDiagrams.enable (ne .Params.flowchartDiagrams.enable false))) (or .IsPage .IsHome) -}}
<script>
  {{- if .Params.flowchartDiagrams.options -}}
  window.flowchartDiagramsOptions = {{ .Params.flowchartDiagrams.options | safeJS }};
  {{- else if .Site.Params.flowchartDiagrams.options -}}
  window.flowchartDiagramsOptions = {{ .Site.Params.flowchartDiagrams.options | safeJS }};
  {{- end -}}
</script>
{{- if .Site.Params.publicCDN.enable -}}
  {{ .Site.Params.publicCDN.flowchartDiagramsJS | safeHTML }}
{{- else -}}
<script src="{{ "lib/flowchartDiagrams/raphael-2.2.7.min.js" | relURL }}" integrity="sha256-67By+NpOtm9ka1R6xpUefeGOY8kWWHHRAKlvaTJ7ONI=" crossorigin="anonymous"></script>
<script src="{{ "lib/flowchartDiagrams/flowchart-1.8.0.min.js" | relURL }}" integrity="sha256-zNGWjubXoY6rb5MnmpBNefO0RgoVYfle9p0tvOQM+6k=" crossorigin="anonymous"></script>
{{- end -}}
{{- end -}}

<!-- js-sequence-diagrams -->
{{- if and (or .Params.sequenceDiagrams.enable (and .Site.Params.sequenceDiagrams.enable (ne .Params.sequenceDiagrams.enable false))) (or .IsPage .IsHome) -}}
<script>
  {{- if .Params.sequenceDiagrams.options -}}
  window.sequenceDiagramsOptions = {{ .Params.sequenceDiagrams.options | safeJS }};
  {{- else if .Site.Params.sequenceDiagrams.options -}}
  window.sequenceDiagramsOptions = {{ .Site.Params.sequenceDiagrams.options | safeJS }};
  {{- end -}}
</script>
{{- if .Site.Params.publicCDN.enable -}}
  {{ .Site.Params.publicCDN.sequenceDiagramsJS | safeHTML }}
  {{ .Site.Params.publicCDN.sequenceDiagramsCSS | safeHTML }}
{{- else -}}
<script src="{{ "lib/js-sequence-diagrams/webfontloader-1.6.28.js" | relURL }}" integrity="sha256-4O4pS1SH31ZqrSO2A/2QJTVjTPqVe+jnYgOWUVr7EEc=" crossorigin="anonymous"></script>
<script src="{{ "lib/js-sequence-diagrams/snap.svg-0.5.1.min.js" | relURL }}" integrity="sha256-oI+elz+sIm+jpn8F/qEspKoKveTc5uKeFHNNVexe6d8=" crossorigin="anonymous"></script>
<script src="{{ "lib/js-sequence-diagrams/underscore-1.8.3.min.js" | relURL }}" integrity="sha256-obZACiHd7gkOk9iIL/pimWMTJ4W/pBsKu+oZnSeBIek=" crossorigin="anonymous"></script>
<script src="{{ "lib/js-sequence-diagrams/sequence-diagram-2.0.1.min.js" | relURL }}" integrity="sha384-8748Vn52gHJYJI0XEuPB2QlPVNUkJlJn9tHqKec6J3q2r9l8fvRxrgn/E5ZHV0sP" crossorigin="anonymous"></script>
<link rel="stylesheet" href="{{ "lib/js-sequence-diagrams/sequence-diagram-2.0.1.min.css" | relURL }}" integrity="sha384-6QbLKJMz5dS3adWSeINZe74uSydBGFbnzaAYmp+tKyq60S7H2p6V7g1TysM5lAaF" crossorigin="anonymous">
{{- end -}}
{{- end }}
<script type="text/javascript" src="{{ print "dist/" .Site.Data.even.assets.even.js | relURL }}"></script>

{{- if and (or .Params.mathjax (and .Site.Params.mathjax (ne .Params.mathjax false))) (or .IsPage .IsHome) }}
  <script type="text/javascript">
    window.MathJax = {
      {{ if or .Params.mathjaxEnableSingleDollar (and .Site.Params.mathjaxEnableSingleDollar (ne .Params.mathjaxEnableSingleDollar false)) -}}
        tex2jax: {inlineMath: [['$','$'], ['\\(','\\)']]},
      {{ end -}}
      {{ if or .Params.mathjaxEnableAutoNumber (and .Site.Params.mathjaxEnableAutoNumber (ne .Params.mathjaxEnableAutoNumber false)) -}}
        TeX: {equationNumbers: {autoNumber: "AMS"}},
      {{ end -}}
      showProcessingMessages: false,
      messageStyle: 'none'
    };
  </script>
  {{ if .Site.Params.mathjaxUseLocalFiles -}}
    <script type="text/javascript" async src="{{ "lib/mathjax/MathJax.js?config=TeX-MML-AM_CHTML" | relURL }}"></script>
  {{- else -}}
    <script type="text/javascript" async src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.2/MathJax.js?config=TeX-MML-AM_CHTML"></script>
  {{- end }}
{{- end }}

<!-- Analytics -->
{{- if .Site.GoogleAnalytics -}}
  {{ template "_internal/google_analytics_async.html" . }}
{{- end -}}

{{- with .Site.Params.baiduAnalytics -}}
<script id="baidu_analytics">
  var _hmt = _hmt || [];
  (function() {
    if (window.location.hostname === 'localhost') return;
    var hm = document.createElement("script"); hm.async = true;
    hm.src = "https://hm.baidu.com/hm.js?{{.}}";
    var s = document.getElementsByTagName("script")[0];
    s.parentNode.insertBefore(hm, s);
  })();
</script>
{{- end }}

<!-- baidu push -->
{{- if .Site.Params.baiduPush -}}
<script id="baidu_push">
  (function(){
    if (window.location.hostname === 'localhost') return;
    var bp = document.createElement('script'); bp.async = true;
    var curProtocol = window.location.protocol.split(':')[0];
    if (curProtocol === 'https') {
      bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';
    }
    else {
      bp.src = 'http://push.zhanzhang.baidu.com/push.js';
    }
    var s = document.getElementsByTagName("script")[0];
    s.parentNode.insertBefore(bp, s);
  })();
</script>
{{- end }}

<!-- custom js -->
{{ range .Site.Params.customJS -}}
<script src="{{ "/js/" | relURL }}{{ . }}"></script>
{{ end }}