diff --git a/content/sections/church-magazine.md b/content/sections/church-magazine.md index e10ce7c..5407567 100644 --- a/content/sections/church-magazine.md +++ b/content/sections/church-magazine.md @@ -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 diff --git a/gatsby-node.js b/gatsby-node.js index e09c860..4aa930c 100644 --- a/gatsby-node.js +++ b/gatsby-node.js @@ -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, -// }, -// }) -// }) -// }) -// } \ No newline at end of file + 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, + }, + }) + }) + }) +} \ No newline at end of file diff --git a/src/components/HeraldArchive.tsx b/src/components/HeraldArchive.tsx new file mode 100644 index 0000000..de70147 --- /dev/null +++ b/src/components/HeraldArchive.tsx @@ -0,0 +1,38 @@ +import React from 'react' +import { StaticQuery, graphql } from 'gatsby' + +const HeraldArchive = () => ( + ( +
+ {data.allMarkdownRemark.nodes.map((node, index: number) => ( + + +

+ {node.frontmatter.title} +

+
+ ))} +
+ )} + /> +) + +export default HeraldArchive diff --git a/src/pages/herald.tsx b/src/pages/herald.tsx deleted file mode 100644 index 25f63da..0000000 --- a/src/pages/herald.tsx +++ /dev/null @@ -1,68 +0,0 @@ -import React from 'react' -import { graphql } from 'gatsby' -import Layout from '../components/Layout' -import SEO from '../components/seo' -import Title from '../components/Title'; - -export default ({ data }) => { - const summary = data.summary.nodes[0]; - const issues = data.issues.nodes; - - return ( - - - -
-
- - - <h2>{summary.frontmatter.title}</h2> - <div dangerouslySetInnerHTML={{ __html: summary.html }} /> - - <div className="items style1 medium onscroll-fade-in"> - {issues.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> - </div> - </section> - </Layout> - ) -} - -export const query = graphql` -query { - summary: allMarkdownRemark( - filter: { fileAbsolutePath: { regex:"/.*/fixed/herald.md/" } }, - limit: 1 - ) - { - nodes { - frontmatter{ - title - } - html - } - } - - issues: allMarkdownRemark( - filter: { fileAbsolutePath: { regex:"/.*/herald/.*/" } }, - sort: { fields: [frontmatter___date], order: DESC }, - limit: 12 - ) - { - nodes { - frontmatter{ - title - pdf - } - } - totalCount - } -} -` \ No newline at end of file diff --git a/src/templates/page.tsx b/src/templates/page.tsx new file mode 100644 index 0000000..3702871 --- /dev/null +++ b/src/templates/page.tsx @@ -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 + } +} +` \ No newline at end of file diff --git a/static/admin/config.yml b/static/admin/config.yml index 24fa287..cd7cb78 100644 --- a/static/admin/config.yml +++ b/static/admin/config.yml @@ -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: @@ -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 \ No newline at end of file + - { name: pdf, label: PDF, widget: file } \ No newline at end of file