Skip to content
This repository has been archived by the owner on May 17, 2024. It is now read-only.

Commit

Permalink
add schema.org events to head (#3385)
Browse files Browse the repository at this point in the history
* add schema.org events to head

* fix lint

* lint fix

* [WIP] events from schemaorgs

* move schemaOrg to composable

* add list of events

* move events schema to events/index

* remove qiskit schema composable

* add eventschema to all event pages

* add schema.org events to head

* fix lint

* lint fix

* [WIP] events from schemaorgs

* move schemaOrg to composable

* add list of events

* move events schema to events/index

* remove qiskit schema composable

* add eventschema to all event pages

* fix import

* [WIP]

* move reusable code to utils/

* add schema.org events to head

* fix lint

* lint fix

* [WIP] events from schemaorgs

* move schemaOrg to composable

* add list of events

* move events schema to events/index

* remove qiskit schema composable

* add eventschema to all event pages

* add schema.org events to head

* fix lint

* [WIP] events from schemaorgs

* move schemaOrg to composable

* add list of events

* move events schema to events/index

* remove qiskit schema composable

* fix import

* [WIP]

* move reusable code to utils/

* fix lint

* Apply suggestions from code review

Co-authored-by: Eddybrando Vásquez <eddybrando.vasquez@gmail.com>

* [WIP] fixing PR requests

* fix: add EventSchemaOrg type

* chore: DRY sort events

* fix: useSchemaOrg fix

* resolve PR conversations

* chore: remove unused layout

---------

Co-authored-by: Yaiza <yaiza.garcia.mm@gmail.com>
Co-authored-by: Eddybrando Vásquez <eddybrando.vasquez@gmail.com>
  • Loading branch information
3 people authored Aug 1, 2023
1 parent 0dca4d2 commit 76b2080
Show file tree
Hide file tree
Showing 10 changed files with 189 additions and 3 deletions.
21 changes: 21 additions & 0 deletions components/EventsFallFest/EventsFallFestUniversityDirectory.vue
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,27 @@ const universities: University[] = [
},
},
];
const config = useRuntimeConfig();
const sortedEvents = sortEvents(universities);
useSchemaOrg([
defineItemList({
itemListElement: sortedEvents.map((event) =>
createEventSchemaOrg({
startDate: new Date(event.startDate),
location: event.title,
mode: event.detail === "In Person" ? "Offline" : "Online",
url: `${config.public.siteUrl}/fall-fest`,
name: event.title,
image: event.image,
})
),
itemListOrder: "Ascending",
numberOfItems: sortedEvents.length,
}),
]);
</script>

<style lang="scss" scoped>
Expand Down
2 changes: 1 addition & 1 deletion constants/summerSchool2022Content.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MosaicElement } from "~/types/uiComponents";
import { DescriptionCard, MosaicElement } from "~/types/uiComponents";

const header = {
titleLine1: "Qiskit Global Summer School 2022:",
Expand Down
6 changes: 4 additions & 2 deletions nuxt.config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { defineNuxtConfig } from "nuxt/config";
import fetchEvents from "./hooks/update-events";
import fetchAdvocates from "./hooks/update-advocates";
import fetchEcosystemMembers from "./hooks/update-ecosystem";
Expand All @@ -6,13 +7,14 @@ import { generateMocks } from "./hooks/mock/mock-service";
const { AIRTABLE_API_KEY, GENERATE_CONTENT, NODE_ENV, SITE_URL, MOCK_CONTENT } =
process.env;
const IS_PRODUCTION = NODE_ENV === "production";
const siteUrl = SITE_URL || "https://qiskit.org";

// https://nuxt.com/docs/api/configuration/nuxt-config
export default defineNuxtConfig({
modules: ["@nuxt/content", "@nuxt/image-edge", "nuxt-schema-org"],

schemaOrg: {
host: "https://qiskit.org",
host: siteUrl,
},

runtimeConfig: {
Expand All @@ -26,7 +28,7 @@ export default defineNuxtConfig({
IBM_ANALYTICS_SEGMENT_PRODUCT_TITLE: "",
IBM_ANALYTICS_SEGMENT_SCRIPT_SRC: "",
IBM_ANALYTICS_SEGMENT_UT30: "",
siteUrl: SITE_URL || "https://qiskit.org",
siteUrl,
},
},

Expand Down
23 changes: 23 additions & 0 deletions pages/events/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,29 @@ const selectTab = (selectedTab: string) => {
tabsIsDirty.value = true;
};
const sortedEvents = sortEvents(upcomingEvents);
useSchemaOrg([
defineItemList({
itemListElement: sortedEvents.map((event) =>
createEventSchemaOrg({
startDate: new Date(event.startDate),
mode: ["YouTube", "Virtual"].includes(event.location)
? "Online"
: "Offline",
location: event.location,
url: event.to,
name: event.title,
image: event.image,
performer: event.speaker,
endDate: event.endDate ? new Date(event.endDate) : undefined,
})
),
itemListOrder: "Ascending",
numberOfItems: sortedEvents.length,
}),
]);
</script>

<style lang="scss" scoped>
Expand Down
21 changes: 21 additions & 0 deletions pages/events/seminar-series.vue
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,27 @@ function dataPerRow(
},
]);
}
const sortedEvents = sortEvents(upcomingSeminarSerieEvents);
useSchemaOrg([
defineItemList({
itemListElement: sortedEvents.map((event) =>
createEventSchemaOrg({
startDate: new Date(event.startDate),
mode: "Online",
location: event.location,
url: event.to,
name: event.title,
image: event.image,
performer: event.speaker,
endDate: event.endDate ? new Date(event.endDate) : undefined,
})
),
itemListOrder: "Ascending",
numberOfItems: sortedEvents.length,
}),
]);
</script>

<style lang="scss" scoped>
Expand Down
12 changes: 12 additions & 0 deletions pages/events/summer-school-2022.vue
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,18 @@ const headerData = header;
const mosaicData = mosaic;
const agendaData = agenda;
const helpfulResourcesData = helpfulResources;
useSchemaOrg([
createEventSchemaOrg({
startDate: new Date("2022-07-18"),
mode: "Online",
location: "",
url: `${config.public.siteUrl}/events/summer-school-2022/`,
name: headerData.card.title,
image: `${config.public.siteUrl}${headerData.card.image}`,
endDate: new Date("2022-07-29"),
}),
]);
</script>

<style lang="scss" scoped>
Expand Down
12 changes: 12 additions & 0 deletions pages/events/summer-school-2023.vue
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,18 @@ const headerCta = headerData.cta;
const mosaicData = mosaic;
const agendaData = agenda;
const helpfulResourcesData = helpfulResources;
useSchemaOrg([
createEventSchemaOrg({
startDate: new Date("2023-07-17"),
mode: "Online",
location: "",
url: `${config.public.siteUrl}/events/summer-school-2023/`,
name: headerData.card.title,
image: `${config.public.siteUrl}${headerData.card.image}`,
endDate: new Date("2023-07-28"),
}),
]);
</script>

<style lang="scss" scoped>
Expand Down
85 changes: 85 additions & 0 deletions utils/event-schema-org.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
type EventAttendanceModeTypes =
| "OfflineEventAttendanceMode"
| "OnlineEventAttendanceMode"
| "MixedEventAttendanceMode";

interface VirtualLocation {
"@type"?: "VirtualLocation";
url: string;
}
interface Place {
name: string;
address: string;
url: string;
}

interface EventSchemaOrg {
name: string;
eventAttendanceMode: EventAttendanceModeTypes;
image: string;
location: VirtualLocation | Place;
startDate: string;
organizer: {
name: string;
url: string;
};
performer?: {
name: string;
};
endDate?: string;
}

interface Event {
startDate: Date;
mode: "Online" | "Offline";
location: string;
url: string;
name: string;
image: string;
performer?: string;
endDate?: Date;
}

export function createEventSchemaOrg(event: Event) {
let location;
if (event.mode === "Online") {
location = {
url: event.url,
};
} else {
location = {
name: event.location,
address: event.location,
url: event.url,
};
}

const eventAttendanceMode =
event.mode === "Online"
? "OnlineEventAttendanceMode"
: "OfflineEventAttendanceMode";

const schemaEvent: EventSchemaOrg = {
name: event.name,
eventAttendanceMode,
image: event.image,
location,
startDate: new Date(event.startDate).toISOString(),
organizer: {
name: "IBM Quantum",
url: "https://ibm.com/quantum",
},
};

if (event.performer) {
schemaEvent.performer = {
name: event.performer,
};
}

if (event.endDate) {
schemaEvent.endDate = event.endDate.toISOString();
}

return defineEvent(schemaEvent);
}
10 changes: 10 additions & 0 deletions utils/sort-events.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export function sortEvents<T extends { startDate: string }>(events: T[]): T[] {
return events
.filter((event) => event.startDate)
.sort((a, b) => {
const dateA = new Date(a.startDate);
const dateB = new Date(b.startDate);

return dateA > dateB ? 1 : dateA < dateB ? -1 : 0;
});
}
File renamed without changes.

0 comments on commit 76b2080

Please sign in to comment.