Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
({ internal, fileAbsolutePath }) =>
internal.type === 'MarkdownRemark' &&
fileAbsolutePath.indexOf('/posts/') !== -1,
)
// Create posts index with pagination
paginate({
createPage,
items: posts,
component: indexTemplate,
itemsPerPage: siteMetadata.postsPerPage,
pathPrefix: '/',
})
// Create each markdown page and post
forEach(({ node }, index) => {
const previous = index === 0 ? null : sortedPages[index - 1].node
const next =
index === sortedPages.length - 1 ? null : sortedPages[index + 1].node
const isNextSameType = getType(node) === (next && getType(next))
const isPreviousSameType =
getType(node) === (previous && getType(previous))
createPage({
path: node.frontmatter.path,
component: pageTemplate,
context: {
type: getType(node),
next: isNextSameType ? next : null,
previous: isPreviousSameType ? previous : null,
},
})
component: pageTemplate,
context: {
type: getType(node),
next: isNextSameType ? next : null,
previous: isPreviousSameType ? previous : null,
},
})
}, sortedPages)
// Create tag pages
const tags = filter(
tag => not(isNil(tag)),
uniq(flatMap(post => post.frontmatter.tags, posts)),
)
forEach(tag => {
const postsWithTag = posts.filter(
post =>
post.frontmatter.tags && post.frontmatter.tags.indexOf(tag) !== -1,
)
paginate({
createPage,
items: postsWithTag,
component: tagsTemplate,
itemsPerPage: siteMetadata.postsPerPage,
pathPrefix: `/tag/${toKebabCase(tag)}`,
context: {
tag,
},
})
}, tags)
destroyDeletedRecords(table: TableName, records: RecordId[]): void {
const collection = this.loki.getCollection(table)
forEach(recordId => {
const record = collection.by('id', recordId)
record && collection.remove(record)
}, records)
}
const copyFiles = (dir, files, rm = resolvePath()) =>
forEach(file => {
fs.copySync(file, path.join(dir, replace(rm, '', file)))
}, files)