Skip to content

Commit

Permalink
Merge branch 'main' into feat/add-logo-data-in-cms-footer-collection
Browse files Browse the repository at this point in the history
  • Loading branch information
ljc1991 committed Nov 2, 2023
2 parents 1cc461d + 14937f5 commit 60d026d
Show file tree
Hide file tree
Showing 25 changed files with 169 additions and 443 deletions.
1 change: 0 additions & 1 deletion homepage/_cards/en/公務員.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,3 @@ type: job
tags:
- civil servants
---
Public Servant
1 change: 0 additions & 1 deletion homepage/_cards/en/工程師.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,3 @@ type: job
tags:
- engineer
---
Engineer
1 change: 0 additions & 1 deletion homepage/_cards/en/文字工作者.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,3 @@ type: job
tags:
- writer
---
Copywriter
1 change: 0 additions & 1 deletion homepage/_cards/en/法務人員.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,3 @@ type: job
tags:
- legal
---
Legal Personnel
1 change: 0 additions & 1 deletion homepage/_cards/en/美術設計.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,3 @@ type: job
tags:
- designer
---
AD
1 change: 0 additions & 1 deletion homepage/_cards/en/行銷公關.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,3 @@ type: job
tags:
- marketing
---
Marketing PR
1 change: 0 additions & 1 deletion homepage/_cards/en/議題工作者.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,3 @@ type: job
tags:
- advocator
---
Advocator
1 change: 0 additions & 1 deletion homepage/_cards/zh-tw/公務員.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,3 @@ type: job
tags:
- civil servants
---
公務
1 change: 0 additions & 1 deletion homepage/_cards/zh-tw/工程師.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,3 @@ type: job
tags:
- engineer
---
工程
1 change: 0 additions & 1 deletion homepage/_cards/zh-tw/文字工作者.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,3 @@ type: job
tags:
- writer
---
文字
1 change: 0 additions & 1 deletion homepage/_cards/zh-tw/法務人員.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,3 @@ type: job
tags:
- legal
---
法務
1 change: 0 additions & 1 deletion homepage/_cards/zh-tw/美術設計.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,3 @@ type: job
tags:
- designer
---
美術
1 change: 0 additions & 1 deletion homepage/_cards/zh-tw/行銷公關.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,3 @@ type: job
tags:
- marketing
---
行銷
1 change: 0 additions & 1 deletion homepage/_cards/zh-tw/議題工作者.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,3 @@ type: job
tags:
- advocator
---
議題
15 changes: 3 additions & 12 deletions homepage/_pages/zh-tw/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,22 +44,13 @@ layout_list:
title: 桌遊用途
columns:
- title: 教學教材
text: |-
###
無論大學、高中課程,教學簡報配合桌遊,輕鬆認識開源觀念,提升公民行動力!
text: 無論大學、高中課程,教學簡報配合桌遊,輕鬆認識開源觀念,提升公民行動力!
image: /images/uploads/pxl_20230508_052023298.jpg
- title: 社群推坑
text: |-
###
已是開源老手、社群活躍成員的你,想要不費吹灰之力吸收新血?揪團玩就對了!
text: 已是開源老手、社群活躍成員的你,想要不費吹灰之力吸收新血?揪團玩就對了!
image: /images/uploads/pxl_20230730_051310179.jpeg
- title: 破冰團康
text: |-
###
社團活動怎麼帶?利用星手村桌遊,輕鬆達到破冰與理念推廣。學弟學妹揪起來!
text: 社團活動怎麼帶?利用星手村桌遊,輕鬆達到破冰與理念推廣。學弟學妹揪起來!
image: /images/uploads/img_3763.jpeg
- type: layout_section
title: 桌遊背後的故事
Expand Down
3 changes: 0 additions & 3 deletions homepage/public/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -963,9 +963,6 @@ code {
}
}
@media only screen and (min-width: 768px) and (max-width: 991px) {
.avatar-tablet {
transform: translate(-13%);
}
}
@media only screen and (max-width: 767px) {
.container {
Expand Down
51 changes: 51 additions & 0 deletions homepage/src/CMS/DecapCms.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import dynamic from 'next/dynamic';
import PagePreview from './preview/PagePreview';
import FooterPreview from './preview/FooterPreview';
import CardPreview from './preview/CardPreview';

import config from './config.json';

const withAssetsByLocale = (Component, assetsByLocale) => {
const WrappedComponent = (props) => (
<Component {...props} assetsByLocale={assetsByLocale} />
);
WrappedComponent.displayName = `withAssetsByLocale(${Component.displayName})`;
return WrappedComponent;
};

const DecapCms = (assetsByLocale) =>
dynamic(
() =>
import('decap-cms-app').then((cms) => {
cms.init({ config });
cms.registerPreviewStyle(
'https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css',
);
cms.registerPreviewStyle(
'https://cdn.jsdelivr.net/npm/@fortawesome/[email protected]/css/all.min.css',
);
cms.registerPreviewStyle(
'https://fonts.googleapis.com/css?family=Montserrat:400,700',
);
cms.registerPreviewStyle(
'https://fonts.googleapis.com/css?family=Roboto+Slab:400,100,300,700',
);
cms.registerPreviewStyle('/css/style.css');

cms.registerPreviewTemplate(
'pages',
withAssetsByLocale(PagePreview, assetsByLocale),
);
cms.registerPreviewTemplate(
'footer',
withAssetsByLocale(FooterPreview, assetsByLocale),
);
cms.registerPreviewTemplate(
'cards',
withAssetsByLocale(CardPreview, assetsByLocale),
);
}),
{ ssr: false, loading: () => <p>Loading...</p> },
);

export default DecapCms;
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@
},
{ "label": "Name", "name": "name", "widget": "string", "i18n": true },
{
"label": "Page order", "name": "page_order", "widget": "number", "value_type": "int", "i18n": "duplicate"
"label": "Page order",
"name": "page_order",
"widget": "number",
"value_type": "int",
"i18n": "duplicate"
},
{
"label": "Layout & Content",
Expand Down Expand Up @@ -294,6 +298,7 @@
"label": "Content",
"name": "body",
"widget": "markdown",
"required": false,
"i18n": true
}
]
Expand Down
18 changes: 18 additions & 0 deletions homepage/src/CMS/preview/CardPreview.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import Card from '../../components/cards/card';
import { processCard } from '../../lib/processCard';

const CardPreview = ({ entry, getAsset, assetsByLocale }) => {
const locale = 'en';
const assets = assetsByLocale[locale];

const data = entry.getIn(['data']).toJS();
const content = data.body;

const card = processCard({ data, content }, assets.cards);

card.data.image = getAsset(card.data.image).toString();

return <Card card={card} />;
};

export default CardPreview;
17 changes: 17 additions & 0 deletions homepage/src/CMS/preview/FooterPreview.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import FooterLinks from '../../layouts/footer/footerLinks';

const FooterPreview = ({ entry }) => {
const footer = entry.getIn(['data', 'footer']);
const links = footer
?.get('links')
.map((link) => {
return {
displayText: link.get('display_text')?.toString(),
url: link.get('url')?.toString(),
};
})
.toArray();
return <FooterLinks links={links} />;
};

export default FooterPreview;
16 changes: 16 additions & 0 deletions homepage/src/CMS/preview/PagePreview.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { componentMapper } from '../../lib/componentMapper';
import contentMapper from '../../layouts/contentMapper';

const PagePreview = ({ entry, assetsByLocale }) => {
const locale = 'en';
const assets = assetsByLocale[locale];

const layoutList = entry.getIn(['data', 'layout_list']);
const sections = layoutList?.map((layout) => {
const component = componentMapper(layout.toJS(), assets.cards);
return contentMapper(component);
});
return <div>{sections}</div>;
};

export default PagePreview;
2 changes: 1 addition & 1 deletion homepage/src/components/cards/defaultCard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const DefaultCard = ({ card }) => (
<h3>{card.data.title}</h3>
<div className="d-flex flex-column">
<div
className="avatar avatar-tablet"
className="avatar"
style={{ backgroundColor: card.data.color.avatar }}
>
<div className="image-container">
Expand Down
57 changes: 57 additions & 0 deletions homepage/src/pages/admin.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import Head from 'next/head';
import Script from 'next/script';

import { fetchCards } from '../lib/fetchCards';
import { processCard } from '../lib/processCard';
import DecapCms from '../CMS/DecapCms';

/**
*
* @type {import('next').GetStaticProps}
*/
export const getStaticProps = async ({ locales }) => {
const assetsTasks = locales.map(async (locale) => {
const rawCards = fetchCards(locale);
const cardTasks = rawCards.map(async (card) => {
return processCard(card, rawCards);
});
const cards = await Promise.all(cardTasks);

return {
locale,
cards,
};
});

const assets = await Promise.all(assetsTasks);
const assetsByLocale = assets.reduce((assets, asset) => {
assets[asset.locale] = asset;
return assets;
}, {});

return {
props: {
assetsByLocale,
},
};
};

const Admin = ({ assetsByLocale }) => {
const Cms = DecapCms(assetsByLocale);
return (
<>
<Head>
<title>Content Manager</title>
</Head>
<Script
id="netlify-identity-widget"
src="https://identity.netlify.com/v1/netlify-identity-widget.js"
/>
<Cms />
</>
);
};

export default Admin;

Admin.getLayout = (page) => page;
Loading

0 comments on commit 60d026d

Please sign in to comment.