Skip to content

Commit 3c14804

Browse files
committed
✨ feat: Add JSON-LD Structured Data to project
1 parent a05e368 commit 3c14804

File tree

7 files changed

+61
-2
lines changed

7 files changed

+61
-2
lines changed

src/components/App.astro

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import Presentation from './Presentation.astro';
88
import { getI18N } from '../i18n/';
99
import Experience from './Experience.astro';
1010
import Articles from './Articles.astro';
11+
import HeadMeta from '../components/Header/HeadMeta.astro';
12+
1113
export interface Props {
1214
public_src: string;
1315
}
@@ -16,6 +18,7 @@ const i18n = getI18N({ currentLocale });
1618
---
1719

1820
<Layout {...i18n}>
21+
<HeadMeta SEO_TITLE={i18n.SEO_TITLE} SEO_DESCRIPTION={i18n.SEO_DESCRIPTION} slot="structured-data" />
1922
<Header {...i18n} {...Astro.props} />
2023
<main>
2124
<Presentation {...i18n} />

src/components/Articles.astro

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ const allPosts = await Astro.glob('../pages/posts/*.md');
3030
class="w-48 rounded-xl max-sm:w-full aspect-video"
3131
alt={post.frontmatter.image.alt}
3232
/>
33-
3433
<section>
3534
<CustomParagraph
3635
textColor="text-slate-50"
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
export interface Props {
3+
SEO_TITLE: string;
4+
SEO_DESCRIPTION: string;
5+
}
6+
7+
const { SEO_TITLE, SEO_DESCRIPTION } = Astro.props;
8+
9+
let schema = JSON.stringify({
10+
"@context": "https://schema.org/",
11+
"@type": "WebSite",
12+
"headline": SEO_TITLE,
13+
"description": SEO_DESCRIPTION,
14+
"author": {
15+
"@type": "Person",
16+
"name": "Carlos Rodríguez"
17+
}
18+
});
19+
---
20+
<script type="application/ld+json" set:html={schema}></script>
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
---
2+
import type { CollectionEntry } from "astro:content";
3+
4+
type Props = CollectionEntry<"blog">["data"];
5+
6+
const { title, description, pubDate, image } =
7+
Astro.props as Props;
8+
9+
const pageUrl = new URL(Astro.url.pathname, Astro.site);
10+
const imageUrl = new URL(image.src, Astro.site)
11+
function removeAllTags(str) {
12+
return str.replace(/<\/?[\w\s="/.':;#-\/]+>/g, '');
13+
}
14+
const structuredData = {
15+
"@context": "https://schema.org",
16+
"@type": "Article",
17+
headline: title,
18+
description: removeAllTags(description),
19+
datePublished: pubDate,
20+
url: pageUrl,
21+
thumbnailUrl: imageUrl,
22+
image: {
23+
"@type": "ImageObject",
24+
url: imageUrl,
25+
caption: image.alt,
26+
},
27+
author: {
28+
"@type": "Person",
29+
name: 'Carlos Rodríguez',
30+
},
31+
};
32+
---
33+
34+
<script type="application/ld+json" set:html={JSON.stringify(structuredData)} />

src/layouts/Layout.astro

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ const canonicalURL = new URL(Astro.url.pathname, Astro.site);
6161
<script
6262
src="https://cdnjs.cloudflare.com/ajax/libs/flowbite/1.8.0/flowbite.min.js"
6363
is:inline></script>
64+
<slot name="structured-data" />
6465
<body>
6566
<ViewTransitions />
6667
<slot />

src/layouts/MarkdownPostLayout.astro

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import SectionContainer from '@components/shared/SectionContainer.astro';
66
import Title from '@components/shared/Title.astro';
77
import '../styles/post-styles.css';
88
import { primaryFormatDate } from '@utils/dateUtils';
9+
import PostMeta from '@components/Header/PostMeta.astro';
910
export interface Props {
1011
frontmatter: {
1112
title: string;
@@ -32,6 +33,7 @@ const postLayoutProps = { ...i18n, SEO_TITLE, SEO_DESCRIPTION };
3233
---
3334

3435
<Layout {...postLayoutProps}>
36+
<PostMeta {...frontmatter} slot="structured-data" />
3537
<div
3638
class="absolute -z-10 m-0 h-screen w-full bg-[radial-gradient(ellipse_80%_80%_at_50%_-20%,rgba(120,119,198,0.4),rgba(255,255,255,0))]"
3739
>

src/pages/posts/enriquece-el-drag-and-drop-de-tu-aplicacion-de-vue-3-con-vue-fluid-dnd.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ pubDate: 2024-04-26
55
description: 'En este artículo presenta a <strong>Vue Fluid DnD</strong> como una alternativa a funcionalidades drag and drop en <strong>Vue 3</strong>'
66
image:
77
src: '/images/vue-fluid-dnd-cover.webp'
8-
alt: 'Vue logo'
8+
alt: 'Vue Fluid DnD logo'
99
---
1010

1111
En las aplicaciones web que usan frameworks reactivos como **vue**, **react**, **angular**, etc es muy común la necesidad de organizar listas u otras colecciones de elementos ordenándolas o añadiendo, eliminando o trasladando elementos en estas.

0 commit comments

Comments
 (0)