Skip to content

Commit d4e03b5

Browse files
creating schema data for jobs
1 parent a2eec78 commit d4e03b5

File tree

2 files changed

+57
-2
lines changed

2 files changed

+57
-2
lines changed

src/layouts/baseLayout.astro

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import PageMetaTags from "../components/pageMetaTags.astro";
33
import NavBar from "../components/navBar.astro";
44
import Footer from "../components/footer.astro";
55
import MainDrawer from "../components/mainDrawer.astro";
6+
import { Schema } from "astro-seo-schema";
67
78
const {
89
title,
@@ -11,6 +12,7 @@ const {
1112
hasRightSidebar = false,
1213
noIndex = false,
1314
canonicalUrl,
15+
seoSchema,
1416
} = Astro.props;
1517
---
1618

@@ -32,7 +34,8 @@ const {
3234
<link rel="icon" type="image/svg+xml" href="/assets/img/favicon.png" />
3335
<meta name="generator" content={Astro.generator} />
3436
{canonicalUrl && <link rel="canonical" href={canonicalUrl} />}
35-
{noIndex && <meta name="robots" content="noindex">}
37+
{noIndex && <meta name="robots" content="noindex" />}
38+
{seoSchema && <Schema item={seoSchema} />}
3639
<PageMetaTags title={title} description={description} image={image} />
3740
</head>
3841
<body class="bg-gray-50">

src/pages/empleos/[...slug].astro

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import { backend_url } from "../../data/conf.json";
33
import BaseLayout from "../../layouts/baseLayout.astro";
44
import JobHeader from "../../components/jobs/jobHeader.astro";
55
import OthersJobsCta from "../../components/jobs/othersJobsCta.astro";
6+
import dayjs from "dayjs";
7+
import profileCategories from "../../data/profileCategories.json";
68
79
export async function getStaticPaths() {
810
const response = await fetch(backend_url + "api/jobs/get-all-jobs");
@@ -15,9 +17,59 @@ export async function getStaticPaths() {
1517
}
1618
1719
const { job, nextJobs } = Astro.props;
20+
21+
let seoSchema = {
22+
"@context": "https://schema.org/",
23+
"@type": "JobPosting",
24+
description: `<p>${job.title} \n\n ${job.description}</p>`,
25+
datePosted: dayjs(job.pubDate).format("YYYY-MM-DD"),
26+
applicantLocationRequirements: {
27+
"@type": "Country",
28+
name: "CUBA",
29+
},
30+
};
31+
32+
if (job.remote) {
33+
seoSchema["jobLocationType"] = "TELECOMMUTE";
34+
}
35+
36+
if (job.presential && job.location) {
37+
seoSchema["jobLocation"] = {
38+
"@type": "Place",
39+
name: job.location,
40+
};
41+
}
42+
43+
if (job.organization) {
44+
seoSchema["hiringOrganization"] = {
45+
"@type": "Organization",
46+
name: job.organization,
47+
};
48+
if (job.organization_site) {
49+
seoSchema["hiringOrganization"]["sameAs"] = job.organization_site;
50+
}
51+
}
52+
53+
let jobTitle = job.categories.map((category) => profileCategories[category].text).join(", ");
54+
let jobType;
55+
56+
if (job.fulltime) {
57+
seoSchema["employmentType"] = "FULL_TIME";
58+
jobType = "Full-time";
59+
}
60+
if (job.parttime) {
61+
seoSchema["employmentType"] = "PART_TIME";
62+
jobType = "Part-time";
63+
}
64+
if (job.freelance) {
65+
seoSchema["employmentType"] = "CONTRACTOR";
66+
jobType = "Freelance";
67+
}
68+
69+
seoSchema["title"] = jobType ? jobType + " " + jobTitle : jobTitle;
1870
---
1971

20-
<BaseLayout title={`${job.title} | CuCoders Jobs`}>
72+
<BaseLayout title={`${job.title} | CuCoders Jobs`} seoSchema={seoSchema} description={job.description.slice(0, 180)}>
2173
<JobHeader job={job} />
2274
<div
2375
class="bg-white border md:mx-auto mb-5 py-7 px-9 lg:max-w-[58rem] border-gray-200 rounded-lg dark:bg-gray-800 dark:border-gray-700 w-full"

0 commit comments

Comments
 (0)