From 94f4b914965bb8cd9efb0bde968704e1db4f6e49 Mon Sep 17 00:00:00 2001 From: ljc1991 Date: Sat, 23 Sep 2023 03:56:29 +0800 Subject: [PATCH] fix: review comment - update dynamic page navigation list 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 --- homepage/src/pages/cards.jsx | 31 +++++++++++++++---------------- homepage/src/pages/index.jsx | 23 +++++++++++------------ homepage/src/pages/resource.jsx | 29 ++++++++--------------------- 3 files changed, 34 insertions(+), 49 deletions(-) diff --git a/homepage/src/pages/cards.jsx b/homepage/src/pages/cards.jsx index 001d3ebb..716f1e86 100644 --- a/homepage/src/pages/cards.jsx +++ b/homepage/src/pages/cards.jsx @@ -3,6 +3,7 @@ import Headline from '../components/headline'; import CardsGrid from '../components/cardsGrid'; import { fetchCards } from '../lib/fetchCards'; +import { getPagesList } from '../lib/getPagesList'; /** * @@ -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 = { @@ -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: { diff --git a/homepage/src/pages/index.jsx b/homepage/src/pages/index.jsx index 421b7580..27ac7866 100644 --- a/homepage/src/pages/index.jsx +++ b/homepage/src/pages/index.jsx @@ -1,6 +1,7 @@ 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'; /** @@ -8,6 +9,7 @@ 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': '回到頁首', @@ -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: { diff --git a/homepage/src/pages/resource.jsx b/homepage/src/pages/resource.jsx index a5d941de..86b53e2f 100644 --- a/homepage/src/pages/resource.jsx +++ b/homepage/src/pages/resource.jsx @@ -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