Skip to content

Commit 93fd495

Browse files
Switch from Pocketbase data retrieval to JSON (#100)
* Add new animation for switching themes. * Remove unused metadata files from testing * increase duration on theme switch * Reduce animation duration for view transition effect to improve responsiveness * Fetch categories and scripts from external sources, updating `GET` endpoint to aggregate data. Adjust type definitions for Script and Category * Refactor all components to use data from new API * Refactor `InterFaces` component to use updated `Script` type and streamline interface/port handling for better clarity * Refactor `CommandMenu` component to utilize updated `Category` and `Script` types, simplifying the sorting logic and enhancing clarity * Fix animation duration in `globals.css` to ensure proper view transition functionality across the application * Remove unnecessary console log for file name in `fetchAllMetaDataFiles` to clean up code * Refactor category fetching in `ScriptContent` and `CommandMenu` to utilize centralized `fetchCategories` for improved maintainability * Use `formattedBadge` in `ScriptAccordion` and `CommandMenu` for consistent badge rendering across script types * Refactor source URL generation in `Buttons` component to enhance clarity and streamline the installation script logic * Check default settings availability in `DefaultSettings` component and handle undefined values more gracefully in rendering * Fix install command generation to handle optional script parameter and update copy button logic for improved functionality * Add most popular scripts feature and update script rendering logic in `ScriptInfoBlocks` component * Enhance `ScriptItem` component to display correct type naming alongside script name for better clarity in the UI * Add conversion utility to display RAM in GB for better readability in `DefaultSettings` component * Refactor Next.js config to use dynamic basePath and update sitemap URLs for improved adaptability and host configuration * Refactor site configuration to utilize centralized settings for analytics and base path; replace PocketBase imports with new data module * Refactor sitemap generation to use centralized basePath from config, enhancing adaptability for URL management * Refactor to replace PocketBase with a new data module across components * Refactor layout to use centralized analytics configuration * Update deployment workflow to include JSON files for GitHub Pages publishing * Remove caching step from GitHub Pages deploy workflow to avoid caching * Remove basePath from Next.js config to simplify configuration and avoid potential issues with path resolution * Add category sorting and fetching logic in data.ts * Add analytics configuration and basePath to siteConfig * Remove obsolete environment files for analytics and PocketBase * Update sitemap to use a fixed domain for the generated sitemap instead of deriving from headers * Refactor layout to utilize basePath for metadata base URL and image links for better configurability * use cleaner `basePath` variable around codebase for easier management * Update frontend/src/app/api/categories/route.ts Co-authored-by: Håvard Gjøby Thom <[email protected]> * Update frontend/src/app/api/categories/route.ts Co-authored-by: Håvard Gjøby Thom <[email protected]> * Update frontend/src/app/api/categories/route.ts Co-authored-by: Håvard Gjøby Thom <[email protected]> * Update frontend/src/components/CommandMenu.tsx Co-authored-by: Håvard Gjøby Thom <[email protected]> * Update frontend/src/components/ui/theme-toggle.tsx Co-authored-by: Håvard Gjøby Thom <[email protected]> * Update frontend/src/components/CommandMenu.tsx Co-authored-by: Håvard Gjøby Thom <[email protected]> * Update frontend/src/app/api/categories/route.ts Co-authored-by: Håvard Gjøby Thom <[email protected]> * Update frontend/src/app/api/categories/route.ts Co-authored-by: Håvard Gjøby Thom <[email protected]> * Update frontend/src/app/scripts/_components/ScriptItems/DefaultPassword.tsx Co-authored-by: Håvard Gjøby Thom <[email protected]> * Update frontend/src/app/scripts/_components/ScriptItems/DefaultSettings.tsx Co-authored-by: Håvard Gjøby Thom <[email protected]> * Update src/lib/data.ts with necessary changes. Co-authored-by: Håvard Gjøby Thom <[email protected]> * Update src/app/api/categories/route.ts with necessary modifications * Update frontend/src/app/scripts/_components/ScriptItems/InstallCommand.tsx Co-authored-by: Håvard Gjøby Thom <[email protected]> * Update src/components/CommandMenu.tsx with necessary improvements * Add renamed themetoggle * Update frontend/src/app/scripts/_components/ScriptInfoBlocks.tsx Co-authored-by: Håvard Gjøby Thom <[email protected]> * Update frontend/src/app/scripts/_components/ScriptItems/DefaultSettings.tsx Co-authored-by: Håvard Gjøby Thom <[email protected]> * Update frontend/src/app/scripts/_components/ScriptItems/DefaultSettings.tsx with new settings configuration * Update src/app/scripts/_components/ScriptInfoBlocks.tsx with enhancements and fixes * Update src/app/scripts/_components/ScriptItems/InstallCommand.tsx * Update src/app/scripts/_components/ScriptItem.tsx * Update src/app/scripts/_components/ScriptAccordion.tsx with necessary adjustments and improvements * Update Interfaces to use strict check * updated interfaces to use normal string label instead of jsx * Update configuration to use environment variable for BASE_PATH and reflect changes in siteConfig * force static base path * Update CommandMenu.tsx Co-authored-by: Håvard Gjøby Thom <[email protected]> * Update DefaultSettings.tsx Co-authored-by: Håvard Gjøby Thom <[email protected]> * Update DefaultSettings.tsx Co-authored-by: Håvard Gjøby Thom <[email protected]> * Ensure fetchScripts returns a typed Script array by specifying return type in map function * Remove commented-out import for unused Category type in CommandMenu component * Fix fetch URLs by removing unnecessary slashes and ensure proper return type in fetchScripts map function * Refactor MostViewedScripts to ensure proper type annotations and improve array concatenation method for better readability * Update BASE_PATH handling in next.config and fix fetch URLs to ensure correct path structure in API routes --------- Co-authored-by: Håvard Gjøby Thom <[email protected]>
1 parent 97008d0 commit 93fd495

37 files changed

+474
-453
lines changed

.github/workflows/deploy-pages.yml

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ on:
99
branches: ["main"]
1010
paths:
1111
- frontend/**
12+
- json/**
1213

1314
workflow_dispatch:
1415

@@ -57,14 +58,6 @@ jobs:
5758
uses: actions/configure-pages@v5
5859
with:
5960
static_site_generator: next
60-
- name: Restore cache
61-
uses: actions/cache@v4
62-
with:
63-
path: |
64-
frontend/.next/cache
65-
key: ${{ runner.os }}-nextjs-${{ hashFiles('frontend/**/package-lock.json', 'frontend/**/yarn.lock') }}-${{ hashFiles('frontend/**.[jt]s', 'frontend/**.[jt]sx') }}
66-
restore-keys: |
67-
${{ runner.os }}-nextjs-${{ hashFiles('frontend/**/package-lock.json', 'frontend/**/yarn.lock') }}-
6861
- name: Install dependencies
6962
run: ${{ steps.detect-package-manager.outputs.manager }} ${{ steps.detect-package-manager.outputs.command }} --legacy-peer-deps
7063
- name: Build with Next.js

frontend/.env.local

Lines changed: 0 additions & 3 deletions
This file was deleted.

frontend/example.env

Lines changed: 0 additions & 4 deletions
This file was deleted.

frontend/next.config.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ const nextConfig = {
1515
},
1616

1717
env: {
18-
NEXT_PUBLIC_BUILD_TIME: `${Date.now()}`,
18+
BASE_PATH: "ProxmoxVE",
1919
},
2020

2121
output: "export",
22-
basePath: "/ProxmoxVE",
22+
basePath: `/${process.env.BASE_PATH}`,
2323
};
2424

2525
export default nextConfig;

frontend/package-lock.json

Lines changed: 10 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

frontend/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"@radix-ui/react-accordion": "^1.1.2",
2323
"@radix-ui/react-dialog": "^1.0.5",
2424
"@radix-ui/react-dropdown-menu": "^2.0.6",
25+
"@radix-ui/react-icons": "^1.3.1",
2526
"@radix-ui/react-navigation-menu": "^1.1.4",
2627
"@radix-ui/react-separator": "^1.1.0",
2728
"@radix-ui/react-slot": "^1.1.0",
@@ -31,7 +32,7 @@
3132
"class-variance-authority": "^0.7.0",
3233
"clsx": "^2.1.1",
3334
"cmdk": "^1.0.0",
34-
"framer-motion": "^11.11.10",
35+
"framer-motion": "^11.11.11",
3536
"fuse.js": "^7.0.0",
3637
"lucide-react": "^0.453.0",
3738
"mini-svg-data-uri": "^1.4.4",

frontend/public/metadata/docker.json

Lines changed: 0 additions & 23 deletions
This file was deleted.

frontend/public/metadata/nginxproxymanager.json

Lines changed: 0 additions & 20 deletions
This file was deleted.

frontend/src/app/api/categories/route.ts

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,45 @@
1-
import { pb } from "@/lib/pocketbase";
2-
import { Category } from "@/lib/types";
1+
import { basePath } from "@/config/siteConfig";
2+
import { Category, Script } from "@/lib/types";
33
import { NextResponse } from "next/server";
44

55
export const dynamic = "force-static";
66

7+
const fetchCategories = async (): Promise<Category[]> => {
8+
const response = await fetch(
9+
`https://raw.githubusercontent.com/community-scripts/${basePath}/refs/heads/main/json/metadata.json`,
10+
);
11+
const data = await response.json();
12+
return data.categories;
13+
};
14+
15+
const fetchScripts = async (): Promise<Script[]> => {
16+
const response = await fetch(
17+
`https://api.github.com/repos/community-scripts/${basePath}/contents/json`,
18+
);
19+
const files: { download_url: string }[] = await response.json();
20+
const scripts = await Promise.all(
21+
files.map(async (file) : Promise<Script> => {
22+
const response = await fetch(file.download_url);
23+
const script = await response.json();
24+
return script;
25+
}),
26+
);
27+
return scripts;
28+
};
29+
730
export async function GET() {
831
try {
9-
const response = await pb.collection("categories").getFullList<Category>({
10-
expand: "items.alerts,items.alpine_script,items.default_login",
11-
sort: "order",
12-
});
13-
14-
return NextResponse.json(response);
32+
const categories = await fetchCategories();
33+
const scripts = await fetchScripts();
34+
for (const category of categories) {
35+
category.scripts = scripts.filter((script) => script.categories.includes(category.id));
36+
}
37+
return NextResponse.json(categories);
1538
} catch (error) {
16-
console.error("Error fetching categories:", error);
39+
console.error(error as Error);
1740
return NextResponse.json(
1841
{ error: "Failed to fetch categories" },
1942
{ status: 500 },
2043
);
2144
}
2245
}
23-

frontend/src/app/layout.tsx

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import "@/styles/globals.css";
66
import { Inter } from "next/font/google";
77
import React from "react";
88
import { NuqsAdapter } from "nuqs/adapters/next/app";
9+
import { analytics, basePath } from "@/config/siteConfig";
910

1011
const inter = Inter({ subsets: ["latin"] });
1112

@@ -34,15 +35,15 @@ export const metadata = {
3435
address: false,
3536
telephone: false,
3637
},
37-
metadataBase: new URL("https://community-scripts.github.io/Proxmox/"),
38+
metadataBase: new URL(`https://community-scripts.github.io/${basePath}/`),
3839
openGraph: {
3940
title: "Proxmox VE Helper-Scripts",
4041
description:
4142
"A Front-end for the Proxmox VE Helper-Scripts (Community) Repository. Featuring over 200+ scripts to help you manage your Proxmox VE environment.",
4243
url: "/defaultimg.png",
4344
images: [
4445
{
45-
url: "https://community-scripts.github.io/Proxmox/defaultimg.png",
46+
url: `https://community-scripts.github.io/${basePath}/defaultimg.png`,
4647
},
4748
],
4849
locale: "en_US",
@@ -60,15 +61,20 @@ export default function RootLayout({
6061
<head>
6162
<script
6263
defer
63-
src={`https://${process.env.NEXT_PUBLIC_ANALYTICS_URL}/script.js`}
64-
data-website-id={process.env.NEXT_PUBLIC_ANALYTICS_TOKEN}
64+
src={`https://${analytics.url}/script.js`}
65+
data-website-id={analytics.token}
6566
></script>
6667
<link rel="manifest" href="manifest.webmanifest" />
6768
<link rel="preconnect" href={process.env.NEXT_PUBLIC_POCKETBASE_URL} />
6869
<link rel="preconnect" href="https://api.github.com" />
6970
</head>
7071
<body className={inter.className}>
71-
<ThemeProvider attribute="class" defaultTheme="dark" enableSystem>
72+
<ThemeProvider
73+
attribute="class"
74+
defaultTheme="dark"
75+
enableSystem
76+
disableTransitionOnChange
77+
>
7278
<div className="flex w-full flex-col justify-center">
7379
<Navbar />
7480
<div className="flex min-h-screen flex-col justify-center">

0 commit comments

Comments
 (0)