@tenjuu99/blog 0.2.26 → 0.2.28

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/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { allData } from './lib/indexer.js'
2
2
  import config from './lib/config.js'
3
+ import * as dir from './lib/dir.js'
3
4
 
4
- export { allData, config }
5
+ export { allData, config, dir }
package/lib/dir.js CHANGED
@@ -36,10 +36,16 @@ const cache = () => {
36
36
  const packages = config.packages.split(',')
37
37
  packages.forEach(dir => {
38
38
  if (fs.existsSync(`${packageDirCore}/${dir}`)) {
39
+ const helper = config.helper.split(',')
40
+ helper.push(`${dir}.js`)
41
+ config.helper = helper.join(',')
39
42
  console.log(styleText('blue', `[cache] enable core package: ${dir}`))
40
43
  fs.cpSync(`${packageDirCore}/${dir}`, cacheDir, { recursive: true })
41
44
  }
42
45
  if (fs.existsSync(`${packageDir}/${dir}`)) {
46
+ const helper = config.helper.split(',')
47
+ helper.push(`${dir}.js`)
48
+ config.helper = helper.join(',')
43
49
  console.log(styleText('blue', `[cache] enable package: ${dir}`))
44
50
  fs.cpSync(`${packageDir}/${dir}`, cacheDir, { recursive: true })
45
51
  }
package/lib/helper.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import config from './config.js'
2
+ import { existsSync } from 'node:fs'
2
3
  import { helperDir } from './dir.js'
3
4
 
4
5
  let helper = {}
@@ -6,8 +7,10 @@ let helper = {}
6
7
  if (config.helper) {
7
8
  const files = config.helper.split(',')
8
9
  files.forEach(async file => {
9
- const helperAdditional = await import(`${helperDir}/${file}`)
10
- helper = Object.assign(helper, helperAdditional)
10
+ if (existsSync(`${helperDir}/${file}`)) {
11
+ const helperAdditional = await import(`${helperDir}/${file}`)
12
+ helper = Object.assign(helper, helperAdditional)
13
+ }
11
14
  })
12
15
  }
13
16
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tenjuu99/blog",
3
- "version": "0.2.26",
3
+ "version": "0.2.28",
4
4
  "description": "blog template",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -0,0 +1,7 @@
1
+ import fs from 'node:fs'
2
+ import { dir } from '@tenjuu99/blog'
3
+
4
+ export function turbolink() {
5
+ const turbolinkScript = fs.readFileSync(dir.templateDir + '/turbolink.js', 'utf8')
6
+ return `<script>${turbolinkScript}</script>`
7
+ }
@@ -61,6 +61,21 @@ const transition = async (href) => {
61
61
  document.head.appendChild(meta)
62
62
  }
63
63
  })
64
+ const scripts = [...document.scripts].forEach(script => {
65
+ if (script.dataset.turbolink === 'reapply') {
66
+ const newScript = document.createElement('script')
67
+ newScript.dataset.turbolink = 'reapply'
68
+ const newScriptHtml = `(() => {
69
+ ${script.innerHTML}
70
+ })()`
71
+ newScript.innerHTML = newScriptHtml
72
+ script.parentNode.append(newScript)
73
+ script.remove()
74
+ }
75
+ })
76
+ for (let k in window.after_transition) {
77
+ window.after_transition[k].apply()
78
+ }
64
79
  }
65
80
 
66
81
  const urlFromHref = (href) => {
@@ -8,12 +8,13 @@
8
8
  <ul class="container">
9
9
  <li><a href="{{RELATIVE_PATH}}/about">about</a></li>
10
10
  <li><a href="{{RELATIVE_PATH}}/privacy_policy">プライバシーポリシー</a></li>
11
- <li><a href="{{RELATIVE_PATH}}/rss.xml">RSS</a></li>
11
+ <li><a href="{{RELATIVE_PATH}}/rss.xml" data-turbolink="disable">RSS</a></li>
12
12
  </ul>
13
13
  </footer>
14
14
 
15
- {if turbolink}
16
- <script>
17
- {include('template/turbolink.js')}
15
+ <script data-turbolink="reapply">
16
+ const title = document.title
17
+ console.log(title)
18
18
  </script>
19
- {/if}
19
+
20
+ {{ turbolink() }}