This repository has been archived by the owner on Apr 15, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from helpscout/setup-configs
Allow for proper config options
- Loading branch information
Showing
18 changed files
with
416 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
const template = | ||
`--- | ||
title: "<%= front_matter.title %>" | ||
description: "<%= front_matter.description %>" | ||
date: "<%= date %>" | ||
slug: "<%= slug %>" | ||
--- | ||
<%= content %> | ||
`; | ||
|
||
export default template; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,32 @@ | ||
import { isString } from 'lodash'; | ||
import { isObject, isString } from 'lodash'; | ||
import savePost from './savePost'; | ||
import template from './template/post.js'; | ||
|
||
const defaultDir = './posts'; | ||
const defaultOptions = { | ||
dest: './posts', | ||
template: template, | ||
}; | ||
|
||
export const generate = (options = defaultOptions) => (posts = []) => { | ||
if (!isObject(options)) return false; | ||
|
||
const config = Object.assign({}, defaultOptions, options); | ||
const dest = config.dest; | ||
const template = config.template; | ||
|
||
if (!isString(dest) || !isString(template)) return false; | ||
|
||
export const generate = (dir = defaultDir) => (posts = []) => { | ||
if (!isString(dir)) return false; | ||
const saveQueue = []; | ||
|
||
posts.forEach(post => { | ||
saveQueue.push(savePost(dir)(post)); | ||
saveQueue.push(savePost(options)(post)); | ||
}); | ||
|
||
return Promise.all(saveQueue); | ||
return ( | ||
Promise.all(saveQueue) | ||
/* istanbul ignore next */ | ||
.catch(err => err) | ||
); | ||
}; | ||
|
||
export default generate; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,12 @@ | ||
import { template } from 'lodash'; | ||
import postTemplate from './template/post'; | ||
import { isString, template } from 'lodash'; | ||
import defaultPostTemplate from './template/post'; | ||
|
||
const generatePost = data => { | ||
return template(postTemplate)(data); | ||
const generatePost = (postTemplate = defaultPostTemplate) => { | ||
return data => { | ||
if (!isString(postTemplate)) return false; | ||
|
||
return template(postTemplate)(data); | ||
}; | ||
}; | ||
|
||
export default generatePost; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
const template = `--- | ||
title: "<%= front_matter.title %>" | ||
description: "<%= front_matter.description %>" | ||
date: "<%= date %>" | ||
slug: "<%= slug %>" | ||
title: "<%= marq.front_matter.title %>" | ||
description: "<%= marq.front_matter.description %>" | ||
date: "<%= marq.date %>" | ||
slug: "<%= marq.slug %>" | ||
--- | ||
<%= content %> | ||
<%= marq.content %> | ||
`; | ||
|
||
export default template; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { has, isObject } from 'lodash'; | ||
import defaultTemplate from '../template/post'; | ||
|
||
const remapOptions = (options = {}) => { | ||
let output = {}; | ||
if (!isObject(options)) return output; | ||
if (!has(options, 'hubspot')) return output; | ||
|
||
const { hubspot, dest, template } = options; | ||
|
||
const hapikey = hubspot.key; | ||
const content_group_id = hubspot.blogId; | ||
|
||
if (!hapikey || !content_group_id) return output; | ||
|
||
output = { | ||
query: { | ||
hapikey, | ||
content_group_id, | ||
}, | ||
dest: dest ? dest : './_posts/', | ||
template: template ? template : defaultTemplate, | ||
}; | ||
|
||
return output; | ||
}; | ||
|
||
export default remapOptions; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.