forked from newwwie/newwwie.com
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into 90-add-linting-action
- Loading branch information
Showing
29 changed files
with
4,776 additions
and
7,466 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
|
@@ -24,12 +24,12 @@ jobs: | |
run: npm ci | ||
- run: npm run fetchEvents | ||
- run: npm run build | ||
- name: Commit events-data.js | ||
- name: Commit events-data.ts | ||
run: | | ||
git status | ||
git config --global user.name 'Newwwie Bot' | ||
git config --global user.email '[email protected]' | ||
git add src/js/events/events-data.js | ||
git add src/js/events/events-data.ts | ||
git add dist | ||
git commit -m "Get latest set of Meetup events" | ||
git push |
This file contains 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,2 +1,3 @@ | ||
src/js/events/events-data.js | ||
src/js/communities/communities-data.js | ||
src/js/events/events-data.ts | ||
src/js/communities/community-data.ts | ||
dist/ |
This file contains 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 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 was deleted.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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,5 @@ | ||
{#- Template format for the generated event file -#} | ||
// Auto Generated on {{ generationTime }} | ||
import { type EventItem } from "./types"; | ||
|
||
export const events: readonly EventItem[] = {{ sortedEvents | dump(2) | safe }}; |
This file contains 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,62 @@ | ||
import _ from "lodash"; | ||
import axios from "axios"; | ||
import dayjs from "dayjs"; | ||
import path from "path"; | ||
import { readFileSync, writeFileSync } from "fs"; | ||
import { renderString } from "nunjucks"; | ||
|
||
import { EventItem } from "../src/js/events/types"; | ||
import { GroupEdge, GroupResponse, MEETUP_GQL_QUERY } from "./types"; | ||
import { Meetups } from "./meetups.json"; | ||
|
||
const MEETUP_GQL_URL = "https://www.meetup.com/gql"; | ||
const END_DATE_RANGE = dayjs().add(3, "month").toISOString(); // Retrieve up to three months from the current date | ||
const EVENT_OUTPUT_FILE = path.join(__dirname, "../src/js/events/events-data.ts"); | ||
const EVENT_TEMPLATE_FILE = path.join(__dirname, "./event-data-template.njk"); | ||
|
||
const buildGraphQLQuery = (groupName: string) => ({ | ||
query: MEETUP_GQL_QUERY, | ||
variables: { | ||
groupName, | ||
endDateRange: END_DATE_RANGE, | ||
}, | ||
}); | ||
|
||
const getGroupEvents = async (groupName: string): Promise<EventItem[]> => { | ||
console.log(`Fetching events for "${groupName}"`); | ||
const query = buildGraphQLQuery(groupName); | ||
const events = (await axios.post(MEETUP_GQL_URL, JSON.stringify(query))).data as GroupResponse; | ||
|
||
// Transform the response | ||
const { unifiedEvents, ...group } = events.data.groupByUrlname || {}; | ||
|
||
console.log(`Finished fetching events for "${groupName}"`); | ||
return ( | ||
unifiedEvents?.edges?.map((edge: GroupEdge) => ({ | ||
event: edge.node, | ||
group, | ||
})) || [] | ||
); | ||
}; | ||
|
||
(async () => { | ||
try { | ||
console.log("Fetching events"); | ||
const events = await Promise.all(Meetups.map((eventName: string) => getGroupEvents(eventName))); | ||
|
||
const sortedEvents = _.sortBy(events.flat(), (event: EventItem) => event.event.dateTime); | ||
|
||
console.log("Rendering the events file"); | ||
const template = readFileSync(EVENT_TEMPLATE_FILE, "utf-8"); | ||
const rendered = renderString(template, { | ||
generationTime: dayjs().toISOString(), | ||
sortedEvents, | ||
}); | ||
|
||
writeFileSync(EVENT_OUTPUT_FILE, rendered); | ||
|
||
console.log("Fetch events complete"); | ||
} catch (err) { | ||
console.error(`Error fetching events: ${err}`); | ||
} | ||
})(); |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.