Skip to content

Commit

Permalink
contentful friends (#777)
Browse files Browse the repository at this point in the history
  • Loading branch information
zyzik1248 authored Jun 29, 2023
1 parent e8f1ed8 commit 9fceca4
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 46 deletions.
32 changes: 16 additions & 16 deletions gatsby-node.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
const path = require('path');
const { createFilePath } = require(`gatsby-source-filesystem`);
// const { createFilePath } = require(`gatsby-source-filesystem`);
const FilterWarningsPlugin = require('webpack-filter-warnings-plugin');

exports.onCreateNode = ({ node, getNode, actions }) => {
const { createNodeField } = actions;
if (node.internal.type === `MarkdownRemark`) {
const slug = createFilePath({ node, getNode, basePath: `pages` });
const separtorIndex = ~slug.indexOf('--') ? slug.indexOf('--') : 0;
const shortSlugStart = separtorIndex ? separtorIndex + 2 : 0;
createNodeField({
node,
name: `slug`,
value: `${separtorIndex ? '/' : ''}${slug.substring(shortSlugStart)}`,
});
createNodeField({
node,
name: `prefix`,
value: separtorIndex ? slug.substring(1, separtorIndex) : '',
});
}
// if (node.internal.type === `MarkdownRemark`) {
// const slug = createFilePath({ node, getNode, basePath: `pages` });
// const separtorIndex = ~slug.indexOf('--') ? slug.indexOf('--') : 0;
// const shortSlugStart = separtorIndex ? separtorIndex + 2 : 0;
// createNodeField({
// node,
// name: `slug`,
// value: `${separtorIndex ? '/' : ''}${slug.substring(shortSlugStart)}`,
// });
// createNodeField({
// node,
// name: `prefix`,
// value: separtorIndex ? slug.substring(1, separtorIndex) : '',
// });
// }
};

exports.createPages = async function ({ graphql, actions }) {
Expand Down
35 changes: 25 additions & 10 deletions src/friends/components/FriendLogo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,33 @@ import React from 'react';
export const FriendLogo: React.FC<IResponsiveImage> = ({ imageSrc, title }) => (
<StaticQuery
query={graphql`
query {
images: allFile(filter: { sourceInstanceName: { eq: "friend-images" } }) {
nodes {
extension
relativePath
childImageSharp {
gatsbyImageData(layout: CONSTRAINED, placeholder: BLURRED)
}
}
query {
images: allContentfulAsset {
nodes {
title
name: filename
relativePath: url
url
id
gatsbyImageData(layout: CONSTRAINED, placeholder: BLURRED)
}
}
}
`}
render={(data) => renderFromQuery(data.images.nodes, imageSrc, title)}
render={(data) => {
const images = data.images.nodes.map((node: any) => ({
name: node.name,
relativePath: node.relativePath,
childImageSharp: {
gatsbyImageData: node.gatsbyImageData,
id: node.id,
},
}));
return (
<>
{renderFromQuery(images, imageSrc, title)}
</>
);
}}
/>
);
40 changes: 22 additions & 18 deletions src/friends/state/friends-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,18 @@ import { IGatsbyNode } from '@App/generics';

export interface IFriendNode extends IGatsbyNode {
name: string;
description: string;
description: {
description: string
}
image: {
base: string;
url: string;
};
page: string;
slug: string;
}

export interface IFriendsGraph {
allFriendsYaml: {
allContentfulFriends: {
nodes: IFriendNode[];
};
}
Expand All @@ -30,31 +32,33 @@ export class FriendsLoader {
private static getAllNodes() {
const resultGraph: IFriendsGraph = useStaticQuery(
graphql`
{
allFriendsYaml {
nodes {
id
name
description
image {
base
}
page
slug
}
{
allContentfulFriends {
nodes {
id
name
image {
url
}
slug
page
description {
description
}
}
}
}
`
);

return resultGraph?.allFriendsYaml?.nodes;
return resultGraph?.allContentfulFriends?.nodes;
}

private static toDataModel = (node: IFriendNode): IFriendData => ({
id: node.id,
name: node.name,
image: node.image.base,
description: node.description,
image: node.image.url,
description: node.description.description,
page: node.page,
slug: node.slug,
});
Expand Down
4 changes: 2 additions & 2 deletions src/utils/browser/SEOMetadata.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,11 @@ const SEOMetadata: React.FC<ISEOMetadata> = ({ image = '', pageTitle, descriptio
? [
{
name: 'og:image',
content: `${site.siteMetadata.siteUrl}${image}`,
content: image,
},
{
name: 'twitter:image',
content: `${site.siteMetadata.siteUrl}${image}`,
content: image,
},
{
name: 'og:image:width',
Expand Down

0 comments on commit 9fceca4

Please sign in to comment.