-
-
Save canertuzunar/7e5164a9e2400241f5c79b505a6e4bae to your computer and use it in GitHub Desktop.
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
const path = require('path') | |
const { createFilePath } = require(`gatsby-source-filesystem`) | |
/* adi ilk gonderi olan bir markdown dosyasi oldugunu varsayalim. bu dosyayi linklerken | |
kullanilacak olan patterndir dosyanin linkini /ilk-gonderi olarak olusturacaktir*/ | |
exports.onCreateNode =({ node, getNode, actions}) => { | |
const { createNodeField } = actions | |
if(node.internal.type === `MarkdownRemark`) { | |
const slug = createFilePath({ node, getNode, basePath: `pages`}) | |
createNodeField({ | |
node, | |
name: `slug`, | |
value: slug | |
}) | |
} | |
} | |
exports.createPages = async ({graphql, actions, reporter}) => { | |
const { createPage } = actions | |
//olusturdugumuz blog sayfasinda kullanmak uzere sorgu hazirliyoruz | |
const result = await graphql(` | |
{ | |
allMarkdownRemark(limit:1000) { | |
edges{ | |
node{ | |
fields{ | |
slug | |
} | |
frontmatter{ | |
title | |
date | |
description | |
} | |
html | |
rawMarkdownBody | |
} | |
} | |
} | |
} | |
`) | |
//Olusabilecek hatalari gormek icin reporter kullaniyoruz | |
if(result.errors){ | |
reporter.panicOnBuild(`Graphql Sorgusunda bir hata olustu. ${result.errors}`) | |
} | |
//Olusturulan her post dosyasi icin blog sayfasi olusturuyoruz | |
const blogPostTemplate = path.resolve(`./src/templates/blog.jsx`) | |
result.data.allMarkdownRemark.edges.forEach( ({node}) => { | |
const path = node.fields.slug | |
createPage({ | |
path, //md dosyasi gatsby sayfasi haline geldikten sonra olusacak linki | |
component: blogPostTemplate, /* md dosyasi goruntulenirken kullanilacak | |
olan react componenti*/ | |
context: { | |
pagePath: path, | |
html: node.html, | |
frontmatter: node.frontmatter | |
} /* olusan gatsby sayfalarinin alacagi propslari belirliyoruz */ | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment