Skip to content

Commit c07708f

Browse files
committed
solve conflict
1 parent 88099e4 commit c07708f

File tree

1 file changed

+71
-54
lines changed

1 file changed

+71
-54
lines changed

src/pages/how-to/technology/[technology].jsx

Lines changed: 71 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -37,64 +37,81 @@ export const getStaticProps = async ({ params, locale, locales }) => {
3737
const { technology } = params;
3838
const currentLang = locale === 'en' ? 'us' : 'es';
3939

40-
const responseTechs = await fetch(`${process.env.BREATHECODE_HOST}/v1/registry/academy/technology?slug=${technology}&limit=1000&academy=${WHITE_LABEL_ACADEMY}`, {
41-
method: 'GET',
42-
headers: {
43-
Authorization: `Token ${process.env.BC_ACADEMY_TOKEN}`,
44-
Academy: 4,
45-
},
46-
});
47-
const techs = await responseTechs.json(); // array of objects
48-
const technologyData = techs.results.find((tech) => tech.slug === technology);
49-
50-
const qs = parseQuerys({
51-
asset_type: 'ARTICLE',
52-
visibility: 'PUBLIC',
53-
status: 'PUBLISHED',
54-
academy: WHITE_LABEL_ACADEMY,
55-
limit: 1000,
56-
technologies: technology,
57-
});
58-
59-
const response = await fetch(`${process.env.BREATHECODE_HOST}/v1/registry/asset${qs}`);
60-
const exercises = await response.json();
61-
62-
const dataFiltered = exercises?.results?.filter(
63-
(l) => l?.category?.slug === 'how-to' || l?.category?.slug === 'como',
64-
);
40+
try {
41+
const responseTechs = await fetch(`${process.env.BREATHECODE_HOST}/v1/registry/academy/technology?slug=${technology}&limit=1000&academy=${WHITE_LABEL_ACADEMY}`, {
42+
method: 'GET',
43+
headers: {
44+
Authorization: `Token ${process.env.BC_ACADEMY_TOKEN}`,
45+
Academy: 4,
46+
},
47+
});
48+
49+
if (!responseTechs.ok) {
50+
console.error(`Error fetching technology data: ${responseTechs.status}`);
51+
return { notFound: true };
52+
}
53+
54+
const techs = await responseTechs.json();
55+
const technologyData = techs.results?.find((tech) => tech.slug === technology);
56+
57+
if (!technologyData) {
58+
return { notFound: true };
59+
}
60+
61+
const qs = parseQuerys({
62+
asset_type: 'ARTICLE',
63+
visibility: 'PUBLIC',
64+
status: 'PUBLISHED',
65+
academy: WHITE_LABEL_ACADEMY,
66+
limit: 1000,
67+
technologies: technology,
68+
});
69+
70+
const response = await fetch(`${process.env.BREATHECODE_HOST}/v1/registry/asset${qs}`);
71+
72+
if (!response.ok) {
73+
console.error(`Error fetching articles: ${response.status}`);
74+
return { notFound: true };
75+
}
76+
77+
const exercises = await response.json();
78+
const dataFiltered = exercises?.results?.filter(
79+
(l) => l?.category?.slug === 'how-to' || l?.category?.slug === 'como',
80+
) || [];
81+
82+
if (dataFiltered.length === 0) {
83+
return { notFound: true };
84+
}
85+
86+
const ogUrl = {
87+
en: `/how-to/technology/${technology}`,
88+
us: `/how-to/technology/${technology}`,
89+
};
6590

66-
if (response.status >= 400 || response.status_code >= 400
67-
|| !technologyData || dataFiltered?.length === 0) {
6891
return {
69-
notFound: true,
92+
props: {
93+
seo: {
94+
title: technologyData?.title,
95+
description: '',
96+
image: technologyData?.icon_url || '',
97+
pathConnector: `/how-to/technology/${technology}`,
98+
url: ogUrl.en,
99+
type: 'website',
100+
card: 'default',
101+
locales,
102+
locale,
103+
},
104+
fallback: false,
105+
technologyData,
106+
articles: dataFiltered.filter((project) => project.lang === currentLang).map(
107+
(l) => ({ ...l, difficulty: l.difficulty?.toLowerCase() || null }),
108+
),
109+
},
70110
};
111+
} catch (error) {
112+
console.error('Error in getStaticProps:', error);
113+
return { notFound: true };
71114
}
72-
73-
const ogUrl = {
74-
en: `/how-to/technology/${technology}`,
75-
us: `/how-to/technology/${technology}`,
76-
};
77-
78-
return {
79-
props: {
80-
seo: {
81-
title: technologyData?.title,
82-
description: '',
83-
image: technologyData?.icon_url || '',
84-
pathConnector: `/how-to/technology/${technology}`,
85-
url: ogUrl.en,
86-
type: 'website',
87-
card: 'default',
88-
locales,
89-
locale,
90-
},
91-
fallback: false,
92-
technologyData,
93-
articles: dataFiltered.filter((project) => project.lang === currentLang).map(
94-
(l) => ({ ...l, difficulty: l.difficulty?.toLowerCase() || null }),
95-
),
96-
},
97-
};
98115
};
99116

100117
function ExercisesByTechnology({ articles, technologyData }) {

0 commit comments

Comments
 (0)