Skip to content

Commit

Permalink
feat: removed news page
Browse files Browse the repository at this point in the history
  • Loading branch information
Guiso92 committed Mar 28, 2024
1 parent 9fa5e55 commit 94094dd
Show file tree
Hide file tree
Showing 9 changed files with 94 additions and 36 deletions.
4 changes: 4 additions & 0 deletions lib/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ export const CATEGORIES_TO_HIDE: number[] = [
4409778008599, 4410571554839, 4410629239959,
];

export const MENU_CATEGORIES_TO_HIDE: number[] = [
4410571554839, 4410629239959, 4409778008599,
];

// A map from a locale code to Zendesk locale id used for dynamic content translations.
// https://developer.zendesk.com/api-reference/ticketing/account-configuration/locales/
// Keep in sync with locales configured in /next.config.js.
Expand Down
2 changes: 1 addition & 1 deletion lib/logo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import logoEnUs from '../public/importa-mi-logo.png';

export const getHeaderLogoProps = (currentLocale: Locale): LogoProps => {
let imgSrc: string;
switch (currentLocale.url) {
switch (currentLocale?.url) {
case 'en-us':
default:
imgSrc = logoEnUs.src;
Expand Down
4 changes: 2 additions & 2 deletions lib/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ export function getMenuItems(
});
items.push({
key: 'news',
label: strings.news,
href: '/news',
label: 'News',
href: '/categories/4409778008599',
});
if (includeAbout) {
items.push({
Expand Down
15 changes: 13 additions & 2 deletions pages/404.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
CATEGORIES_TO_HIDE,
CATEGORY_ICON_NAMES,
GOOGLE_ANALYTICS_IDS,
MENU_CATEGORIES_TO_HIDE,
REVALIDATION_TIMEOUT_SECONDS,
SEARCH_BAR_INDEX,
SECTION_ICON_NAMES,
Expand Down Expand Up @@ -98,6 +99,7 @@ export const getStaticProps: GetStaticProps = async ({ locale }) => {
const strings: Custom404Strings = populateCustom404Strings(dynamicContent);

let categories: ZendeskCategory[] | CategoryWithSections[];
let menuCategories: ZendeskCategory[] | CategoryWithSections[];
if (USE_CAT_SEC_ART_CONTENT_STRUCTURE) {
categories = await getCategoriesWithSections(
currentLocale,
Expand All @@ -109,12 +111,21 @@ export const getStaticProps: GetStaticProps = async ({ locale }) => {
(s) => (s.icon = SECTION_ICON_NAMES[s.id] || 'help_outline')
);
});
menuCategories = await getCategoriesWithSections(
currentLocale,
getZendeskUrl(),
(c) => !MENU_CATEGORIES_TO_HIDE.includes(c.id)
);
} else {
categories = await getCategories(currentLocale, getZendeskUrl());
categories = categories.filter((c) => !CATEGORIES_TO_HIDE.includes(c.id));
categories.forEach(
(c) => (c.icon = CATEGORY_ICON_NAMES[c.id] || 'help_outline')
);
menuCategories = await getCategories(currentLocale, getZendeskUrl());
menuCategories = menuCategories.filter(
(c) => !MENU_CATEGORIES_TO_HIDE.includes(c.id)
);
}

const aboutUsArticle = await getArticle(
Expand All @@ -126,12 +137,12 @@ export const getStaticProps: GetStaticProps = async ({ locale }) => {
);
const menuOverlayItems = getMenuItems(
populateMenuOverlayStrings(dynamicContent),
categories,
menuCategories,
!!aboutUsArticle
);
const footerLinks = getFooterItems(
populateMenuOverlayStrings(dynamicContent),
categories
menuCategories
);
return {
props: {
Expand Down
16 changes: 14 additions & 2 deletions pages/articles/[article].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import {
CATEGORIES_TO_HIDE,
CATEGORY_ICON_NAMES,
GOOGLE_ANALYTICS_IDS,
MENU_CATEGORIES_TO_HIDE,
REVALIDATION_TIMEOUT_SECONDS,
SEARCH_BAR_INDEX,
SECTION_ICON_NAMES,
Expand Down Expand Up @@ -212,6 +213,7 @@ export const getStaticProps: GetStaticProps = async ({
);

let categories: ZendeskCategory[] | CategoryWithSections[];
let menuCategories: ZendeskCategory[] | CategoryWithSections[];
if (USE_CAT_SEC_ART_CONTENT_STRUCTURE) {
categories = await getCategoriesWithSections(
currentLocale,
Expand All @@ -223,13 +225,23 @@ export const getStaticProps: GetStaticProps = async ({
(s) => (s.icon = SECTION_ICON_NAMES[s.id] || 'help_outline')
);
});
menuCategories = await getCategoriesWithSections(
currentLocale,
getZendeskUrl(),
(c) => !MENU_CATEGORIES_TO_HIDE.includes(c.id)
);
} else {
categories = await getCategories(currentLocale, getZendeskUrl());
categories = categories.filter((c) => !CATEGORIES_TO_HIDE.includes(c.id));
categories.forEach(
(c) => (c.icon = CATEGORY_ICON_NAMES[c.id] || 'help_outline')
);
menuCategories = await getCategories(currentLocale, getZendeskUrl());
menuCategories = menuCategories.filter(
(c) => !MENU_CATEGORIES_TO_HIDE.includes(c.id)
);
}

const aboutUsArticle = await getArticle(
currentLocale,
ABOUT_US_ARTICLE_ID,
Expand All @@ -239,15 +251,15 @@ export const getStaticProps: GetStaticProps = async ({
);
const menuOverlayItems = getMenuItems(
populateMenuOverlayStrings(dynamicContent),
categories,
menuCategories,
!!aboutUsArticle
);

const strings = populateArticlePageStrings(dynamicContent);

const footerLinks = getFooterItems(
populateMenuOverlayStrings(dynamicContent),
categories
menuCategories
);

const article = await getArticle(
Expand Down
48 changes: 25 additions & 23 deletions pages/categories/[category].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
getArticle,
getArticlesForSection,
getCategories,
getCategoriesWithSections,
getTranslationsFromDynamicContent,
} from '@ircsignpost/signpost-base/dist/src/zendesk';
import { GetStaticProps } from 'next';
Expand All @@ -22,10 +23,10 @@ import {
CATEGORIES_TO_HIDE,
CATEGORY_ICON_NAMES,
GOOGLE_ANALYTICS_IDS,
MENU_CATEGORIES_TO_HIDE,
REVALIDATION_TIMEOUT_SECONDS,
SEARCH_BAR_INDEX,
SITE_TITLE,
USE_CAT_SEC_ART_CONTENT_STRUCTURE,
ZENDESK_AUTH_HEADER,
} from '../../lib/constants';
import {
Expand All @@ -39,6 +40,7 @@ import { getFooterItems, getMenuItems } from '../../lib/menu';
import {
CATEGORY_PLACEHOLDERS,
COMMON_DYNAMIC_CONTENT_PLACEHOLDERS,
SECTION_PLACEHOLDERS,
getLastUpdatedLabel,
populateCategoryStrings,
populateFilterSelectStrings,
Expand Down Expand Up @@ -134,16 +136,6 @@ async function getStaticParams() {
}

export async function getStaticPaths() {
if (USE_CAT_SEC_ART_CONTENT_STRUCTURE) {
// Category page does not exist in this type of content structure.
// All paths under categories should return 404
// (https://nextjs.org/docs/api-reference/data-fetching/get-static-paths#fallback-false).
return {
paths: [],
fallback: false,
};
}

const categoryParams = await getStaticParams();

return {
Expand All @@ -162,10 +154,6 @@ function getStringPath(category: string, locale: string): string {
}

export async function getStringPaths(): Promise<string[]> {
if (USE_CAT_SEC_ART_CONTENT_STRUCTURE) {
// Category page does not exist in this type of content structure.
return [];
}
const params = await getStaticParams();
return params.map((param) => getStringPath(param.category, param.locale));
}
Expand All @@ -184,6 +172,14 @@ export const getStaticProps: GetStaticProps = async ({ params, locale }) => {
getZendeskUrl(),
ZENDESK_AUTH_HEADER
);

const sectionDynamicContent = await getTranslationsFromDynamicContent(
getZendeskLocaleId(currentLocale),
COMMON_DYNAMIC_CONTENT_PLACEHOLDERS.concat(SECTION_PLACEHOLDERS),
getZendeskUrl(),
ZENDESK_AUTH_HEADER
);

const strings: CategoryStrings = populateCategoryStrings(dynamicContent);

const categories = (
Expand All @@ -207,12 +203,6 @@ export const getStaticProps: GetStaticProps = async ({ params, locale }) => {
ZENDESK_AUTH_HEADER
);

const menuOverlayItems = getMenuItems(
populateMenuOverlayStrings(dynamicContent),
categories,
!!aboutUsArticle
);

const sections = await getSectionsForCategory(
currentLocale,
Number(params?.category),
Expand All @@ -227,9 +217,21 @@ export const getStaticProps: GetStaticProps = async ({ params, locale }) => {
};
});

const menuCategories = await getCategoriesWithSections(
currentLocale,
getZendeskUrl(),
(c) => !MENU_CATEGORIES_TO_HIDE.includes(c.id)
);

const menuOverlayItems = getMenuItems(
populateMenuOverlayStrings(sectionDynamicContent),
menuCategories,
!!aboutUsArticle
);

const footerLinks = getFooterItems(
populateMenuOverlayStrings(dynamicContent),
categories
populateMenuOverlayStrings(sectionDynamicContent),
menuCategories
);

return {
Expand Down
15 changes: 13 additions & 2 deletions pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import {
DIRECTUS_COUNTRY_ID,
DIRECTUS_INSTANCE,
GOOGLE_ANALYTICS_IDS,
MENU_CATEGORIES_TO_HIDE,
REVALIDATION_TIMEOUT_SECONDS,
SEARCH_BAR_INDEX,
SECTION_ICON_NAMES,
Expand Down Expand Up @@ -143,6 +144,7 @@ export const getStaticProps: GetStaticProps = async ({ locale }) => {
);

let categories: ZendeskCategory[] | CategoryWithSections[];
let menuCategories: ZendeskCategory[] | CategoryWithSections[];
if (USE_CAT_SEC_ART_CONTENT_STRUCTURE) {
categories = await getCategoriesWithSections(
currentLocale,
Expand All @@ -154,12 +156,21 @@ export const getStaticProps: GetStaticProps = async ({ locale }) => {
(s) => (s.icon = SECTION_ICON_NAMES[s.id] || 'help_outline')
);
});
menuCategories = await getCategoriesWithSections(
currentLocale,
getZendeskUrl(),
(c) => !MENU_CATEGORIES_TO_HIDE.includes(c.id)
);
} else {
categories = await getCategories(currentLocale, getZendeskUrl());
categories = categories.filter((c) => !CATEGORIES_TO_HIDE.includes(c.id));
categories.forEach(
(c) => (c.icon = CATEGORY_ICON_NAMES[c.id] || 'help_outline')
);
menuCategories = await getCategories(currentLocale, getZendeskUrl());
menuCategories = menuCategories.filter(
(c) => !MENU_CATEGORIES_TO_HIDE.includes(c.id)
);
}

const aboutUsArticle = await getArticle(
Expand All @@ -173,7 +184,7 @@ export const getStaticProps: GetStaticProps = async ({ locale }) => {

const menuOverlayItems = getMenuItems(
populateMenuOverlayStrings(dynamicContent),
categories,
menuCategories,
!!aboutUsArticle
);

Expand Down Expand Up @@ -287,7 +298,7 @@ export const getStaticProps: GetStaticProps = async ({ locale }) => {

const footerLinks = getFooterItems(
populateMenuOverlayStrings(dynamicContent),
categories
menuCategories
);

return {
Expand Down
15 changes: 13 additions & 2 deletions pages/search-results-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
CATEGORIES_TO_HIDE,
CATEGORY_ICON_NAMES,
GOOGLE_ANALYTICS_IDS,
MENU_CATEGORIES_TO_HIDE,
REVALIDATION_TIMEOUT_SECONDS,
SEARCH_BAR_INDEX,
SEARCH_RESULTS_PAGE_INDEX,
Expand Down Expand Up @@ -106,6 +107,7 @@ export const getStaticProps: GetStaticProps = async ({ locale }) => {
);

let categories: ZendeskCategory[] | CategoryWithSections[];
let menuCategories: ZendeskCategory[] | CategoryWithSections[];
if (USE_CAT_SEC_ART_CONTENT_STRUCTURE) {
categories = await getCategoriesWithSections(
currentLocale,
Expand All @@ -117,12 +119,21 @@ export const getStaticProps: GetStaticProps = async ({ locale }) => {
(s) => (s.icon = SECTION_ICON_NAMES[s.id] || 'help_outline')
);
});
menuCategories = await getCategoriesWithSections(
currentLocale,
getZendeskUrl(),
(c) => !MENU_CATEGORIES_TO_HIDE.includes(c.id)
);
} else {
categories = await getCategories(currentLocale, getZendeskUrl());
categories = categories.filter((c) => !CATEGORIES_TO_HIDE.includes(c.id));
categories.forEach(
(c) => (c.icon = CATEGORY_ICON_NAMES[c.id] || 'help_outline')
);
menuCategories = await getCategories(currentLocale, getZendeskUrl());
menuCategories = menuCategories.filter(
(c) => !MENU_CATEGORIES_TO_HIDE.includes(c.id)
);
}

const aboutUsArticle = await getArticle(
Expand All @@ -135,14 +146,14 @@ export const getStaticProps: GetStaticProps = async ({ locale }) => {

const menuOverlayItems = getMenuItems(
populateMenuOverlayStrings(dynamicContent),
categories,
menuCategories,
!!aboutUsArticle
);

const strings = populateSearchResultsPageStrings(dynamicContent);
const footerLinks = getFooterItems(
populateMenuOverlayStrings(dynamicContent),
categories
menuCategories
);
return {
props: {
Expand Down
11 changes: 9 additions & 2 deletions pages/sections/[section].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
ABOUT_US_ARTICLE_ID,
CATEGORIES_TO_HIDE,
GOOGLE_ANALYTICS_IDS,
MENU_CATEGORIES_TO_HIDE,
REVALIDATION_TIMEOUT_SECONDS,
SEARCH_BAR_INDEX,
SECTION_ICON_NAMES,
Expand Down Expand Up @@ -228,6 +229,12 @@ export const getStaticProps: GetStaticProps = async ({ params, locale }) => {
);
});

const menuCategories = await getCategoriesWithSections(
currentLocale,
getZendeskUrl(),
(c) => !MENU_CATEGORIES_TO_HIDE.includes(c.id)
);

const sectionItems = categories
.flatMap((c) => c.sections)
.map((section) => {
Expand All @@ -249,13 +256,13 @@ export const getStaticProps: GetStaticProps = async ({ params, locale }) => {

const menuOverlayItems = getMenuItems(
populateMenuOverlayStrings(dynamicContent),
categories,
menuCategories,
!!aboutUsArticle
);

const footerLinks = getFooterItems(
populateMenuOverlayStrings(dynamicContent),
categories
menuCategories
);

return {
Expand Down

0 comments on commit 94094dd

Please sign in to comment.