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

Feat/add logo data in cms footer collection #309

Merged
merged 12 commits into from
Nov 4, 2023
Merged
16 changes: 15 additions & 1 deletion homepage/_footer/en/footer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,20 @@
"display_text": "Play Online!",
"url": "/resource/#play-online"
}
],
"logos": [
{
"alt_text": "open culture foundation",
"image_url": "/images/uploads/logo__ocf.svg",
"title": "Initiator",
"link_url": "https://ocf.tw/"
},
{
"alt_text": "Friedrich Naumann Foundation for Freedom",
"image_url": "/images/uploads/logo__fnf.png",
"title": "Sponsor",
"link_url": "https://www.freiheit.org/"
}
]
}
}
}
16 changes: 15 additions & 1 deletion homepage/_footer/zh-tw/footer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,20 @@
"display_text": "來玩線上桌遊!",
"url": "/resource/#線上桌遊一起玩"
}
],
"logos": [
{
"text": "open culture foundation",
"image_url": "/images/uploads/logo__ocf.svg",
"title": "Initiator",
"link_url": "https://ocf.tw/"
},
{
"text": "Friedrich Naumann Foundation for Freedom",
"image_url": "/images/uploads/logo__fnf.png",
"title": "Sponsor",
"link_url": "https://www.freiheit.org/"
}
]
}
}
}
8 changes: 4 additions & 4 deletions homepage/public/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -916,7 +916,7 @@ code {
margin-left: 1rem;
}
.logo-margin {
margin: 0 15px;
margin: 0 1rem;
}
.avatar {
margin: 0.5rem auto;
Expand Down Expand Up @@ -985,9 +985,6 @@ code {
.logos {
flex-wrap: wrap;
}
.logo-margin {
margin: 10px auto;
}
}
@media only screen and (max-width: 568px) {
.photos-page-list .item {
Expand Down Expand Up @@ -1021,6 +1018,9 @@ code {
.blogs-list .item .inner .details .title {
font-size: 20px;
}
.logo-margin {
margin: 0.25rem auto;
}
}
@media only screen and (max-width: 480px) {
/* .image-and-text-main .left img{height:400px} */
Expand Down
Binary file added homepage/public/images/uploads/logo__fnf.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
165 changes: 165 additions & 0 deletions homepage/public/images/uploads/logo__ocf.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
32 changes: 31 additions & 1 deletion homepage/src/CMS/decap-cms.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ module.exports = {
label: 'Links',
label_singular: 'Link',
widget: 'list',
summary: '{{fields.type} - {{fields.url}}',
summary: '{{fields.type}} - {{fields.url}}',
fields: [
{
label: 'Type',
Expand Down Expand Up @@ -429,6 +429,36 @@ module.exports = {
},
],
},
{
label: 'Logos',
name: 'logos',
label_singular: 'Logo',
widget: 'list',
i18n: true,
summary: '{{fields.title}} | {{fields.alt_text}}',
fields: [
{
label: 'Title',
name: 'title',
widget: 'string',
},
{
label: 'Alt Text',
name: 'alt_text',
widget: 'string',
},
{
label: 'Image',
name: 'image_url',
widget: 'image',
},
{
label: 'Link Url',
name: 'link_url',
widget: 'string',
},
],
},
],
},
],
Expand Down
29 changes: 16 additions & 13 deletions homepage/src/components/logo.jsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
import Image from 'next/image';
import Link from 'next/link';

const Logo = ({ text, src, dimension }) => (
<div className="flex flex-row flex-align-center logo-margin">
<span className="logo-title">{text}</span>
<Image
className="logo-image"
src={src}
alt={`${text}-logo`}
height={dimension.height}
width={dimension.width}
style={{
objectFit: 'cover',
}}
/>
const Logo = ({ title, altText, src, dimension, link }) => (
<div className="d-flex align-items-center logo-margin">
<span className="logo-title">{title}</span>
<Link href={link} target="_blank">
<Image
className="logo-image"
src={src}
alt={altText}
height={dimension.height}
width={dimension.width}
style={{
objectFit: 'cover',
}}
/>
</Link>
</div>
);

Expand Down
14 changes: 7 additions & 7 deletions homepage/src/layouts/contentMapper.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@ import { componentTypes } from '../lib/componentMapper';
const contentMapper = (component) => {
switch (component.type) {
case componentTypes.Banner:
return <Banner key={component.id} {...component.props} />;
return <Banner key={component.props.id} {...component.props} />;
case componentTypes.Headline:
return <Headline key={component.id} {...component.props} />;
return <Headline key={component.props.id} {...component.props} />;
case componentTypes.ImageAndText:
return <ImageAndText key={component.id} {...component.props} />;
return <ImageAndText key={component.props.id} {...component.props} />;
case componentTypes.OneColumn:
return <Section key={component.id} {...component.props} />;
return <Section key={component.props.id} {...component.props} />;
case componentTypes.TwoColumns:
return <TwoColumns key={component.id} {...component.props} />;
return <TwoColumns key={component.props.id} {...component.props} />;
case componentTypes.ThreeColumns:
return <ThreeColumns key={component.id} {...component.props} />;
return <ThreeColumns key={component.props.id} {...component.props} />;
case componentTypes.Cards:
return <Cards key={component.id} {...component.props} />;
return <Cards key={component.props.id} {...component.props} />;
default:
return null;
}
Expand Down
35 changes: 12 additions & 23 deletions homepage/src/layouts/footer/footer.jsx
Original file line number Diff line number Diff line change
@@ -1,36 +1,25 @@
import { useRouter } from 'next/router';
import SocialMedia from '../../components/socialMedia';
import Logo from '../../components/logo';
import footerZh from '../../../_footer/zh-tw/footer.json';
import footerEn from '../../../_footer/en/footer.json';
import FooterLinks from './footerLinks';

const Footer = ({ siteData, footer }) => {
const router = useRouter();
const locale = router.locale;
const footerData = locale === 'en' ? footerEn : footerZh;
const footerLinks = footer?.links ?? footerData?.footer?.links ?? [];
const links = footerLinks.map((link) => ({
displayText: link.display_text,
url: link.url,
}));
const Footer = ({ siteData, links = [], logos = [] }) => {
return (
<div className="site-footer" id="footer">
<div className="container footer-main">
<FooterLinks links={links} />
<span>{siteData.title}</span>
<SocialMedia />
<div className="d-flex flex-row flex-justify-center logos margin-2-percent">
<Logo
text="Initiator"
src="/images/campaignpage/logo__OCF.svg"
dimension={{ width: 170, height: 34 }}
/>
<Logo
text="Sponsor"
src="/images/campaignpage/logo__FNF.png"
dimension={{ width: 163, height: 45 }}
/>
<div className="d-flex justify-content-center logos margin-2-percent">
{logos.map((logo) => (
<Logo
key={logo.text}
title={logo.title}
altText={logo.altText}
src={logo.imageUrl}
dimension={{ width: 163, height: 45 }}
link={logo.linkUrl}
/>
))}
</div>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion homepage/src/layouts/footer/footerLinks.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Link from 'next/link';

const FooterLinks = ({ links }) => (
<div className="flex flex-row gap">
<div className="d-flex gap">
{links.map((link) => (
<Link
href={link.url}
Expand Down
4 changes: 2 additions & 2 deletions homepage/src/layouts/header/header.jsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import Navigator from './navigator';

const Header = ({ nav = [], siteData }) => (
const Header = ({ siteData, navigation = [] }) => (
<header className="site-header fixed-top">
<div className="container">
<Navigator logo={siteData.logo} navigationItems={nav} />
<Navigator logo={siteData.logo} navigationItems={navigation} />
</div>
</header>
);
Expand Down
6 changes: 3 additions & 3 deletions homepage/src/layouts/siteLayout/siteLayout.jsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import Footer from '../footer/footer';
import Header from '../header/header';

const SiteLayout = ({ children, nav, siteData, pageProps }) => (
const SiteLayout = ({ children, siteData, pageProps, header, footer }) => (
<>
<Header nav={nav} siteData={siteData} />
<Header siteData={siteData} {...header} />
<main>{children}</main>
<Footer siteData={siteData} />
<Footer siteData={siteData} {...footer} />
</>
);

Expand Down
25 changes: 25 additions & 0 deletions homepage/src/lib/fetchFooter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import fs from 'fs';
import { join } from 'path';

const FOOTER_FOLDER = '_footer';

export function fetchFooter(lang) {
const filePath = join(process.cwd(), FOOTER_FOLDER, lang, 'footer.json');

const file = fs.readFileSync(filePath, 'utf8');

const rawFooter = JSON.parse(file).footer;
const footer = {
links: rawFooter.links.map((link) => ({
displayText: link.display_text,
url: link.url,
})),
logos: rawFooter.logos.map((logo) => ({
title: logo.title,
imageUrl: logo.image_url,
altText: logo.alt_text,
linkUrl: logo.link_url,
})),
};
return footer;
}
16 changes: 16 additions & 0 deletions homepage/src/lib/getLayout.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { getNavigationList } from './getNavigationList';
import { fetchFooter } from './fetchFooter';

export const getLayout = async (locale) => {
const navigation = await getNavigationList(locale);
const header = {
navigation,
};
const footer = fetchFooter(locale);
const layout = {
header,
footer,
};

return layout;
};
2 changes: 1 addition & 1 deletion homepage/src/lib/getNavigationList.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export async function getNavigationList(lang) {
.map((page) => {
page.path = page.path.replace('index', '');
return { link: `/${page.path}`, text: page.name };
})
});

return navigationList;
}
22 changes: 22 additions & 0 deletions homepage/src/lib/getPage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { componentMapper } from './componentMapper';
import { fetchCards } from './fetchCards';
import { fetchPage } from './fetchPage';
import { processCard } from './processCard';

export const getPage = async (pageName, locale) => {
const rawCards = fetchCards(locale);
const cardTasks = rawCards.map(async (card) => {
return processCard(card, rawCards);
});
const cards = await Promise.all(cardTasks);

const page = fetchPage(locale, pageName);

const contentList = page.data['layout_list']?.map((layout) =>
componentMapper(layout, cards),
);

return {
contentList,
};
};
15 changes: 6 additions & 9 deletions homepage/src/pages/404.jsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
import Head from 'next/head';
import { getLayout } from '../lib/getLayout';

/**
*
* @type {import('next').GetStaticProps}
*/
export const getStaticProps = async ({ locale }) => {
const homepage = {
en: 'Home',
'zh-tw': '首頁',
};

const navigationList = [{ link: `/`, text: homepage[locale] }];

const headInfo = {
title: {
en: `OpenStarTerVillage - Page Not Found`,
Expand All @@ -28,13 +22,16 @@ export const getStaticProps = async ({ locale }) => {
`,
};

const layout = await getLayout(locale);

return {
props: {
navigationList,
headInfo: {
title: headInfo.title[locale],
description: '',
},
desc: desc[locale],
layout,
},
};
};
Expand All @@ -43,7 +40,7 @@ const NotFoundPage = ({ headInfo, desc }) => (
<>
<Head>
<title>{headInfo.title}</title>
<meta name="description" content="" />
<meta name="description" content={headInfo.description} />
</Head>
<div className="site-container not-found-page">
<div className="container text-center">
Expand Down
2 changes: 1 addition & 1 deletion homepage/src/pages/_app.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const siteDataDictionary = {

const getDefaultLayout = (page, pageProps, siteData) => {
return (
<SiteLayout nav={pageProps.navigationList} siteData={siteData} pageProps={pageProps}>
<SiteLayout siteData={siteData} pageProps={pageProps} {...pageProps.layout}>
{page}
</SiteLayout>
);
Expand Down
Loading
Loading