@tenjuu99/blog 0.2.22 → 0.2.24

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/lib/config.js CHANGED
@@ -9,7 +9,8 @@ const config = {
9
9
  "distribute_raw": "image",
10
10
  "relative_path": "",
11
11
  "helper": "",
12
- "packages": ""
12
+ "packages": "",
13
+ "allowedSrcExt": "md|html|txt"
13
14
  }
14
15
  try {
15
16
  const file = rootDir + '/blog.json'
package/lib/indexer.js CHANGED
@@ -3,6 +3,7 @@ import { readFile } from "node:fs/promises";
3
3
  import { readdirSync } from "node:fs";
4
4
  import { pageDir, cacheDir } from './dir.js'
5
5
  import makePageData from './pageData.js'
6
+ import config from './config.js'
6
7
 
7
8
  let allData = {}
8
9
 
@@ -18,7 +19,8 @@ const collect = (dir, namePrefix = '', promises = []) => {
18
19
  if (dirent.isDirectory()) {
19
20
  collect(`${dirent.path}/${dirent.name}`, namePrefix + dirent.name + '/', promises)
20
21
  } else {
21
- if (dirent.name.match(/\.(md|html)$/)) {
22
+ const regexp = `\\.(${config.allowedSrcExt})$`
23
+ if (dirent.name.match(regexp)) {
22
24
  const name = `${namePrefix}${dirent.name}`
23
25
  promises.push(readFile(`${dir}/${dirent.name}`, 'utf8').then(f => [name, f]))
24
26
  }
package/lib/render.js CHANGED
@@ -13,9 +13,14 @@ marked.use({
13
13
  })
14
14
 
15
15
  const render = async (templateName, data) => {
16
- let template = await applyTemplate(templateName)
17
- template = replaceIfFilter(template, data)
18
- template = await replaceScriptFilter(template, data)
16
+ let template
17
+ if (!templateName) {
18
+ template = '{{MARKDOWN}}'
19
+ } else {
20
+ template = await applyTemplate(templateName)
21
+ template = replaceIfFilter(template, data)
22
+ template = await replaceScriptFilter(template, data)
23
+ }
19
24
 
20
25
  let markdown = data.markdown
21
26
  markdown = includeFilter(markdown)
package/lib/server.js CHANGED
@@ -7,6 +7,8 @@ import handle from './tryServer.js'
7
7
 
8
8
  const contentType = (ext) => {
9
9
  switch (ext) {
10
+ case 'txt':
11
+ return 'text/plain'
10
12
  case 'html':
11
13
  case 'css':
12
14
  return `text/${ext}`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tenjuu99/blog",
3
- "version": "0.2.22",
3
+ "version": "0.2.24",
4
4
  "description": "blog template",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -0,0 +1,15 @@
1
+ .breadcrumbs {
2
+ display: flex;
3
+ flex-wrap: wrap;
4
+ justify-content:flex-start;
5
+ }
6
+ .breadcrumbs-item {
7
+ margin-left: 10px;
8
+ }
9
+ .breadcrumbs-item::after {
10
+ content: '/';
11
+ margin-left: 10px;
12
+ }
13
+ .breadcrumbs-item:last-child:after {
14
+ content: none;
15
+ }
@@ -0,0 +1,36 @@
1
+ import { allData, config } from '@tenjuu99/blog'
2
+
3
+ export function breadcrumbList(pageName) {
4
+ const pageData = allData[pageName]
5
+ const entries = Object.entries(allData)
6
+ const breadCrumbs = ['/']
7
+ pageData.url.split('/').reduce((prev, curr) => {
8
+ if (curr === 'index') {
9
+ return
10
+ }
11
+ let str = curr
12
+ if (allData[prev + curr]) {
13
+ str = allData[prev + curr].title
14
+ } else {
15
+ const entry = entries.find(v => `/${prev}${curr}` === v[1].url)
16
+ if (entry) {
17
+ str = entry[1].title
18
+ }
19
+ }
20
+ breadCrumbs.push([`/${prev}${curr}/`, str])
21
+ return `${prev}${curr}/`
22
+ })
23
+ if (breadCrumbs.length === 1) {
24
+ return ''
25
+ }
26
+ const last = breadCrumbs.pop()
27
+ last[0] = last[0].substring(0, last[0].length - 1)
28
+
29
+ const output = breadCrumbs.map(v => {
30
+ const href = config.relative_path ? config.relative_path + v[0] : v[0]
31
+ return `<div class="breadcrumbs-item"><a href="${href}">${v[0] === '/' ? 'top' : v[1]}</a></div>`
32
+ }).join('') + `<div class="breadcrumbs-item">${last[1]}</div>`
33
+ return '<div class="breadcrumbs">'
34
+ + output
35
+ + '</div>'
36
+ }
@@ -0,0 +1,80 @@
1
+ const transition = async (href) => {
2
+ const destination = await fetch(href)
3
+ if (!destination.ok) {
4
+ document.location.href = href
5
+ return
6
+ }
7
+ const doc = document.createElement('html')
8
+ doc.innerHTML = await destination.text()
9
+ // load stylesheets
10
+ const headLinks = doc.getElementsByTagName('link')
11
+ const styleSheets = [...document.styleSheets].map(s => s.href).filter(h => h)
12
+ const newStyleSheets = [...headLinks].filter(l => l.rel === 'stylesheet').map(l => l.href)
13
+ const diff = newStyleSheets.filter(i => styleSheets.indexOf(i) === -1)
14
+ diff.forEach(href => {
15
+ const addLink = document.createElement('link')
16
+ addLink.rel = 'stylesheet'
17
+ addLink.href = href
18
+ document.head.appendChild(addLink)
19
+ })
20
+ // load style
21
+ const styleInline = [...document.styleSheets].filter(s => !s.href)
22
+ const newStyleInline = [...doc.getElementsByTagName('style')].filter(s => s.dataset.styleName)
23
+ newStyleInline.forEach(s => {
24
+ const name = s.dataset.styleName
25
+ if (!styleInline.find(si => si.ownerNode.dataset.styleName === name)) {
26
+ document.head.appendChild(s)
27
+ }
28
+ })
29
+ // set body
30
+ document.body = doc.getElementsByTagName('body')[0]
31
+ // set header
32
+ document.title = doc.getElementsByTagName('title')[0].textContent
33
+ const canonical = document.head.querySelector('link[rel=canonical]').href = doc.querySelector('link[rel=canonical]').href
34
+
35
+ const metas = [...document.head.querySelectorAll('meta')]
36
+ metas.forEach(meta => {
37
+ if (
38
+ (meta.getAttribute('property') && meta.getAttribute('property').startsWith('og:')) ||
39
+ (meta.getAttribute('name') && meta.getAttribute('name').startsWith('twitter:'))
40
+ ) {
41
+ meta.remove()
42
+ }
43
+ })
44
+ const newMetas = [...doc.querySelectorAll('meta')]
45
+ newMetas.forEach(meta => {
46
+ if (
47
+ (meta.getAttribute('property') && meta.getAttribute('property').startsWith('og:')) ||
48
+ (meta.getAttribute('name') && meta.getAttribute('name').startsWith('twitter:'))
49
+ ) {
50
+ document.head.appendChild(meta)
51
+ }
52
+ })
53
+ }
54
+
55
+ const turbolinks = () => {
56
+ const links = document.querySelectorAll('a')
57
+ const current = new URL(document.location.href)
58
+ const currentDom = document.body
59
+ links.forEach(link => {
60
+ const href = link.href
61
+ const url = new URL(href)
62
+ if (url.host === current.host) {
63
+ link.onclick = async (e) => {
64
+ e.preventDefault()
65
+ if (`${url.pathname}${url.search}` === `${current.pathname}${current.search}`) {
66
+ return;
67
+ }
68
+ await transition(href)
69
+ history.pushState({}, '', href)
70
+ turbolinks()
71
+ }
72
+ }
73
+ })
74
+ }
75
+ document.body.onload = turbolinks
76
+ window.onpopstate = async (e) => {
77
+ const href = window.location.pathname + window.location.search + window.location.hash
78
+ await transition(href)
79
+ turbolinks()
80
+ }
@@ -82,21 +82,3 @@ export function renderIndex(pages, nodate = 'nodate', headingTag = 'h3') {
82
82
  export function isEditorEnabled() {
83
83
  return allData.editor && allData.editor.distribute
84
84
  }
85
-
86
- export function breadcrumbList(pageName) {
87
- const pageData = allData[pageName]
88
- const breadCrumbs = ['/']
89
- pageData.url.split('/').reduce((prev, curr) => {
90
- breadCrumbs.push([`/${prev}${curr}/`, curr])
91
- return `${prev}${curr}/`
92
- })
93
- const last = breadCrumbs.pop()
94
- last[0] = last[0].substring(0, last[0].length - 1)
95
-
96
- const output = breadCrumbs.map(v => {
97
- return `<div style="margin-left: 10px;"><a href="${v[0]}">${v[0] === '/' ? 'top' : v[1]}</a> > </div>`
98
- }).join('') + `<div style="margin-left: 10px;">${last[1]}</div>`
99
- return '<div style="display: flex;flex-wrap: wrap;">'
100
- + output
101
- + '</div>'
102
- }
@@ -0,0 +1,9 @@
1
+ ---
2
+ template:
3
+ url: /robots
4
+ ext: txt
5
+ index: false
6
+ ---
7
+ User-Agent: *
8
+
9
+ Allow: /
@@ -2,5 +2,4 @@
2
2
  {include('css/reset.css')}
3
3
  </style>
4
4
  <link rel="stylesheet" href="${/css/layout.css<<layout.css,color.css}">
5
- <link rel="preload" href="${/css/lazy.css<<page.css,markdown.css}" as="style">
6
- <link rel="stylesheet" href="${/css/lazy.css<<page.css,markdown.css}" media="print" onload="this.media='all'">
5
+ <link rel="stylesheet" href="${/css/lazy.css<<page.css,markdown.css,breadcrumbs.css}" media="print" onload="this.media='all'">
@@ -5,3 +5,9 @@
5
5
  <li><a href="{{RELATIVE_PATH}}/rss.xml">RSS</a></li>
6
6
  </ul>
7
7
  </footer>
8
+
9
+ {if turbolink}
10
+ <script>
11
+ {include('template/turbolink.js')}
12
+ </script>
13
+ {/if}