mirror of
https://github.com/XRPLF/xrpl-dev-portal.git
synced 2025-11-04 20:05:50 +00:00
adds new workflow logic and sync pages with contentful logix
This commit is contained in:
19
.github/workflows/update-contentful-data.yml
vendored
19
.github/workflows/update-contentful-data.yml
vendored
@@ -2,7 +2,7 @@ name: Update Contentful Data
|
||||
|
||||
on:
|
||||
repository_dispatch:
|
||||
types: [contentful_update] # This should match the event type sent by the webhook
|
||||
types: [contentful_update]
|
||||
|
||||
jobs:
|
||||
update-data:
|
||||
@@ -30,14 +30,29 @@ jobs:
|
||||
CONTENTFUL_ACCESS_TOKEN: ${{ secrets.CONTENTFUL_ACCESS_TOKEN }}
|
||||
run: node scripts/fetchContentfulData.cjs
|
||||
|
||||
- name: Check for changes
|
||||
id: check_changes
|
||||
run: |
|
||||
if [ -z "$(git status --porcelain)" ]; then
|
||||
echo "no_changes=true" >> $GITHUB_OUTPUT
|
||||
else
|
||||
echo "no_changes=false" >> $GITHUB_OUTPUT
|
||||
fi
|
||||
|
||||
- name: No changes found
|
||||
if: steps.check_changes.outputs.no_changes == 'true'
|
||||
run: echo "No changes found. Skipping commit and pull request steps."
|
||||
|
||||
- name: Commit and Push Changes
|
||||
if: steps.check_changes.outputs.no_changes == 'false'
|
||||
uses: stefanzweifel/git-auto-commit-action@v4
|
||||
with:
|
||||
commit_message: 'Update data from Contentful'
|
||||
branch: ${{ env.BRANCH_NAME }}
|
||||
create_branch: true
|
||||
|
||||
|
||||
- name: Create Pull Request
|
||||
if: steps.check_changes.outputs.no_changes == 'false'
|
||||
uses: actions/github-script@v6
|
||||
with:
|
||||
github-token: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import { useState, useMemo } from "react";
|
||||
import { useThemeHooks } from "@redocly/theme/core/hooks";
|
||||
import events from "../static/JSON/events.json";
|
||||
import base_events from "../static/JSON/events.json";
|
||||
import contentful_events from "../static/JSON/contentful-events.json";
|
||||
|
||||
const events = base_events.concat(contentful_events);
|
||||
const moment = require("moment");
|
||||
export const frontmatter = {
|
||||
seo: {
|
||||
@@ -268,7 +270,7 @@ export default function Events() {
|
||||
<div
|
||||
className="event-card-header"
|
||||
style={{
|
||||
backgroundImage: `url(/img/events/${event.image})`,
|
||||
backgroundImage: `url(${event.image.startsWith('https://') ? event.image : `/img/events/${event.image}`})`,
|
||||
backgroundRepeat: "no-repeat",
|
||||
}}
|
||||
>
|
||||
@@ -402,7 +404,7 @@ export default function Events() {
|
||||
<div
|
||||
className="event-card-header"
|
||||
style={{
|
||||
backgroundImage: `url(/img/events/${event.image})`,
|
||||
backgroundImage: `url(${event.image.startsWith('https://') ? event.image : `/img/events/${event.image}`})`,
|
||||
backgroundRepeat: "no-repeat",
|
||||
}}
|
||||
>
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
import React, { useState, useEffect } from "react";
|
||||
import moment from "moment";
|
||||
import { useThemeHooks } from "@redocly/theme/core/hooks";
|
||||
import allEvents from "../static/JSON/events.json";
|
||||
import base_events from "../static/JSON/events.json";
|
||||
import contentful_events from "../static/JSON/contentful-events.json";
|
||||
import { Link } from "@redocly/theme/components/Link/Link";
|
||||
|
||||
const allEvents = base_events.concat(contentful_events)
|
||||
const findNearestUpcomingEvent = (events) => {
|
||||
let nearestEvent = null;
|
||||
let nearestDateDiff = Infinity;
|
||||
@@ -138,14 +139,14 @@ const XrplEventsAndCarouselSection = ({ events }) => {
|
||||
<img
|
||||
id="left-image"
|
||||
alt="Left Event Image"
|
||||
src={prevEvent ? `/img/events/${prevEvent.image}` : ""}
|
||||
src={prevEvent ? (prevEvent.image.startsWith('https://') ? prevEvent.image : `/img/events/${prevEvent.image}`) : ""}
|
||||
style={{ visibility: prevEvent ? "visible" : "hidden" }}
|
||||
/>
|
||||
<div className="center-image-wrapper">
|
||||
<img
|
||||
id="center-image"
|
||||
alt="Featured Event Image"
|
||||
src={currentEvent ? `/img/events/${currentEvent.image}` : ""}
|
||||
src={currentEvent ? (currentEvent.image.startsWith('https://') ? currentEvent.image : `/img/events/${currentEvent.image}`) : ""}
|
||||
onClick={() =>
|
||||
currentEvent && window.open(currentEvent.link, "_blank")
|
||||
}
|
||||
@@ -167,7 +168,7 @@ const XrplEventsAndCarouselSection = ({ events }) => {
|
||||
<img
|
||||
id="right-image"
|
||||
alt="Right Event Image"
|
||||
src={nextEvent ? `/img/events/${nextEvent.image}` : ""}
|
||||
src={nextEvent ? (nextEvent.image.startsWith('https://') ? nextEvent.image : `/img/events/${nextEvent.image}`) : ""}
|
||||
style={{ visibility: nextEvent ? "visible" : "hidden" }}
|
||||
/>
|
||||
</div>
|
||||
|
||||
@@ -1,8 +1,26 @@
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const moment = require('moment');
|
||||
const contentful = require('contentful');
|
||||
require('dotenv').config();
|
||||
|
||||
const eventTypeLookup = {
|
||||
hackathon: 'hackathon',
|
||||
meetup: 'meetup',
|
||||
ama: 'ama',
|
||||
conference: 'conference',
|
||||
'community-call': 'cc',
|
||||
'xrpl-zone': 'zone',
|
||||
'info-session': 'info',
|
||||
}
|
||||
const imageFallbackLookup = {
|
||||
hackathon: 'Hackathons.png',
|
||||
meetup: '', // should not be blank from contentful
|
||||
ama: 'AMAs.png',
|
||||
conference: 'Conference.png',
|
||||
'community-call': 'CommunityCalls.png',
|
||||
'xrpl-zone': 'XRPLZone.png',
|
||||
'info-session': 'InfoSessions.png',
|
||||
}
|
||||
const space = process.env.CONTENTFUL_SPACE_ID;
|
||||
const accessToken = process.env.CONTENTFUL_ACCESS_TOKEN;
|
||||
|
||||
@@ -14,14 +32,42 @@ const client = contentful.createClient({
|
||||
async function fetchData() {
|
||||
try {
|
||||
const entries = await client.getEntries();
|
||||
// Transform the entries into the required JSON format
|
||||
const data = entries.items.map((item) => {
|
||||
return {
|
||||
id: item.sys.id,
|
||||
...item.fields,
|
||||
image: item?.fields.image?.fields?.file?.url || '',
|
||||
};
|
||||
});
|
||||
// Edit: Format the dates to match events.json format
|
||||
const startDate = moment(item.fields.startDate);
|
||||
const endDate = moment(item.fields.endDate);
|
||||
const startDateFormatted = startDate.format('MMMM D, YYYY');
|
||||
const endDateFormatted = endDate.format('MMMM D, YYYY');
|
||||
const sameDay = startDate.isSame(endDate, 'day');
|
||||
const sameMonth = startDate.isSame(endDate, 'month');
|
||||
const sameYear = startDate.isSame(endDate, 'year');
|
||||
let dateString;
|
||||
|
||||
if (sameDay) {
|
||||
dateString = startDateFormatted;
|
||||
} else if (sameYear && sameMonth) {
|
||||
dateString = `${startDate.format('MMMM D')} - ${endDate.format('D, YYYY')}`;
|
||||
} else if (sameYear) {
|
||||
dateString = `${startDate.format('MMMM D')} - ${endDateFormatted}`;
|
||||
} else {
|
||||
dateString = `${startDateFormatted} - ${endDateFormatted}`;
|
||||
}
|
||||
|
||||
const eventType = (item.fields.category[0]).toLocaleLowerCase();
|
||||
return {
|
||||
name: item.fields.name,
|
||||
description: item.fields.description,
|
||||
type: eventTypeLookup[eventType],
|
||||
link: item.fields.link,
|
||||
location: item.fields.location,
|
||||
date: dateString,
|
||||
image: item?.fields?.image?.fields?.file?.url ? `https:${item.fields.image.fields.file.url}` : imageFallbackLookup[eventType],
|
||||
end_date: endDateFormatted,
|
||||
start_date: startDateFormatted,
|
||||
community: item.fields.community,
|
||||
contentful: true, // flag to show its coming from contentful
|
||||
};
|
||||
});
|
||||
// Write data to JSON file
|
||||
const filePath = path.join(__dirname, '../static/JSON/contentful-events.json');
|
||||
fs.writeFileSync(filePath, JSON.stringify(data, null, 2));
|
||||
|
||||
@@ -1,3 +1,15 @@
|
||||
[
|
||||
|
||||
]
|
||||
{
|
||||
"name": "NAMEEE Aria Newest Title",
|
||||
"description": "alfknaskljnfaclonfasckln acfslkasaskdfnasljknfkjlanfkjoanfskanafskjnfakjnafknfsaoknfsoiuasnfoianoifankifsdanaisunfsaoiunfsadoiunfdascdfansiacdsncianacsincsaincasiknason",
|
||||
"type": "ama",
|
||||
"link": "https://google.com",
|
||||
"location": "my house. CA",
|
||||
"date": "December 13, 2024 - January 9, 2025",
|
||||
"image": "https://images.ctfassets.net/mixeai34z104/27BDYjXhNHFEc2g2LpU7pE/43b14752034af1e06e256a8fabfc5c91/SouthKoreaMeetup.png",
|
||||
"end_date": "January 9, 2025",
|
||||
"start_date": "December 13, 2024",
|
||||
"community": true,
|
||||
"contentful": true
|
||||
}
|
||||
]
|
||||
@@ -1021,7 +1021,7 @@
|
||||
"link": "https://xrpl.at/Aquarium-XRPL-Residency-DemoDay4",
|
||||
"location": "New York, New York",
|
||||
"date": "November 19, 2024",
|
||||
"image": "new-york.jpeg",
|
||||
"image": "event-meetup-new-york@2x.jpg",
|
||||
"end_date": "November 19, 2024",
|
||||
"start_date": "November 19, 2024",
|
||||
"community": true
|
||||
|
||||
Reference in New Issue
Block a user