diff --git a/src/templates/BlogItemDetail.js b/src/templates/BlogItemDetail.js index 790ab9a..d7dfb81 100644 --- a/src/templates/BlogItemDetail.js +++ b/src/templates/BlogItemDetail.js @@ -4,18 +4,25 @@ import MarkdownView from "react-showdown" import Layout from "../components/layout" import { Seo, BannerTop, CustomImage } from "../components/index.js" import PropTypes from "prop-types" -import { Helmet } from "react-helmet" // Importa Helmet +import { Helmet } from "react-helmet" import "./BlogItemDetail.scss" +const stripHtml = s => (s ? s.replace(/<[^>]+>/g, "").trim() : s) +const toISODuration = m => (m ? `PT${Math.max(0, Number(m))}M` : undefined) +const pickHowTo = (blocks = []) => + blocks.find(b => { + const uid = b?.strapi_component || b?.__component + return uid && uid.includes("howto") && b?.tieneHowTo === true + }) + const BlogDetail = ({ data }) => { - const { title, description, image, imagePage, author, seo, published_at, updated_at } = + const { title, description, image, imagePage, author, seo, published_at, updated_at, body } = // HOWTO: aƱadimos `body` data?.allStrapiArticle?.nodes[0] || {} const bannerTop = imagePage ? { title, imagePage } : { title, image } -const img = imagePage || image; -const imgWidth = img.width || img.localFile.childImageSharp.original.width; -const imgHeight = img.height || img.localFile.childImageSharp.original.height; - + const img = imagePage || image; + const imgWidth = img.width || img.localFile.childImageSharp.original.width; + const imgHeight = img.height || img.localFile.childImageSharp.original.height; const structuredData = { "@context": "https://schema.org", @@ -52,6 +59,23 @@ const imgHeight = img.height || img.localFile.childImageSharp.original.height; }, } + const blocks = Array.isArray(body) ? body : [] + const howto = pickHowTo(blocks) + + const structuredHowTo = howto && { + "@context": "https://schema.org", + "@type": "HowTo", + name: howto.title || title, + description: stripHtml(howto.descripcion || howto.description), + totalTime: toISODuration(howto.totalMinutes), + tool: (howto.tools || []).map(t => t?.name).filter(Boolean), + step: (howto.steps || []).map(s => ({ + "@type": "HowToStep", + name: s?.name, + text: stripHtml(s?.text), + })), + } + return ( + {structuredHowTo && ( + + + + )} +
@@ -161,6 +193,7 @@ export const query = graphql` published_at updated_at destacado + body seo { pageTitle pageDescription