Skip to content

Commit

Permalink
fix: review comment - update dynamic page navigation list
Browse files Browse the repository at this point in the history
1. Add filter to check if the path and name in each page are empty
2. Add a hard-coded link to cards page
3. Remove the link to activities page
4. Replace page navigation list with dynamic page navigation list
  • Loading branch information
ljc1991 committed Sep 22, 2023
1 parent eba0435 commit 94f4b91
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 49 deletions.
31 changes: 15 additions & 16 deletions homepage/src/pages/cards.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import Headline from '../components/headline';
import CardsGrid from '../components/cardsGrid';

import { fetchCards } from '../lib/fetchCards';
import { getPagesList } from '../lib/getPagesList';

/**
*
Expand Down Expand Up @@ -56,14 +57,9 @@ export const getStaticProps = async ({ locale }) => {
'zh-tw': '事件卡',
};

const activitiesPage = {
en: 'Activities',
'zh-tw': '活動頁',
};

const homepage = {
en: 'Home',
'zh-tw': '首頁',
const cardsPage = {
en: 'Cards',
'zh-tw': '卡片頁',
};

const projectCardSubtitle = {
Expand All @@ -81,14 +77,17 @@ export const getStaticProps = async ({ locale }) => {
},
};

const navigationList = [
// { link: `#page-top`, text: backToTop[locale] },
// { link: `#project-cards`, text: projectCardTitle[locale] },
// { link: `#job-cards`, text: jobCardTitle[locale] },
// { link: `#event-cards`, text: eventCardTitle[locale] },
{ link: `/activities`, text: activitiesPage[locale] },
{ link: `/`, text: homepage[locale] },
];
const pagesList = await getPagesList(locale);

// * dynamic page navigation
const navigationList = pagesList
.filter((page) => page.path && page.name)
.map((page) => {
page.path = page.path.replace('index', '');
return { link: `/${page.path}`, text: page.name };
});
// add hard coded cards page
navigationList.push({ link: `/cards`, text: cardsPage[locale] });

const headInfo = {
title: {
Expand Down
23 changes: 11 additions & 12 deletions homepage/src/pages/index.jsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import Head from 'next/head';
import Script from 'next/script';
import { fetchPage } from '../lib/fetchPage';
import { getPagesList } from '../lib/getPagesList';
import contentMapper from '../layouts/contentMapper';

/**
*
* @type {import('next').GetStaticProps}
*/
export const getStaticProps = async ({ locale }) => {
const pagesList = await getPagesList(locale);
// const backToTop = {
// en: 'Back to top',
// 'zh-tw': '回到頁首',
Expand All @@ -28,18 +30,15 @@ export const getStaticProps = async ({ locale }) => {
'zh-tw': '卡片頁',
};

const activitiesPage = {
en: 'Activities',
'zh-tw': '活動頁',
};

const navigationList = [
// { link: `#page-top`, text: backToTop[locale] },
// { link: `#project-intro`, text: projectIntroNav[locale] },
// { link: `#game-intro`, text: gameIntroNav[locale] },
{ link: `/cards`, text: cardsPage[locale] },
{ link: `/activities`, text: activitiesPage[locale] },
];
// * dynamic page navigation
const navigationList = pagesList
.filter((page) => page.path && page.name)
.map((page) => {
page.path = page.path.replace('index', '');
return { link: `/${page.path}`, text: page.name };
});
// add hard coded cards page
navigationList.push({ link: `/cards`, text: cardsPage[locale] });

const headInfo = {
title: {
Expand Down
29 changes: 8 additions & 21 deletions homepage/src/pages/resource.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,33 +10,20 @@ export const getStaticProps = async ({ locale }) => {
const page = fetchPage(locale, 'resource');
const pagesList = await getPagesList(locale);

const homepage = {
en: 'Home',
'zh-tw': '首頁',
};

const cardsPage = {
en: 'Cards',
'zh-tw': '卡片頁',
};

const activitiesPage = {
en: 'Activities',
'zh-tw': '活動頁',
};

// site page navigation
const navigationList = [
{ link: `/cards`, text: cardsPage[locale] },
{ link: `/activities`, text: activitiesPage[locale] },
{ link: `/`, text: homepage[locale] },
];

// * dynamic page navigation
// const navigationList = pagesList.map((page) => {
// page.path = page.path.replace('index', '');
// return { link: `/${page.path}`, text: page.name ?? 'page' };
// });
const navigationList = pagesList
.filter((page) => page.path && page.name)
.map((page) => {
page.path = page.path.replace('index', '');
return { link: `/${page.path}`, text: page.name };
});
// add hard coded cards page
navigationList.push({ link: `/cards`, text: cardsPage[locale] });

/*
// content navigation
Expand Down

0 comments on commit 94f4b91

Please sign in to comment.