about summary refs log tree commit diff
path: root/scripts/generateApi.js
diff options
context:
space:
mode:
authorPatryk Niedźwiedziński <pniedzwiedzinski19@gmail.com>2020-01-29 11:21:51 +0100
committerPatryk Niedźwiedziński <pniedzwiedzinski19@gmail.com>2020-01-29 11:21:51 +0100
commit6f5413879fc6c4afe04cde9bb930aa9182c57974 (patch)
tree49c1b39eb62679db9617aeb6508b48d0447e3d0f /scripts/generateApi.js
parente7823de0c8160b0b7c77ce24040724b82b58b6f7 (diff)
downloadpuszcza-6f5413879fc6c4afe04cde9bb930aa9182c57974.tar.gz
puszcza-6f5413879fc6c4afe04cde9bb930aa9182c57974.zip
Fix path list
Diffstat (limited to 'scripts/generateApi.js')
-rwxr-xr-xscripts/generateApi.js82
1 files changed, 0 insertions, 82 deletions
diff --git a/scripts/generateApi.js b/scripts/generateApi.js
deleted file mode 100755
index ad266cc..0000000
--- a/scripts/generateApi.js
+++ /dev/null
@@ -1,82 +0,0 @@
-import fs from 'fs'
-import k from '../api'
-import path from 'path'
-
-function mkDirByPathSync(targetDir, { isRelativeToScript = false } = {}) {
-  const sep = path.sep
-  const initDir = path.isAbsolute(targetDir) ? sep : ''
-  const baseDir = isRelativeToScript ? __dirname : '.'
-
-  return targetDir.split(sep).reduce((parentDir, childDir) => {
-    const curDir = path.resolve(baseDir, parentDir, childDir)
-    try {
-      fs.mkdirSync(curDir)
-    } catch (err) {
-      if (err.code === 'EEXIST') {
-        // curDir already exists!
-        return curDir
-      }
-
-      // To avoid `EISDIR` error on Mac and `EACCES`-->`ENOENT` and `EPERM` on Windows.
-      if (err.code === 'ENOENT') {
-        // Throw the original parentDir error on curDir `ENOENT` failure.
-        throw new Error(`EACCES: permission denied, mkdir '${parentDir}'`)
-      }
-
-      const caughtErr = ['EACCES', 'EPERM', 'EISDIR'].indexOf(err.code) > -1
-      if (!caughtErr || (caughtErr && targetDir === curDir)) {
-        throw err // Throw if it's just the last created dir.
-      }
-    }
-
-    return curDir
-  }, initDir)
-}
-
-let posts = k.getPosts()
-
-posts.forEach(post => {
-  const { year, month, day } = post.date
-  const dir = `api/posts/${year}/${month}/${day}`
-  mkDirByPathSync(`./dist/${dir}`)
-  mkDirByPathSync(`./static/${dir}`)
-  console.log(`${dir}/${post.title}.json`)
-  const apiEntry = {
-    title: post.title,
-    date: `${year}-${month}-${day}`,
-    content: post.content.html,
-    meta: post.content.meta
-  }
-  fs.writeFile(
-    `./dist/${dir}/${post.title}.json`,
-    JSON.stringify(apiEntry),
-    err => (err ? console.log(err) : null)
-  )
-  fs.writeFile(
-    `./static/${dir}/${post.title}.json`,
-    JSON.stringify(apiEntry),
-    err => (err ? console.log(err) : null)
-  )
-})
-
-posts = posts.map(({ date, title, content, route }) => {
-  const { year, month, day } = date
-  const { description, meta } = content
-
-  return {
-    date: `${year}-${month}-${day}`,
-    title,
-    content: { description, meta },
-    route
-  }
-})
-
-fs.writeFile('./dist/api/posts.json', JSON.stringify(posts), err =>
-  err ? console.log(err) : null
-)
-
-fs.writeFile('./static/api/posts.json', JSON.stringify(posts), err =>
-  err ? console.log(err) : null
-)
-
-console.log(posts)