-
Notifications
You must be signed in to change notification settings - Fork 0
Migrate GoodAction Hub to standalone data repository API #4
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
Merged
Merged
Changes from 8 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
682e22c
Initial plan
Copilot 5f7dac8
feat: migrate data loading to GoodAction-data external API
Copilot 6ec1760
feat: migrate data loading to GoodAction-data external API
Copilot 1df067c
style: add .prettierrc (semi:false, singleQuote:true) and reformat al…
Copilot fb08f7d
style: move prettier config into package.json, remove .prettierrc
Copilot 5dbf22c
feat: rewrite migration from scratch, restore all non-migration files…
Copilot 4798e65
chore: restore all non-migration files to main branch state via .pret…
Copilot cb216df
feat: API-driven Barrier-Free-Bites page, shared SafeTranslation, Goo…
Copilot 93fe40b
refactor: extract SVG icons to components/icons, move CSS to page.mod…
Copilot 89cfc42
fix: use :global(:root) in CSS module for explicit global scope
Copilot b120b6a
refactor: delete data YAMLs, remove icon wrappers, replace all inline…
Copilot ae634a5
refactor: convert icon components to named FC arrow function exports
Copilot 0c192e8
[remove] outdated Static Data & Document
TechQuery File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| # Files that have not yet been migrated to the project's Prettier style. | ||
| # Remove a file's entry here when it is next meaningfully changed. | ||
| .github/scripts/count-reward.ts | ||
| .github/scripts/share-reward.ts | ||
| .github/scripts/type.ts | ||
| app/Barrier-Free-Bites/layout.tsx | ||
| app/api/ai/health/route.ts | ||
| app/deadlines/page.tsx | ||
| app/home/page.tsx | ||
| app/origin/page.tsx | ||
| app/page.tsx | ||
| components/AddToCalendar.tsx | ||
| components/Aggregation.tsx | ||
| components/CountdownTimer.tsx | ||
| components/FilterBar.tsx | ||
| components/I18nProvider.tsx | ||
| components/TimelineItem.tsx | ||
| components/ui/badge.tsx | ||
| components/ui/button.tsx | ||
| components/ui/card.tsx | ||
| components/ui/dialog.tsx | ||
| components/ui/dropdown-menu.tsx | ||
| components/ui/input.tsx | ||
| components/ui/label.tsx | ||
| components/ui/scroll-area.tsx | ||
| components/ui/switch.tsx | ||
| eslint.config.mjs | ||
| i18n/config.ts | ||
| lib/data.ts | ||
| lib/spark.ts | ||
| lib/store.ts | ||
| lib/utils.ts | ||
| next.config.ts | ||
| postcss.config.mjs |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,31 +1,79 @@ | ||
| import { NextResponse } from 'next/server' | ||
| import yaml from 'yaml' | ||
| import fs from 'fs' | ||
| import path from 'path' | ||
| import { DeadlineItem } from '@/lib/data' | ||
| import { DeadlineItem, EventData } from '@/lib/data' | ||
|
|
||
| export const dynamic = 'force-static' | ||
|
|
||
| let STATIC_DATA: DeadlineItem[] = [] | ||
| let INIT_ERROR: unknown = null | ||
| const DATA_API_URL = | ||
| 'https://goodaction-hub.github.io/GoodAction-data/activities.json' | ||
|
|
||
| try { | ||
| const conferencesPath = path.join(process.cwd(), 'data', 'conferences.yml') | ||
| const competitionsPath = path.join(process.cwd(), 'data', 'competitions.yml') | ||
| const activitiesPath = path.join(process.cwd(), 'data', 'activities.yml') | ||
| interface ExternalEventData { | ||
| id: string | ||
| link: string | ||
| start_time?: string | ||
| end_time?: string | ||
| timeline: { deadline: string; comment: string }[] | ||
| timezone: string | ||
| place: string | ||
| } | ||
|
|
||
| interface ExternalDeadlineItem { | ||
| title: string | ||
| description: string | ||
| category: 'meetup' | 'conference' | 'competition' | ||
| tags: string[] | ||
| events: ExternalEventData[] | ||
| } | ||
|
|
||
| const conferencesData = yaml.parse(fs.readFileSync(conferencesPath, 'utf8')) as DeadlineItem[] | ||
| const competitionsData = yaml.parse(fs.readFileSync(competitionsPath, 'utf8')) as DeadlineItem[] | ||
| const activitiesData = yaml.parse(fs.readFileSync(activitiesPath, 'utf8')) as DeadlineItem[] | ||
| function transformEvent(event: ExternalEventData): EventData { | ||
| const startTime = event.start_time ?? event.timeline[0]?.deadline ?? '' | ||
| const startDate = startTime ? new Date(startTime.replace(' ', 'T')) : null | ||
| const year = startDate ? startDate.getFullYear() : new Date().getFullYear() | ||
|
|
||
| const formatDateToChinese = (d: Date) => | ||
| `${d.getFullYear()}年${d.getMonth() + 1}月${d.getDate()}日` | ||
| let date = startDate ? formatDateToChinese(startDate) : '' | ||
| if (startDate && event.end_time) { | ||
| const endDate = new Date(event.end_time.replace(' ', 'T')) | ||
| if (endDate.getTime() !== startDate.getTime()) { | ||
| date = `${date}-${endDate.getMonth() + 1}月${endDate.getDate()}日` | ||
| } | ||
| } | ||
|
|
||
| STATIC_DATA = [...conferencesData, ...competitionsData, ...activitiesData] | ||
| } catch (err) { | ||
| INIT_ERROR = err | ||
| return { | ||
| year, | ||
| id: event.id, | ||
| link: event.link, | ||
| timeline: event.timeline, | ||
| timezone: event.timezone, | ||
| date, | ||
| place: event.place, | ||
| } | ||
| } | ||
|
|
||
| function transformItem(item: ExternalDeadlineItem): DeadlineItem { | ||
| return { | ||
| title: item.title, | ||
| description: item.description, | ||
| category: item.category === 'meetup' ? 'activity' : item.category, | ||
| tags: item.tags ?? [], | ||
| events: item.events.map(transformEvent), | ||
| } | ||
| } | ||
|
|
||
| export async function GET() { | ||
| if (INIT_ERROR) { | ||
| try { | ||
| const res = await fetch(DATA_API_URL, { cache: 'force-cache' }) | ||
| if (!res.ok) { | ||
| return NextResponse.json( | ||
| { error: 'Failed to fetch data from external API' }, | ||
| { status: 502 }, | ||
| ) | ||
| } | ||
| const externalData = (await res.json()) as ExternalDeadlineItem[] | ||
| const data: DeadlineItem[] = externalData.map(transformItem) | ||
| return NextResponse.json(data) | ||
| } catch (err) { | ||
| console.error('Failed to fetch data from external API:', err) | ||
| return NextResponse.json({ error: 'Failed to load data' }, { status: 500 }) | ||
| } | ||
| return NextResponse.json(STATIC_DATA) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.