-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.js
41 lines (37 loc) · 1.28 KB
/
utils.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
const slugify = require("slugify");
/**
* function to create the base64 encoded file content for commiting the changes to Github
*
* @param {object} params
* @param {string} params.title title of the post
* @param {string} params.description subtitle or brief description of the post
* @param {string[]} params.tags an array of string for keywords or tech tags related to the post
* @param {string} params.body body of the post
* @param {string} params.date date string for created_at or updated_at value
*
* @return {string} base64 encoded file content
*/
const getPostFileContent = ({ title, description, body, date, tags }) =>
Buffer.from(
`---
title: ${title}
date: ${date}
${description ? `description: ${description}` : ""}
${tags.length ? `tags: ${tags.join(", ")}` : ""}
---
${body}`
).toString("base64");
/**
* function to create the file name based on the title and slug
*
* @param {object} param
* @param {string} param.title title of the post
* @param {string} param.slug slug identifier of the post in Able
*
* @returns {string} the file name in gatsby
*/
const getFileName = ({ title, slug }) => `${slugify(title)}-${slug}.md`;
module.exports = {
getPostFileContent,
getFileName,
};