@tenjuu99/blog 0.2.24 → 0.2.26

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tenjuu99/blog",
3
- "version": "0.2.24",
3
+ "version": "0.2.26",
4
4
  "description": "blog template",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -26,11 +26,22 @@ const transition = async (href) => {
26
26
  document.head.appendChild(s)
27
27
  }
28
28
  })
29
+ window.scroll({top: 0, left: 0, behavior: 'instant'})
29
30
  // set body
30
31
  document.body = doc.getElementsByTagName('body')[0]
31
32
  // set header
32
33
  document.title = doc.getElementsByTagName('title')[0].textContent
33
- const canonical = document.head.querySelector('link[rel=canonical]').href = doc.querySelector('link[rel=canonical]').href
34
+ const canonical = document.head.querySelector('link[rel=canonical]')
35
+ const newCanonical = doc.querySelector('link[rel=canonical]')
36
+ if (canonical) {
37
+ if (newCanonical) {
38
+ canonical.href = newCanonical.href
39
+ } else {
40
+ canonical.remove()
41
+ }
42
+ } else if (newCanonical) {
43
+ document.head.appendChild(newCanonical)
44
+ }
34
45
 
35
46
  const metas = [...document.head.querySelectorAll('meta')]
36
47
  metas.forEach(meta => {
@@ -52,13 +63,24 @@ const transition = async (href) => {
52
63
  })
53
64
  }
54
65
 
66
+ const urlFromHref = (href) => {
67
+ try {
68
+ return new URL(encodeURI(href))
69
+ } catch (e) {
70
+ console.log(`${href} is invalid`)
71
+ throw e
72
+ }
73
+ }
55
74
  const turbolinks = () => {
56
75
  const links = document.querySelectorAll('a')
57
- const current = new URL(document.location.href)
76
+ const current = urlFromHref(document.location.href)
58
77
  const currentDom = document.body
59
78
  links.forEach(link => {
60
79
  const href = link.href
61
- const url = new URL(href)
80
+ if (!href.trim() || href.startsWith('javascript:') || link.dataset['turbolink'] === 'disable') {
81
+ return
82
+ }
83
+ const url = urlFromHref(href)
62
84
  if (url.host === current.host) {
63
85
  link.onclick = async (e) => {
64
86
  e.preventDefault()
@@ -47,12 +47,6 @@
47
47
 
48
48
  {include('template/prevNext.html')}
49
49
  </main>
50
- {if isEditorEnabled() }
51
- <div class="container">
52
- <a href="/editor?md={{name}}.{{__filetype}}" class="editor_link">編集する</a>
53
- </div>
54
- {/if}
55
-
56
50
  {include('template/footer.html')}
57
51
  {if add_script}
58
52
  <script src="{{ADD_SCRIPT}}" async></script>
@@ -1,10 +1,16 @@
1
- <footer>
2
- <ul class="container">
3
- <li><a href="{{RELATIVE_PATH}}/about">about</a></li>
4
- <li><a href="{{RELATIVE_PATH}}/privacy_policy">プライバシーポリシー</a></li>
5
- <li><a href="{{RELATIVE_PATH}}/rss.xml">RSS</a></li>
6
- </ul>
7
- </footer>
1
+ {if isEditorEnabled() }
2
+ <div class="container">
3
+ <a href="/editor?md={{name}}.{{__filetype}}" class="editor_link" data-turbolink="disable">編集する</a>
4
+ </div>
5
+ {/if}
6
+
7
+ <footer>
8
+ <ul class="container">
9
+ <li><a href="{{RELATIVE_PATH}}/about">about</a></li>
10
+ <li><a href="{{RELATIVE_PATH}}/privacy_policy">プライバシーポリシー</a></li>
11
+ <li><a href="{{RELATIVE_PATH}}/rss.xml">RSS</a></li>
12
+ </ul>
13
+ </footer>
8
14
 
9
15
  {if turbolink}
10
16
  <script>