From 1e248151d5bd60e8c94ab26f272e5e9cf900ca7a Mon Sep 17 00:00:00 2001 From: Patryk Niedźwiedziński Date: Fri, 11 Oct 2019 19:08:14 +0200 Subject: Add folder structure parser --- netlify.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'netlify.toml') diff --git a/netlify.toml b/netlify.toml index 3a88ace..080dfa8 100644 --- a/netlify.toml +++ b/netlify.toml @@ -1,4 +1,4 @@ [build] publish = "dist/" -command = "npm run generate" \ No newline at end of file +command = "npm run build" \ No newline at end of file -- cgit 1.4.1 From 5855198867cc0586b71b6d64f4581dffc7fe6cbb Mon Sep 17 00:00:00 2001 From: Patryk Niedźwiedziński Date: Fri, 11 Oct 2019 19:33:24 +0200 Subject: Add api endpoint --- api/api.js | 1 - netlify.toml | 7 ++++++- package.json | 3 ++- scripts/generateApi.js | 13 +++++++++++++ scripts/postbuild.sh | 6 ++++++ scripts/prebuild.sh | 12 ++++++++++++ 6 files changed, 39 insertions(+), 3 deletions(-) create mode 100755 scripts/generateApi.js create mode 100755 scripts/postbuild.sh create mode 100755 scripts/prebuild.sh (limited to 'netlify.toml') diff --git a/api/api.js b/api/api.js index f0d3894..34a53a0 100644 --- a/api/api.js +++ b/api/api.js @@ -31,7 +31,6 @@ function getPosts() { }) } finally { - console.log(routesArray) return routesArray } } diff --git a/netlify.toml b/netlify.toml index 080dfa8..5c94b41 100644 --- a/netlify.toml +++ b/netlify.toml @@ -1,4 +1,9 @@ [build] publish = "dist/" -command = "npm run build" \ No newline at end of file +command = "npm run build" + +[[redirects]] + from = "/api/posts" + to = "/api/posts.json" + status = 200 \ No newline at end of file diff --git a/package.json b/package.json index 722d911..e99735d 100644 --- a/package.json +++ b/package.json @@ -6,8 +6,9 @@ "private": true, "scripts": { "dev": "nuxt", - "prebuild": "git clone https://github.com/19pdh/kronika && rm -rf kronika/.git", + "prebuild": "./scripts/prebuild.sh", "build": "nuxt generate", + "postbuild": "./scripts/postbuild.sh", "start": "nuxt start", "test": "jest" }, diff --git a/scripts/generateApi.js b/scripts/generateApi.js new file mode 100755 index 0000000..f439252 --- /dev/null +++ b/scripts/generateApi.js @@ -0,0 +1,13 @@ +let { getPosts } = require('../api/api') + +let posts = getPosts() + +posts = posts.map(({ year, month, day, title, route }) => { + return { + date: `${year}-${month}-${day}`, + title, + route + } +}) + +console.log(posts) \ No newline at end of file diff --git a/scripts/postbuild.sh b/scripts/postbuild.sh new file mode 100755 index 0000000..6a0d1df --- /dev/null +++ b/scripts/postbuild.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env bash + +mkdir ./dist/api + +node ./script/generateApi.js > ./dist/api/posts.json + diff --git a/scripts/prebuild.sh b/scripts/prebuild.sh new file mode 100755 index 0000000..22d8e00 --- /dev/null +++ b/scripts/prebuild.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +set -x +set -eou pipefail + +if [ -d ./kronika ]; then + cd kronika + git pull + cd .. +else + git clone https://github.com/19pdh/kronika +fi -- cgit 1.4.1