2020-03-21 20:41:52 +03:00
|
|
|
const path = require('path')
|
2020-08-24 14:46:46 +03:00
|
|
|
const ncp = require('ncp').ncp;
|
2020-03-21 20:41:52 +03:00
|
|
|
|
2020-08-24 14:46:46 +03:00
|
|
|
const filesSource = "./src/files"
|
|
|
|
const imagesSource = "./src/images"
|
2021-04-03 22:11:37 +03:00
|
|
|
const webpack = require('webpack')
|
|
|
|
|
2020-08-24 14:46:46 +03:00
|
|
|
|
|
|
|
exports.onPreBootstrap = () => {
|
|
|
|
ncp(filesSource, "./static/files", function (err) {
|
|
|
|
if (err) {
|
|
|
|
return console.error(err);
|
|
|
|
}
|
|
|
|
console.log('Files copied');
|
|
|
|
});
|
|
|
|
ncp(imagesSource, "./static/images", function (err) {
|
|
|
|
if (err) {
|
|
|
|
return console.error(err);
|
|
|
|
}
|
|
|
|
console.log('Images copied');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
exports.createPages = async ({actions, graphql}) => {
|
2020-03-21 20:41:52 +03:00
|
|
|
const {createPage} = actions;
|
|
|
|
|
2020-08-24 14:46:46 +03:00
|
|
|
// language=GraphQL
|
2020-03-21 20:41:52 +03:00
|
|
|
const result = await graphql(`
|
2020-08-24 14:46:46 +03:00
|
|
|
{
|
2021-03-28 21:32:20 +03:00
|
|
|
|
|
|
|
news: allMarkdownRemark(
|
|
|
|
filter: {frontmatter: {content_type: {eq: "post"}, published: {ne: false}}},
|
|
|
|
sort: {fields: [frontmatter___date], order: DESC}
|
|
|
|
) {
|
2020-03-21 20:41:52 +03:00
|
|
|
edges{
|
|
|
|
node{
|
|
|
|
frontmatter{
|
|
|
|
title
|
2021-03-28 21:32:20 +03:00
|
|
|
slug
|
|
|
|
date(formatString: "DD.MM.YYYY")
|
2020-03-21 20:41:52 +03:00
|
|
|
}
|
2021-03-28 21:32:20 +03:00
|
|
|
html
|
2020-03-21 20:41:52 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-08-24 14:46:46 +03:00
|
|
|
|
2021-03-28 21:32:20 +03:00
|
|
|
coursePages: allMarkdownRemark(
|
|
|
|
filter: {frontmatter: {content_type: {eq: "course"}, published: {ne: false}}}
|
|
|
|
){
|
2020-08-24 14:46:46 +03:00
|
|
|
edges{
|
|
|
|
node{
|
2021-03-28 21:32:20 +03:00
|
|
|
html
|
2020-08-24 14:46:46 +03:00
|
|
|
frontmatter{
|
2021-03-28 21:32:20 +03:00
|
|
|
path
|
2020-08-24 14:46:46 +03:00
|
|
|
slug
|
|
|
|
}
|
2020-03-21 20:41:52 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-10-31 12:19:05 +03:00
|
|
|
|
|
|
|
personalPages: allMarkdownRemark(
|
|
|
|
filter: {frontmatter: {content_type: {eq: "personal_page"}, published: {ne: false}}}
|
|
|
|
){
|
|
|
|
edges{
|
|
|
|
node{
|
|
|
|
html
|
|
|
|
frontmatter{
|
|
|
|
path
|
2021-11-08 15:12:30 +03:00
|
|
|
id
|
|
|
|
language
|
2021-10-31 12:19:05 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-03-28 21:32:20 +03:00
|
|
|
}
|
|
|
|
`)
|
2020-08-24 14:46:46 +03:00
|
|
|
|
|
|
|
if (result.errors) {
|
|
|
|
throw result.errors;
|
|
|
|
}
|
|
|
|
|
2021-03-28 21:32:20 +03:00
|
|
|
// Render courses
|
2020-03-21 20:41:52 +03:00
|
|
|
const courseTemplate = path.resolve(`./src/components/templates/courseTemplate.js`);
|
2021-03-28 21:32:20 +03:00
|
|
|
const courses = result.data.coursePages.edges;
|
2020-03-21 20:41:52 +03:00
|
|
|
|
|
|
|
courses.forEach(({node}) => {
|
|
|
|
createPage({
|
|
|
|
path: node.frontmatter.path,
|
|
|
|
component: courseTemplate,
|
|
|
|
})
|
|
|
|
});
|
|
|
|
|
2021-10-31 12:19:05 +03:00
|
|
|
//Render personal pages
|
|
|
|
const personalPageTemplate = path.resolve(`./src/components/templates/personalPageTemplate.js`);
|
|
|
|
const personalPages = result.data.personalPages.edges;
|
|
|
|
|
|
|
|
personalPages.forEach(({node}) => {
|
|
|
|
createPage({
|
|
|
|
path: node.frontmatter.path,
|
|
|
|
component: personalPageTemplate,
|
2021-11-08 15:12:30 +03:00
|
|
|
context:{
|
|
|
|
id: node.frontmatter.id
|
|
|
|
}
|
2021-10-31 12:19:05 +03:00
|
|
|
})
|
|
|
|
});
|
|
|
|
|
2021-03-28 21:32:20 +03:00
|
|
|
// Render news page
|
2020-03-21 20:41:52 +03:00
|
|
|
|
|
|
|
const newsTemplate = path.resolve(`./src/components/templates/news.js`);
|
|
|
|
const posts = result.data.news.edges;
|
2020-08-24 14:46:46 +03:00
|
|
|
|
2020-03-21 20:41:52 +03:00
|
|
|
const postsPerPage = 5;
|
|
|
|
const numberOfNewsItems = posts.length;
|
|
|
|
const numberOfNewsPages = Math.ceil(numberOfNewsItems / postsPerPage);
|
2020-08-24 14:46:46 +03:00
|
|
|
|
|
|
|
|
2020-03-21 20:41:52 +03:00
|
|
|
for (let pageIndex = 0; pageIndex < numberOfNewsPages; pageIndex++) {
|
2020-08-24 14:46:46 +03:00
|
|
|
const pageNumber = pageIndex + 1;
|
|
|
|
const path = pageIndex === 0 ? '/news' : `/news/${pageNumber}`;
|
|
|
|
const skip = pageIndex * postsPerPage;
|
|
|
|
|
|
|
|
function getPreviousPageLink() {
|
|
|
|
if (!pageIndex) return null
|
|
|
|
if (pageIndex === 1) return '/news'
|
|
|
|
return `/news/${pageIndex}`
|
|
|
|
}
|
|
|
|
|
|
|
|
function getNextPageLink() {
|
|
|
|
if (pageNumber < numberOfNewsPages) return `news/${pageNumber + 1}`
|
|
|
|
return null
|
|
|
|
}
|
|
|
|
|
|
|
|
createPage({
|
|
|
|
path,
|
|
|
|
component: newsTemplate,
|
|
|
|
context: {
|
|
|
|
limit: postsPerPage,
|
|
|
|
skip,
|
|
|
|
next: getNextPageLink(),
|
|
|
|
prev: getPreviousPageLink(),
|
|
|
|
},
|
|
|
|
})
|
2020-03-21 20:41:52 +03:00
|
|
|
}
|
2021-04-03 22:11:37 +03:00
|
|
|
}
|