@tenjuu99/blog 0.2.16 → 0.2.17

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/bin/dev-server CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  import { spawn } from 'child_process'
4
- import { srcDir, watch as watchDir } from '../lib/dir.js'
4
+ import { srcDir, watch as watchDir, packageDir, packageDirCore } from '../lib/dir.js'
5
5
  import { watchers, watch } from '../lib/watcher.js'
6
6
  import generate from '../lib/generate.js'
7
7
  import path from 'path'
@@ -27,7 +27,7 @@ watchers.push({
27
27
  event: ['change', 'unlink', 'add']
28
28
  })
29
29
  watchers.push({
30
- paths: [watchDir.serverDir, watchDir.helperDir, libDir],
30
+ paths: [watchDir.serverDir, watchDir.helperDir, libDir, packageDir, packageDirCore],
31
31
  callback: () => {
32
32
  childProcess.kill('SIGINT')
33
33
  childProcess = proceed()
package/index.js ADDED
@@ -0,0 +1,4 @@
1
+ import { allData } from './lib/indexer.js'
2
+ import config from './lib/config.js'
3
+
4
+ export { allData, config }
package/lib/config.js CHANGED
@@ -9,7 +9,7 @@ const config = {
9
9
  "distribute_raw": "image",
10
10
  "relative_path": "",
11
11
  "helper": "",
12
- "package": ""
12
+ "packages": ""
13
13
  }
14
14
  try {
15
15
  const file = rootDir + '/blog.json'
package/lib/dir.js CHANGED
@@ -58,11 +58,37 @@ const cache = () => {
58
58
  // generate の中でもコールしているが、同一プロセスであれば alreadyCached 変数で制御される
59
59
  cache()
60
60
 
61
+ let packageDirectoriesLoaded = []
62
+ const packageDirectories = () => {
63
+ if (packageDirectoriesLoaded.length > 0) {
64
+ return packageDirectoriesLoaded
65
+ }
66
+ const watchTargetDir = ['pages', 'template', 'css', 'helper', 'server', 'js']
67
+ const packages = config.packages.split(',').reduce((prev, packageName) => {
68
+ if (fs.existsSync(`${packageDir}/${packageName}`)) {
69
+ prev.push(fs.realpathSync(`${packageDir}/${packageName}`))
70
+ }
71
+ prev.push(fs.realpathSync(`${packageDirCore}/${packageName}`))
72
+ return prev
73
+ }, [srcDir])
74
+
75
+ for (const baseDir of packages) {
76
+ for (const target of watchTargetDir) {
77
+ if (!fs.existsSync(`${baseDir}/${target}`)) {
78
+ continue;
79
+ }
80
+ const targetDir = `${baseDir}/${target}`
81
+ packageDirectoriesLoaded.push(targetDir)
82
+ }
83
+ }
84
+ return packageDirectoriesLoaded
85
+ }
86
+
61
87
  const resolveDestinationPath = (path) => {
62
- for (const key of Object.keys(watch)) {
63
- if (path.startsWith(watch[key])) {
64
- const dir = watch[key].split('/').pop()
65
- const srcFile = `${dir}${path.replace(watch[key], '')}`
88
+ for (const targetDir of packageDirectories()) {
89
+ if (path.startsWith(targetDir)) {
90
+ const dir = targetDir.split('/').pop()
91
+ const srcFile = `${dir}${path.replace(targetDir, '')}`
66
92
  return `${cacheDir}/${srcFile}`
67
93
  }
68
94
  }
@@ -101,5 +127,7 @@ export {
101
127
  serverDir,
102
128
  helperDir,
103
129
  watch,
104
- cache
130
+ cache,
131
+ packageDir,
132
+ packageDirCore
105
133
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tenjuu99/blog",
3
- "version": "0.2.16",
3
+ "version": "0.2.17",
4
4
  "description": "blog template",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -1,6 +1,4 @@
1
- import { allData } from '@tenjuu99/blog/lib/indexer.js'
2
- import replaceVariablesFilter from '@tenjuu99/blog/lib/replaceVariablesFilter.js'
3
- import config from '@tenjuu99/blog/lib/config.js'
1
+ import { allData, config } from '@tenjuu99/blog'
4
2
 
5
3
  export function readIndex (filter = null) {
6
4
  const data = Object.entries(allData)
@@ -15,44 +13,10 @@ export function dateFormat(dateString) {
15
13
  return `${date.getFullYear()}年${date.getMonth() + 1}月${date.getDate()}日`
16
14
  }
17
15
 
18
- export function render(text, variables) {
19
- return replaceVariablesFilter(text, variables)
20
- }
21
-
22
16
  export function getPageData(name) {
23
17
  return allData[name]
24
18
  }
25
19
 
26
- let indexedItemsSorted = null
27
- export function indexedItems() {
28
- if (indexedItemsSorted) {
29
- return indexedItemsSorted
30
- }
31
- const sorted = readIndex()
32
- .filter(v => v.index && v.published != '1970-01-01')
33
- .sort((a, b) => new Date(a.published) - new Date(b.published))
34
- let prev, next
35
- for (const item of sorted) {
36
- if (prev) {
37
- prev.next = {
38
- name: item.name,
39
- published: item.published,
40
- url: item.url,
41
- title: item.title,
42
- }
43
- item.prev = {
44
- name: prev.name,
45
- published: prev.published,
46
- url: prev.url,
47
- title: prev.title,
48
- }
49
- }
50
- prev = item
51
- }
52
- indexedItemsSorted = sorted
53
- return indexedItemsSorted
54
- }
55
-
56
20
  /**
57
21
  * 配列を再帰的に順不同リストに変換する
58
22
  * @param {Array|string} arrayOrText