Skip to content

Commit d83e45b

Browse files
committed
✨ render NFD banners
♻️refactor to library ♻️refactor shadcn components to Astro
1 parent 15ea0f3 commit d83e45b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+3875
-6964
lines changed

.db/db.json .db/nfds.json

File renamed without changes.

package-lock.json

+46-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+8-5
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@
55
"scripts": {
66
"dev": "astro dev",
77
"build": "astro build",
8-
"preview": "npm run generate && astro build && wrangler pages dev",
8+
"preview": "astro build && wrangler pages dev",
99
"astro": "astro",
1010
"deploy": "npm run generate && astro build && wrangler pages deploy",
11-
"cf-typegen": "wrangler types",
12-
"generate": "npx @hey-api/openapi-ts -c @hey-api/client-fetch -i https://api.nf.domains/info/openapi3.yaml -o ./src/lib/nfd/client"
11+
"cf-typegen": "wrangler types"
1312
},
1413
"dependencies": {
1514
"@astrojs/cloudflare": "^12.2.1",
@@ -18,7 +17,10 @@
1817
"@astrojs/rss": "^4.0.11",
1918
"@astrojs/sitemap": "^3.2.1",
2019
"@astrojs/tailwind": "^5.1.5",
21-
"@hey-api/client-fetch": "^0.7.1",
20+
"@awesome-algorand/ipfs-toolkit": "^0.0.1-experimental.1",
21+
"@awesome-algorand/nfd-fetch": "^0.0.1-experimental.3",
22+
"@awesome-algorand/nfd-toolkit": "^0.0.1-experimental.1",
23+
"@hey-api/client-fetch": "^0.7.0",
2224
"@radix-ui/react-avatar": "^1.1.2",
2325
"@radix-ui/react-dropdown-menu": "^2.1.5",
2426
"@radix-ui/react-navigation-menu": "^1.2.4",
@@ -40,7 +42,8 @@
4042
"react-dom": "^19.0.0",
4143
"tailwind-merge": "^2.6.0",
4244
"tailwindcss": "^3.4.17",
43-
"tailwindcss-animate": "^1.0.7"
45+
"tailwindcss-animate": "^1.0.7",
46+
"world-geojson": "^3.1.1"
4447
},
4548
"devDependencies": {
4649
"@cloudflare/workers-types": "^4.20250124.3",
File renamed without changes.

public/favicon.ico

14.7 KB
Binary file not shown.

public/favicon.png

9.21 KB
Loading

public/favicon.svg

-9
This file was deleted.

public/nfd.png

-1.15 KB
Binary file not shown.

public/nfd/banner-placeholder.webp

5.69 KB
Binary file not shown.
File renamed without changes.
File renamed without changes.

public/relays/marker.png

17.1 KB
Loading

scripts/cache-nations.ts

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/**
2+
* This script is used to cache data based on geographic location.
3+
* TODO: Think about if this is a good idea or not. It gets political quickly
4+
*/
5+
import * as world from "world-geojson";
6+
import * as turf from '@turf/turf'
7+
8+
import geoJson from '../src/layers/nfds.geo.json'
9+
import type { Feature } from "geojson";
10+
11+
// FS Tools
12+
import fs from "fs";
13+
import { dirname } from "path";
14+
import { fileURLToPath } from "url";
15+
const __dirname = dirname(fileURLToPath(import.meta.url));
16+
17+
18+
// EXAMPLE UNIONS:
19+
// The European Union: A union of member states
20+
// The Eurasian Economic Union: A transcontinental union of states from Europe and Asia
21+
// The Association of Southeast Asian Nations (ASEAN): A political union
22+
// The Asia-Pacific Economic Cooperation Forum: A political union
23+
// The Pacific Islands Forum: A political union
24+
// The North Atlantic Treaty Organization (NATO): A political union of member states
25+
// The African Union: A political union
26+
27+
// This is an example of how to use the world-geojson package and turf to filter out only the features that are within the USA
28+
const usaPoly = turf.polygon(world.forCountry('USA').features[0].geometry.coordinates)
29+
30+
let usaFeatures = turf.featureCollection([])
31+
geoJson.features.forEach((feature) => {
32+
const point = turf.point(feature.geometry.coordinates)
33+
const res = turf.pointsWithinPolygon(point, usaPoly)
34+
if(res.features.length > 0) {
35+
usaFeatures.features.push(feature as Feature)
36+
}
37+
})
38+
39+
40+
console.log(usaFeatures)

scripts/cache-nfd.ts

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import fs from "fs";
2+
import { dirname, resolve } from "path";
3+
import { fileURLToPath } from "url";
4+
import {type NfdRecordCollection} from '@awesome-algorand/nfd-fetch'
5+
import { type NfdGeoProperties, toFeatureCollection } from "@awesome-algorand/nfd-toolkit";
6+
import {
7+
fetchAll,
8+
totals,
9+
} from "@/lib/nfd";
10+
import type { FeatureCollection, Point } from "geojson";
11+
12+
13+
const __dirname = dirname(fileURLToPath(import.meta.url));
14+
export const NFD_CACHE = resolve(__dirname, '../.db/nfds.json')
15+
export const NFD_GEOJSON = resolve(__dirname, '../src/layers/nfds.geo.json')
16+
17+
let data: NfdRecordCollection;
18+
if (fs.existsSync(NFD_CACHE) && process.env.FORCE_DOWNLOAD !== "true") {
19+
data = JSON.parse(fs.readFileSync(NFD_CACHE, "utf8"));
20+
} else {
21+
const total = await totals();
22+
data = await fetchAll(total.total);
23+
24+
// Backup data
25+
fs.writeFileSync(NFD_CACHE, JSON.stringify(data, null, 2));
26+
}
27+
28+
// Load the existing geojson
29+
let geo: FeatureCollection<Point, NfdGeoProperties> = fs.existsSync(NFD_GEOJSON) && process.env.FORCE_DOWNLOAD !== "true" ?
30+
JSON.parse(fs.readFileSync(NFD_GEOJSON, "utf8")) :
31+
{
32+
type: "FeatureCollection",
33+
features: []
34+
}
35+
36+
// Update the resources
37+
const geoJson = await toFeatureCollection(data, geo.features);
38+
// Filter out invalid coordinates
39+
40+
geoJson.features = geoJson.features.filter((pin: any) =>
41+
pin.geometry.coordinates[0] !== -40 && pin.geometry.coordinates[1] !== 25,
42+
);
43+
// Write to disk
44+
fs.writeFileSync(NFD_GEOJSON, JSON.stringify(geoJson, null, 2));

scripts/cache-relays.ts

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/**
2+
* This script downloads the latest list of relay nodes from the awesome-algorand repository,
3+
* translates them to GeoJSON and caches it to the src/layers/relays.geo.json file
4+
*/
5+
6+
import fs from 'fs'
7+
import { dirname, resolve } from 'path';
8+
import { fileURLToPath } from 'url';
9+
import * as turf from '@turf/turf'
10+
11+
const __dirname = dirname(fileURLToPath(import.meta.url));
12+
13+
const RELAY_URL = 'https://raw.githubusercontent.com/awesome-algorand/awesome-algorand/stats/.github/scripts/relay_nodes.json'
14+
const RELAY_CACHE = resolve(__dirname, '../src/layers/relays.geo.json')
15+
16+
type RelayRecord = {
17+
"lat": number,
18+
"lon": number,
19+
"countryCode": string,
20+
"country": string,
21+
"city": string,
22+
"domain": string,
23+
"ip": string
24+
}
25+
26+
let data
27+
if( fs.existsSync(RELAY_CACHE) && process.env.FORCE_DOWNLOAD !== 'true' ) {
28+
data = JSON.parse(fs.readFileSync(RELAY_CACHE, 'utf8'))
29+
} else {
30+
data = await fetch(RELAY_URL).then(res => res.json())
31+
data = turf.featureCollection(data.map((relay: RelayRecord)=>{
32+
return turf.point([relay.lon, relay.lat], {
33+
countryCode: relay.countryCode,
34+
name: relay.city,
35+
country: relay.country,
36+
domain: relay.domain,
37+
ip: relay.ip
38+
})
39+
}))
40+
fs.writeFileSync(RELAY_CACHE, JSON.stringify(data, null, 2))
41+
}
42+

src/components/Card.tsx

-98
This file was deleted.

0 commit comments

Comments
 (0)