Skip to content

Commit 60ef2ee

Browse files
Add custom JS
1 parent deda346 commit 60ef2ee

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

assets/js/main.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// A function that replaces all external links with a target="_blank" attribute on DOM load
2+
function externalLinks() {
3+
const a = document.getElementsByTagName("a");
4+
for (i = 0; i < a.length; i++) {
5+
if (a[i].getAttribute("href") && a[i].hostname !== location.hostname)
6+
a[i].target = "_blank";
7+
}
8+
}
9+
10+
document.addEventListener("DOMContentLoaded", externalLinks);

layouts/_default/baseof.html

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@
22
<html lang="en">
33

44
<head>
5+
<!-- Meta tags -->
56
<meta charset="UTF-8">
6-
<title>{{ block "title" . }}{{ .Title }}{{ end }}</title>
7+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
8+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
9+
<!-- Dependencies -->
710
<link rel="preconnect" href="https://fonts.googleapis.com">
811
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
912
<link
@@ -14,9 +17,15 @@
1417
<link rel="stylesheet" href="/js/katex/katex.min.css">
1518
<script defer src="/js/katex/katex.min.js"></script>
1619
<script defer src="/js/katex/contrib/auto-render.min.js"></script>
17-
20+
<!-- Custom styles -->
1821
{{ $styles := resources.Get "scss/main.scss" | toCSS | minify | fingerprint }}
1922
<link rel="stylesheet" href="{{ $styles.Permalink }}">
23+
<!-- Custom scripts -->
24+
{{ $scripts := resources.Get "js/main.js" | minify | fingerprint }}
25+
<script defer src="{{ $scripts.Permalink }}"></script>
26+
<!-- Title -->
27+
<title>{{ block "title" . }}{{ .Title }}{{ end }}</title>
28+
<!-- Head block -->
2029
{{ block "head" . }}{{ end }}
2130
</head>
2231

0 commit comments

Comments
 (0)