Skip to content

Commit

Permalink
multilanguage post fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobias Irigoyen committed Feb 1, 2022
1 parent 9b5e8d4 commit 16db5f0
Showing 1 changed file with 33 additions and 26 deletions.
59 changes: 33 additions & 26 deletions src/blogTemplates/blogPost.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React from "react";
import { graphql } from "gatsby";
import { changeLocale } from "gatsby-plugin-react-intl";
import { useEffect } from "react";
import styled from 'styled-components'
import Img from "gatsby-image"
import data from '../content/content.json'
Expand Down Expand Up @@ -208,16 +207,18 @@ const Btn = styled(Button)`
margin-right: auto;
`

export default function Post({ data, props }) {
export default function Post({ data: {allMarkdownRemark: { edges }} }) {
deckDeckGoHighlightElement();
const { html, frontmatter: post } = data.markdownRemark;
const intl = useIntl();

useEffect(() => {
if (post.lang !== "es") {
changeLocale(post.lang);
}
}, [post.lang]);
let post = edges[0].node.frontmatter;
let html = "";
const postFiqus = edges.forEach((e) => {
const { frontmatter: p } = e.node;
if (p.lang === intl.locale) {
post = p;
html = e.node.html;
}
})

return (
<PostContainer>
Expand Down Expand Up @@ -261,28 +262,34 @@ export default function Post({ data, props }) {
);
}


export const pageQuery = graphql`
query PostQuery($slug: String!) {
markdownRemark(frontmatter: { slug: { eq: $slug } }) {
html
frontmatter {
lang
type
title
author
slug
date
tags
image{
childImageSharp {
fluid(maxWidth: 800) {
...GatsbyImageSharpFluid
query ($slug: String!) {
allMarkdownRemark(filter: {frontmatter: { type: {eq: "post"}, slug: { eq: $slug } }}){
edges {
node {
id
html
frontmatter {
lang
type
title
author
slug
date
tags
image{
childImageSharp {
fluid(maxWidth: 800) {
...GatsbyImageSharpFluid
}
}
}
imageCredits
}
timeToRead
}
imageCredits
}
timeToRead
}
}
`;

0 comments on commit 16db5f0

Please sign in to comment.