-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
1,749 additions
and
7,098 deletions.
There are no files selected for viewing
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
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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,62 +1,32 @@ | ||
--- | ||
import { NewsSliderComponent } from "@components"; | ||
import { writeFileSync } from "fs"; | ||
import { getNewsItems } from "@util/AirTable"; | ||
import type { INewsItem } from "@interfaces/INews"; | ||
const { headline, id, ...rest } = Astro.props; | ||
const AIRTABLE_BASE_URL = "https://api.airtable.com/v0/"; | ||
const token = import.meta.env.PUBLIC_AIRTABLE_TOKEN; | ||
const options = { | ||
method: "GET", | ||
headers: { | ||
Authorization: `Bearer ${token}`, | ||
}, | ||
}; | ||
const response = await fetch( | ||
AIRTABLE_BASE_URL + "appy8mE1ZpLXfYzEQ/tblvfXTgnme0tqIQD", | ||
options | ||
); | ||
const data = await response.json(); | ||
let news = []; | ||
if (data.records && data.records.length > 0) { | ||
try { | ||
writeFileSync( | ||
"./fetch.json", | ||
JSON.stringify(data.records) | ||
); | ||
// file written successfully | ||
} catch (err) { | ||
console.error("Error while writing file", err); | ||
} | ||
news = data.records | ||
// has Instagram URL | ||
.filter((record) => record.fields?.["Instagram URL"]) | ||
// has status "live" | ||
.filter((record) => record.fields?.["Status"] === "live") | ||
// is of media type "photo" | ||
.filter((record) => record.fields?.["Media type"]?.includes("photo")) | ||
// has images | ||
.filter((record) => record.fields?.["Selected Photos (from Event)"]?.length) | ||
.map((record) => { | ||
return { | ||
title: record.fields.Name, | ||
target: record.fields?.["Instagram URL"], | ||
instagram: true, | ||
image: | ||
record.fields?.["Selected Photos (from Event)"]?.[0].thumbnails?.[ | ||
"large" | ||
]?.url, | ||
}; | ||
}); | ||
console.log("NEWS", news); | ||
} else { | ||
console.log("Error"); | ||
} | ||
const data = await getNewsItems(); | ||
const news = data | ||
// has Instagram URL | ||
?.filter((record) => record.fields?.["Instagram URL"]) | ||
// has status "live" | ||
.filter((record) => record.fields?.["Status"] === "live") | ||
// is of media type "photo" | ||
.filter((record) => record.fields?.["Media type"]?.includes("photo")) | ||
// has images | ||
.filter((record) => record.fields?.["Selected Photos (from Event)"]?.length) | ||
.map((record) => { | ||
return { | ||
title: record.fields.Name, | ||
target: record.fields?.["Instagram URL"], | ||
instagram: true, | ||
image: | ||
record.fields?.["Selected Photos (from Event)"]?.[0].thumbnails?.[ | ||
"large" | ||
]?.url, | ||
} as INewsItem; | ||
}).splice(30); | ||
--- | ||
|
||
<NewsSliderComponent {news} {headline} {id} {...rest} client:idle /> | ||
<NewsSliderComponent news={news || []} {headline} {id} {...rest} client:idle /> |
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 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 |
---|---|---|
|
@@ -37,8 +37,8 @@ const trimmedAndSorted = trimAndSortInterventions(rawInterventionsContent); | |
title={intervention.frontmatter?.title} | ||
teaser={intervention.frontmatter?.teaser} | ||
tags={[ | ||
intervention.frontmatter?.tags?.[0], | ||
intervention.frontmatter?.tags?.[1], | ||
intervention.frontmatter?.tags?.[0] || "", | ||
intervention.frontmatter?.tags?.[1] || "", | ||
]} | ||
date={intervention.frontmatter?.date} | ||
location={intervention.frontmatter?.location} | ||
|
@@ -66,18 +66,20 @@ const trimmedAndSorted = trimAndSortInterventions(rawInterventionsContent); | |
bg={4} | ||
target="mailto:[email protected]" | ||
actionCaption="Get in contact" | ||
>Schools, universities, NGOs, Startups and other organizations can reach | ||
out to us to request the Tolocars for projects, workshops and trainings.</Card | ||
> | ||
Schools, universities, NGOs, Startups and other organizations can reach | ||
out to us to request the Tolocars for projects, workshops and trainings. | ||
</Card> | ||
<Card | ||
title="You are a Maker and want to partner with us?" | ||
bg={5} | ||
target="mailto:[email protected]" | ||
actionCaption="Get in contact" | ||
>We are looking for Makers, FabLabs, Hackerspaces, Makerspaces and other | ||
Communities who wants to partner with us in the Ukraine and | ||
internationally over the internet.</Card | ||
> | ||
We are looking for Makers, FabLabs, Hackerspaces, Makerspaces and other | ||
Communities who wants to partner with us in the Ukraine and | ||
internationally over the internet. | ||
</Card> | ||
</CardContainer> | ||
</ContentSection> | ||
</BaseLayout> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import fs from "node:fs"; | ||
|
||
const AIRTABLE_BASE_URL = "https://api.airtable.com/v0/"; | ||
const AIRTABLE_BASE_ID = "appy8mE1ZpLXfYzEQ/tblvfXTgnme0tqIQD"; | ||
|
||
const token = import.meta.env.PUBLIC_AIRTABLE_TOKEN; | ||
|
||
const commonHeaders = { | ||
"content-type": "application/json", | ||
Authorization: `Bearer ${token}`, | ||
}; | ||
|
||
interface AirtableResponse { | ||
records: Array<{ | ||
id?: string; | ||
createdTime?: string; | ||
fields: { | ||
Name?: string; | ||
"Instagram URL"?: string; | ||
Status?: string; | ||
"Media type"?: Array<string>; | ||
"Selected Photos (from Event)"?: Array<{ | ||
id?: string; | ||
url?: string; | ||
thumbnails?: { | ||
small?: { url?: string }; | ||
medium?: { url?: string }; | ||
large?: { url?: string }; | ||
}; | ||
}>; | ||
Type?: Array<string>; | ||
}; | ||
}>; | ||
} | ||
|
||
const fetchAndHandleErrors = async <T>( | ||
resource: RequestInfo, | ||
options?: RequestInit | ||
): Promise<T> => { | ||
const response = await fetch(AIRTABLE_BASE_URL + resource, { | ||
...options, | ||
headers: { | ||
...options?.headers, | ||
...commonHeaders, | ||
}, | ||
}); | ||
|
||
console.log(JSON.stringify(response)); | ||
|
||
if (!response.ok) { | ||
const text = await response.text(); | ||
console.error("Server returned Error: " + text); | ||
throw new Error("Server returned Error: " + text); | ||
} | ||
|
||
return response.json(); | ||
}; | ||
|
||
export const getNewsItems = async () => { | ||
const { records } = await fetchAndHandleErrors<AirtableResponse>( | ||
AIRTABLE_BASE_ID | ||
); | ||
|
||
if (records && records.length > 0) { | ||
try { | ||
fs.writeFileSync("./fetch.json", JSON.stringify(records)); | ||
// file written successfully | ||
} catch (err) { | ||
console.error("Error while writing file", err); | ||
} | ||
return records; | ||
} | ||
}; |
Oops, something went wrong.