Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/adjust navigation bar and font size in layout #239

Merged
merged 6 commits into from
Sep 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions homepage/public/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,6 @@ body {
.section-main p {
font-size: 16px;
}
.section-main .flex-col p {
font-size: 14px;
}
.section:nth-child(even) .section-main {
background: #fafafe;
}
Expand Down
48 changes: 48 additions & 0 deletions homepage/src/lib/getNavigationList.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import fs from 'fs';
import { join } from 'path';
import matter from 'gray-matter';

const pagesDirectory = join(process.cwd(), '_pages');

function getPagesDirectoryPath(lang) {
return join(pagesDirectory, lang);
}

export async function getPagesList(lang) {
const pagesDirectory = getPagesDirectoryPath(lang);
const filesInPages = fs.readdirSync(pagesDirectory);

const pagesList = filesInPages.map(async (filename) => {
const fullPath = join(pagesDirectory, filename);
const file = fs.readFileSync(fullPath, 'utf8');
const matterFile = matter(file);
const { data, content } = matterFile;

return {
path: data.unique_slug,
name: data.name,
};
});

return Promise.all(pagesList);
}

export async function getNavigationList(lang) {
const pagesList = await getPagesList(lang);
const cardsPage = {
en: 'Cards',
'zh-tw': '卡片頁',
};

// * 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[lang] });

return navigationList;
}
18 changes: 9 additions & 9 deletions homepage/src/pages/activities.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import Head from 'next/head';
* @type {import('next').GetStaticProps}
*/
export const getStaticProps = async ({ locale }) => {
const backToTop = {
en: 'Back to top',
'zh-tw': '回到頁首',
};
// const backToTop = {
// en: 'Back to top',
// 'zh-tw': '回到頁首',
// };

const aboutOpenSourceNav = {
en: 'About Open Source',
Expand Down Expand Up @@ -44,11 +44,11 @@ export const getStaticProps = async ({ locale }) => {
};

const navigationList = [
{ link: `#page-top`, text: backToTop[locale] },
{ link: `#about-open-source`, text: aboutOpenSourceNav[locale] },
{ link: `#our-beliefs`, text: ourBeliefsNav[locale] },
{ link: `#details`, text: detailsNav[locale] },
{ link: `#instructors`, text: instructorsNav[locale] },
// { link: `#page-top`, text: backToTop[locale] },
// { link: `#about-open-source`, text: aboutOpenSourceNav[locale] },
// { link: `#our-beliefs`, text: ourBeliefsNav[locale] },
// { link: `#details`, text: detailsNav[locale] },
// { link: `#instructors`, text: instructorsNav[locale] },
{ link: `/cards`, text: cardsPage[locale] },
{ link: `/`, text: homepage[locale] },
];
Expand Down
27 changes: 3 additions & 24 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 { getNavigationList } from '../lib/getNavigationList';

/**
*
Expand Down Expand Up @@ -31,16 +32,13 @@ export const getStaticProps = async ({ locale }) => {
};
});

const navigationList = await getNavigationList(locale);

const title = {
en: 'Card Introduction',
'zh-tw': '卡片介紹',
};

const backToTop = {
en: 'Back to top',
'zh-tw': '回到頁首',
};

const projectCardTitle = {
en: 'Project Card',
'zh-tw': '專案卡',
Expand All @@ -56,16 +54,6 @@ export const getStaticProps = async ({ locale }) => {
'zh-tw': '事件卡',
};

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

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

const projectCardSubtitle = {
'open gov': {
en: 'Open Government',
Expand All @@ -81,15 +69,6 @@ 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 headInfo = {
title: {
en: `OpenStarTerVillage - Card Introduction`,
Expand Down
34 changes: 2 additions & 32 deletions homepage/src/pages/index.jsx
Original file line number Diff line number Diff line change
@@ -1,45 +1,15 @@
import Head from 'next/head';
import Script from 'next/script';
import { fetchPage } from '../lib/fetchPage';
import { getNavigationList } from '../lib/getNavigationList';
import contentMapper from '../layouts/contentMapper';

/**
*
* @type {import('next').GetStaticProps}
*/
export const getStaticProps = async ({ locale }) => {
// const backToTop = {
// en: 'Back to top',
// 'zh-tw': '回到頁首',
// };

// const projectIntroNav = {
// en: 'Project Intro',
// 'zh-tw': '專案介紹',
// };

// const gameIntroNav = {
// en: 'Game Intro',
// 'zh-tw': '遊戲介紹',
// };

const cardsPage = {
en: 'Cards',
'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] },
];
const navigationList = await getNavigationList(locale);

const headInfo = {
title: {
Expand Down
34 changes: 2 additions & 32 deletions homepage/src/pages/resource.jsx
Original file line number Diff line number Diff line change
@@ -1,44 +1,14 @@
import contentMapper from '../layouts/contentMapper';
import { fetchPage } from '../lib/fetchPage';
import { getNavigationList } from '../lib/getNavigationList';

/**
*
* @type {import('next').GetStaticProps}
*/
export const getStaticProps = async ({ locale }) => {
const page = fetchPage(locale, 'resource');

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] },
];

/*
// content navigation
const navigationList = page.data['layout_list']?.map((layout) => {
return {
text: layout?.title,
link: `#${layout?.title}`,
};
});
*/
const navigationList = await getNavigationList(locale);

return {
props: {
Expand Down