Skip to content

Commit

Permalink
Merge pull request #11 from CivicActions/new-strapi-datasource-ii
Browse files Browse the repository at this point in the history
Connect to new Strapi datasource
  • Loading branch information
iris-i authored Oct 16, 2020
2 parents aa3b764 + 4647344 commit 50469a5
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 27 deletions.
12 changes: 9 additions & 3 deletions gatsby-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,17 @@ module.exports = {
{
resolve: 'gatsby-source-strapi',
options: {
apiURL: 'https://fe-knowledgebase-cms.herokuapp.com',
apiURL: 'https://fe-strapi.herokuapp.com',
queryLimit: 1000,
contentTypes: [
'recipe',
'recipes',
'user'
]
],
singleTypes: [],
loginData: {
identifier: "",
password: "",
},
}
},
{
Expand Down
7 changes: 4 additions & 3 deletions gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ exports.createPages = async ({ graphql, actions }) => {
const recipeTemplate = path.resolve(`src/templates/recipes.jsx`);
const result = await graphql(`
query {
allStrapiRecipe {
allStrapiRecipes {
edges {
node {
Title
Body
Tags
author {
Author {
username
}
created_at
Expand All @@ -28,7 +28,8 @@ exports.createPages = async ({ graphql, actions }) => {
}
}
`)
result.data.allStrapiRecipe.edges.forEach(edge => {
console.log(result.data);
result.data.allStrapiRecipes.edges.forEach(edge => {
let slug = edge.node.Title.replace(/\s+/g, '-').toLowerCase();
createPage({
path: `recipes/${slug}`,
Expand Down
16 changes: 8 additions & 8 deletions src/components/RelatedRecipes.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import React from 'react';
import PropTypes from 'prop-types';
import { graphql, Link, StaticQuery } from 'gatsby';

const RelatedRecipies = ({ tag }) => (
const RelatedRecipes = ({ tag }) => (
<StaticQuery
query={graphql`
query recipeQuery {
allStrapiRecipe {
allStrapiRecipes {
edges {
node {
Title
Expand All @@ -19,15 +19,15 @@ const RelatedRecipies = ({ tag }) => (
`}
render={(data) => {
const related = [];
Object.keys(data.allStrapiRecipe.edges).forEach((id) => {
if (data.allStrapiRecipe.edges[id].node.Tags === tag) {
Object.keys(data.allStrapiRecipes.edges).forEach((id) => {
if (data.allStrapiRecipes.edges[id].node.Tags === tag) {
related.push(
<h3>
<Link
// @todo refactor the slug to make it more modular
to={`/recipes/${data.allStrapiRecipe.edges[id].node.Title.replace(/\s+/g, '-').toLowerCase()}`}
to={`/recipes/${data.allStrapiRecipes.edges[id].node.Title.replace(/\s+/g, '-').toLowerCase()}`}
>
{ data.allStrapiRecipe.edges[id].node.Title }
{ data.allStrapiRecipes.edges[id].node.Title }
</Link>
</h3>,
);
Expand All @@ -48,8 +48,8 @@ const RelatedRecipies = ({ tag }) => (
/>
);

export default RelatedRecipies;
export default RelatedRecipes;

RelatedRecipies.propTypes = {
RelatedRecipes.propTypes = {
tag: PropTypes.string.isRequired,
};
5 changes: 2 additions & 3 deletions src/components/layout.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@
import React from 'react';
import PropTypes from 'prop-types';
import { useStaticQuery, graphql } from 'gatsby';
import RelatedRecipies from './RelatedRecipes';
import Header from './header/header';
import '../sass/styles.scss';
import '../sass/components/layout.scss';

import RelatedRecipes from './RelatedRecipes';

const Layout = ({ children, tag }) => {
const data = useStaticQuery(graphql`
Expand All @@ -36,7 +35,7 @@ const Layout = ({ children, tag }) => {
}}
>
<main>{children}</main>
{tag ? <aside><RelatedRecipies tag={tag} /></aside> : '' }
{tag ? <aside><RelatedRecipes tag={tag} /></aside> : '' }
<footer>
©
{' '}
Expand Down
8 changes: 4 additions & 4 deletions src/pages/recipes/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const RecipesIndex = ({ data }) => (

<h2>All Recipes</h2>
<ul>
{data.allStrapiRecipe.edges.map((document) => (
{data.allStrapiRecipes.edges.map((document) => (
<li key={document.node.id}>
<h3>
<Link
Expand All @@ -33,20 +33,20 @@ export default RecipesIndex;

RecipesIndex.propTypes = {
data: PropTypes.shape({
allStrapiRecipe: PropTypes.objectOf(PropTypes.string),
allStrapiRecipes: PropTypes.objectOf(PropTypes.array),
}).isRequired,
};

export const pageQuery = graphql`
query IndexQuery {
allStrapiRecipe {
allStrapiRecipes {
edges {
node {
Title
Body
Tags
Summary
author {
Author {
username
}
created_at
Expand Down
12 changes: 6 additions & 6 deletions src/templates/recipes.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import AuthorLink from '../components/author-link';
const converter = new showdown.Converter({ ghCompatibleHeaderId: true });

const RecipeTemplate = ({ data }) => {
const recipe = data.strapiRecipe;
const author = recipe.author ? <AuthorLink uid={recipe.author.id} name={recipe.author.username} /> : '';
const recipe = data.strapiRecipes;
const author = recipe.Author ? <AuthorLink uid={recipe.Author.id} name={recipe.Author.username} /> : '';

return (
<Layout>
Expand All @@ -28,19 +28,19 @@ export default RecipeTemplate;

RecipeTemplate.propTypes = {
data: PropTypes.shape({
strapiRecipe: PropTypes.objectOf(PropTypes.string),
strapiRecipes: PropTypes.string,
}).isRequired,
};

export const query = graphql`
query RecipeTemplate($id: String!) {
strapiRecipe(id: { eq: $id }) {
strapiRecipes(id: { eq: $id }) {
Title
Created
created_at
Body
Tags
id
author {
Author {
id
username
}
Expand Down

0 comments on commit 50469a5

Please sign in to comment.