diff --git a/server.js b/server.js index 4a40ff4..6a3cc5d 100644 --- a/server.js +++ b/server.js @@ -1,6 +1,8 @@ const express = require('express') const bodyParser = require('body-parser') const { vueRenderer } = require('@doweb/vuexpress') +const slugify = require('underscore.string/slugify') +const fs = require('fs') const app = express() @@ -83,6 +85,14 @@ app.post('/fetch/', (req, res) => { if (post.virtuals.previewImage) { post.featuredImage = 'https://cdn-images-1.medium.com/max/800/' + post.virtuals.previewImage.imageId } + + // set ID + if (!post.slug) { + post.slug = slugify(post.title) + } + + // save to disk + fs.writeFileSync(`${post.slug}.json`, JSON.stringify(json), 'utf-8') } // render the final post