Skip to content

Commit

Permalink
Pages should now be created for the pages collection. list magazines …
Browse files Browse the repository at this point in the history
…functionality for pages now works. Previous static page collection has been removed.
  • Loading branch information
FTWinston committed Apr 29, 2019
1 parent 00f20e4 commit 6ac7d26
Show file tree
Hide file tree
Showing 6 changed files with 120 additions and 131 deletions.
2 changes: 1 addition & 1 deletion content/sections/church-magazine.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ title: Church Magazine
image: /uploads/herald.jpg
order: 4
buttons:
- target: /herald
- target: /herald-magazine-archive
text: View Archive
- target: '#articles'
text: Read articles
Expand Down
68 changes: 34 additions & 34 deletions gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,39 +18,39 @@ exports.onCreateNode = ({ node, getNode, actions }) => {
fmImagesToRelative(node);
}

// exports.createPages = ({ graphql, actions }) => {
// const { createPage } = actions
exports.createPages = ({ graphql, actions }) => {
const { createPage } = actions

// const createPagesForDirectories = [
// 'pages',
// ];
const createPagesForDirectories = [
'pages',
];

// return graphql(`
// {
// allMarkdownRemark(
// filter: { fileAbsolutePath: { regex:"/.\/*(${createPagesForDirectories.join('|')})\/.*/" } },
// )
// {
// edges {
// node {
// fields {
// slug
// }
// }
// }
// }
// }`
// ).then(result => {
// result.data.allMarkdownRemark.edges.forEach(({ node }) => {
// createPage({
// path: node.fields.slug,
// component: path.resolve(`./src/templates/articleTemplate.js`),
// context: {
// // Data passed to context is available
// // in page queries as GraphQL variables.
// slug: node.fields.slug,
// },
// })
// })
// })
// }
return graphql(`
{
allMarkdownRemark(
filter: { fileAbsolutePath: { regex:"/.\/*(${createPagesForDirectories.join('|')})\/.*/" } },
)
{
edges {
node {
fields {
slug
}
}
}
}
}`
).then(result => {
result.data.allMarkdownRemark.edges.forEach(({ node }) => {
createPage({
path: node.fields.slug,
component: path.resolve(`./src/templates/page.tsx`),
context: {
// Data passed to context is available
// in page queries as GraphQL variables.
slug: node.fields.slug,
},
})
})
})
}
38 changes: 38 additions & 0 deletions src/components/HeraldArchive.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import React from 'react'
import { StaticQuery, graphql } from 'gatsby'

const HeraldArchive = () => (
<StaticQuery
query={graphql`
query {
allMarkdownRemark(
filter: { fileAbsolutePath: { regex:"/.*/herald/.*/" } },
sort: { fields: [frontmatter___date], order: DESC },
limit: 12
)
{
nodes {
frontmatter{
title
pdf
}
}
}
}
`}
render={data => (
<div className="items style1 medium onscroll-fade-in">
{data.allMarkdownRemark.nodes.map((node, index: number) => (
<a href={node.frontmatter.pdf} key={index}>
<span className="icon style2 major fa-save"></span>
<p className="major">
{node.frontmatter.title}
</p>
</a>
))}
</div>
)}
/>
)

export default HeraldArchive
68 changes: 0 additions & 68 deletions src/pages/herald.tsx

This file was deleted.

45 changes: 45 additions & 0 deletions src/templates/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import React from 'react'
import { graphql } from 'gatsby'
import Layout from '../components/Layout'
import SEO from '../components/seo'
import Title from '../components/Title';
import HeraldArchive from '../components/HeraldArchive';

export default ({ data }) => {
const post = data.markdownRemark

let functionality;
switch (post.frontmatter.functionality) {
case 'list magazines':
functionality = <HeraldArchive />
break
}

return (
<Layout>
<SEO title={post.frontmatter.title} />

<section className="wrapper style1 align-center">
<div className="inner">
<Title />

<h2>{post.frontmatter.title}</h2>
<div dangerouslySetInnerHTML={{ __html: post.html }} />
{functionality}
</div>
</section>
</Layout>
)
}

export const query = graphql`
query($slug: String!) {
markdownRemark(fields: { slug: { eq: $slug } }) {
frontmatter {
title
functionality
}
html
}
}
`
30 changes: 2 additions & 28 deletions static/admin/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ collections:
- name: page
label: Pages
label_singular: Page
description: "Pages are only accessible if they are linked from somewhere on the main page."
description: "The address of a page is its title, with spaces replaced with dashes. Remember to link to a page (e.g. from the main page), or nobody will find it."
folder: content/pages
create: true
fields:
Expand All @@ -46,30 +46,4 @@ collections:
fields:
- { name: date, label: Date, widget: date }
- { name: title, label: Title }
- { name: pdf, label: PDF, widget: file }
- name: fixed
label: "Fixed pages"
label_singular: "Fixed page"
files:
- file: "content/fixed/herald.md"
label: "Herald page"
name: "herald"
fields:
- {label: Title, name: title, widget: string}
- {label: Body, name: body, widget: markdown}
- file: "content/fixed/articles.md"
label: "Articles page"
name: "articles"
fields:
- {label: Title, name: title, widget: string}
- {label: Body, name: body, widget: markdown}
- label: Contact Entries
name: contact_entries
widget: list
fields:
- label: Heading
name: heading
widget: string
- label: Text
name: text
widget: text
- { name: pdf, label: PDF, widget: file }

0 comments on commit 6ac7d26

Please sign in to comment.