diff --git a/.github/workflows/translation-progress.yml b/.github/workflows/translation-progress.yml index ca2bb87e..1607e918 100644 --- a/.github/workflows/translation-progress.yml +++ b/.github/workflows/translation-progress.yml @@ -6,7 +6,7 @@ on: branches: - main paths: - - "src/translations.php" + - "api/translations.php" - "scripts/translation-progress.php" - ".github/workflows/translation-progress.yml" - "README.md" diff --git a/.vercelignore b/.vercelignore new file mode 100644 index 00000000..e9c5a7aa --- /dev/null +++ b/.vercelignore @@ -0,0 +1,20 @@ +# Generated files +vendor/ +node_modules/ +*.log +composer.phar +yarn.lock +package-lock.json +composer.lock + +# Local Configuration +package.json +.DS_Store + +# Environment +.env +DOCKER_ENV +docker_tag + +# IDE +.vscode/ diff --git a/Procfile b/Procfile index 29bb24c8..7284f824 100644 --- a/Procfile +++ b/Procfile @@ -1 +1 @@ -web: vendor/bin/heroku-php-apache2 src/ +web: vendor/bin/heroku-php-apache2 api/ diff --git a/src/card.php b/api/card.php similarity index 100% rename from src/card.php rename to api/card.php diff --git a/src/colors.php b/api/colors.php similarity index 100% rename from src/colors.php rename to api/colors.php diff --git a/src/demo/apple-touch-icon.png b/api/demo/apple-touch-icon.png similarity index 100% rename from src/demo/apple-touch-icon.png rename to api/demo/apple-touch-icon.png diff --git a/src/demo/css/style.css b/api/demo/css/style.css similarity index 100% rename from src/demo/css/style.css rename to api/demo/css/style.css diff --git a/src/demo/css/toggle-dark.css b/api/demo/css/toggle-dark.css similarity index 100% rename from src/demo/css/toggle-dark.css rename to api/demo/css/toggle-dark.css diff --git a/src/demo/favicon-16x16.png b/api/demo/favicon-16x16.png similarity index 100% rename from src/demo/favicon-16x16.png rename to api/demo/favicon-16x16.png diff --git a/src/demo/favicon-32x32.png b/api/demo/favicon-32x32.png similarity index 100% rename from src/demo/favicon-32x32.png rename to api/demo/favicon-32x32.png diff --git a/src/demo/icon.svg b/api/demo/icon.svg similarity index 100% rename from src/demo/icon.svg rename to api/demo/icon.svg diff --git a/src/demo/index.php b/api/demo/index.php similarity index 94% rename from src/demo/index.php rename to api/demo/index.php index 62f02c4e..daddce8d 100644 --- a/src/demo/index.php +++ b/api/demo/index.php @@ -1,7 +1,7 @@ @@ -47,8 +58,8 @@ function gtag() { GitHub Readme Streak Stats Demo - "> - "> + "> + "> @@ -56,10 +67,10 @@ function gtag() { - - - - + + + + diff --git a/src/demo/js/accordion.js b/api/demo/js/accordion.js similarity index 100% rename from src/demo/js/accordion.js rename to api/demo/js/accordion.js diff --git a/src/demo/js/jscolor.min.js b/api/demo/js/jscolor.min.js similarity index 100% rename from src/demo/js/jscolor.min.js rename to api/demo/js/jscolor.min.js diff --git a/src/demo/js/script.js b/api/demo/js/script.js similarity index 100% rename from src/demo/js/script.js rename to api/demo/js/script.js diff --git a/src/demo/js/toggle-dark.js b/api/demo/js/toggle-dark.js similarity index 100% rename from src/demo/js/toggle-dark.js rename to api/demo/js/toggle-dark.js diff --git a/src/demo/preview.php b/api/demo/preview.php similarity index 93% rename from src/demo/preview.php rename to api/demo/preview.php index 2a43bc64..23c7c8d3 100644 --- a/src/demo/preview.php +++ b/api/demo/preview.php @@ -2,8 +2,8 @@ declare(strict_types=1); -require_once "../card.php"; -require_once "../stats.php"; +require_once dirname(__DIR__, 1) . "/card.php"; +require_once dirname(__DIR__, 1) . "/stats.php"; $mode = $_GET["mode"] ?? "daily"; diff --git a/api/demo/vercel-static.php b/api/demo/vercel-static.php new file mode 100644 index 00000000..fd018b5c --- /dev/null +++ b/api/demo/vercel-static.php @@ -0,0 +1,31 @@ + text/css +// require __DIR__ . "/css/style.css" + +// Remove the "/demo" from the URI and the query string +$path = str_replace("/demo", "", strtok($_SERVER["REQUEST_URI"], "?")); +// Get the file extension +$extension = pathinfo($path, PATHINFO_EXTENSION); + +// Set the content type based on the file extension +switch ($extension) { + case "css": + header("Content-Type: text/css"); + break; + case "js": + header("Content-Type: text/javascript"); + break; + case "svg": + header("Content-Type: image/svg+xml"); + break; + case "png": + header("Content-Type: image/png"); + break; + default: + break; +} + +// Return the contents of the file +require __DIR__ . $path; diff --git a/src/index.php b/api/index.php similarity index 92% rename from src/index.php rename to api/index.php index 610543ad..a7685760 100644 --- a/src/index.php +++ b/api/index.php @@ -3,7 +3,7 @@ declare(strict_types=1); // load functions -require_once "../vendor/autoload.php"; +require_once dirname(__DIR__, 1) . "/vendor/autoload.php"; require_once "stats.php"; require_once "card.php"; @@ -12,8 +12,8 @@ $dotenv->safeLoad(); // if environment variables are not loaded, display error -if (!isset($_SERVER["TOKEN"])) { - $message = file_exists(dirname(__DIR__ . "../.env", 1)) +if (!isset($_ENV["TOKEN"])) { + $message = file_exists(dirname(__DIR__, 1) . "/.env") ? "Missing token in config. Check Contributing.md for details." : ".env was not found. Check Contributing.md for details."; renderOutput($message, 500); diff --git a/src/stats.php b/api/stats.php similarity index 99% rename from src/stats.php rename to api/stats.php index 6511758c..645b5a58 100644 --- a/src/stats.php +++ b/api/stats.php @@ -163,11 +163,11 @@ function getGitHubTokens(): array return $GLOBALS["ALL_TOKENS"]; } // find all tokens in environment variables - $tokens = isset($_SERVER["TOKEN"]) ? [$_SERVER["TOKEN"]] : []; + $tokens = isset($_ENV["TOKEN"]) ? [$_ENV["TOKEN"]] : []; $index = 2; - while (isset($_SERVER["TOKEN{$index}"])) { + while (isset($_ENV["TOKEN{$index}"])) { // add token to list - $tokens[] = $_SERVER["TOKEN{$index}"]; + $tokens[] = $_ENV["TOKEN{$index}"]; $index++; } // store for future use diff --git a/src/themes.php b/api/themes.php similarity index 100% rename from src/themes.php rename to api/themes.php diff --git a/src/translations.php b/api/translations.php similarity index 100% rename from src/translations.php rename to api/translations.php diff --git a/composer.json b/composer.json index 82a95b97..04318a8e 100644 --- a/composer.json +++ b/composer.json @@ -14,7 +14,7 @@ "homepage": "https://github.com/DenverCoder1/github-readme-streak-stats", "autoload": { "classmap": [ - "src/" + "api/" ] }, "require": { @@ -28,7 +28,7 @@ "scripts": { "start": [ "Composer\\Config::disableProcessTimeout", - "php -S localhost:8000 -t src" + "php -S localhost:8000 -t api" ], "test": "./vendor/bin/phpunit --testdox tests", "lint": "prettier --check *.md **/*.{php,md,js,css} !**/*.min.js --print-width 120", diff --git a/scripts/translation-progress.php b/scripts/translation-progress.php index 30289d27..5835aad6 100644 --- a/scripts/translation-progress.php +++ b/scripts/translation-progress.php @@ -1,6 +1,6 @@ $phrases) { // skip aliases @@ -77,7 +77,7 @@ function progressToBadges(array $progress): string if ($i % $per_row === 0) { $table .= ""; } - $line_url = "https://github.com/DenverCoder1/github-readme-streak-stats/blob/main/src/translations.php#L{$data["line_number"]}"; + $line_url = "https://github.com/DenverCoder1/github-readme-streak-stats/blob/main/api/translations.php#L{$data["line_number"]}"; $table .= "{$data["locale"]} - {$data["locale_name"]}
\"{$data["locale_name"]}"; $i++; if ($i % $per_row === 0) { @@ -120,7 +120,7 @@ function updateReadme(string $path, string $start, string $end, string $content) $progress = getProgress($GLOBALS["TRANSLATIONS"]); $badges = "\n" . progressToBadges($progress); $update = updateReadme( - __DIR__ . "/../README.md", + dirname(__DIR__, 1) . "/README.md", "", "", $badges diff --git a/tests/OptionsTest.php b/tests/OptionsTest.php index 370ec171..733dda1f 100644 --- a/tests/OptionsTest.php +++ b/tests/OptionsTest.php @@ -5,7 +5,7 @@ use PHPUnit\Framework\TestCase; // load functions -require_once "src/card.php"; +require_once "api/card.php"; final class OptionsTest extends TestCase { @@ -29,7 +29,7 @@ final class OptionsTest extends TestCase public function testThemes(): void { // check that getRequestedTheme returns correct colors for each theme - $themes = include "src/themes.php"; + $themes = include "api/themes.php"; foreach ($themes as $theme => $colors) { $actualColors = getRequestedTheme(["theme" => $theme]); $expectedColors = $colors; @@ -65,7 +65,7 @@ public function testFallbackToDefaultTheme(): void public function testThemesHaveValidParameters(): void { // check that all themes contain all parameters and have valid values - $themes = include "src/themes.php"; + $themes = include "api/themes.php"; $hexPartialRegex = "(?:[A-F0-9]{3}|[A-F0-9]{4}|[A-F0-9]{6}|[A-F0-9]{8})"; $hexRegex = "/^#{$hexPartialRegex}$/"; $backgroundRegex = "/^#{$hexPartialRegex}|-?\d+(?:,{$hexPartialRegex})+$/"; diff --git a/tests/RenderTest.php b/tests/RenderTest.php index a551736a..213d308a 100644 --- a/tests/RenderTest.php +++ b/tests/RenderTest.php @@ -5,7 +5,7 @@ use PHPUnit\Framework\TestCase; // load functions -require_once "src/card.php"; +require_once "api/card.php"; final class RenderTest extends TestCase { diff --git a/tests/StatsTest.php b/tests/StatsTest.php index c05516a7..de14f0a7 100644 --- a/tests/StatsTest.php +++ b/tests/StatsTest.php @@ -6,15 +6,15 @@ // load functions require_once dirname(__DIR__, 1) . "/vendor/autoload.php"; -require_once "src/stats.php"; +require_once "api/stats.php"; // load .env $dotenv = \Dotenv\Dotenv::createImmutable(dirname(__DIR__, 1)); $dotenv->safeLoad(); // if environment variables are not loaded, display error -if (!isset($_SERVER["TOKEN"])) { - $message = file_exists(dirname(__DIR__ . "../.env", 1)) +if (!isset($_ENV["TOKEN"])) { + $message = file_exists(dirname(__DIR__, 1) . "/.env") ? "Missing token in config. Check Contributing.md for details." : ".env was not found. Check Contributing.md for details."; diff --git a/tests/TranslationsTest.php b/tests/TranslationsTest.php index d8937b18..a2b6dbf6 100644 --- a/tests/TranslationsTest.php +++ b/tests/TranslationsTest.php @@ -14,7 +14,7 @@ final class TranslationsTest extends TestCase */ public function testAllPhrasesValid(): void { - $translations = include "src/translations.php"; + $translations = include "api/translations.php"; $locales = array_keys($translations); $valid_phrases = [ "rtl", @@ -47,7 +47,7 @@ public function testAllPhrasesValid(): void */ public function testLocalesSortedAlphabetically(): void { - $translations = include "src/translations.php"; + $translations = include "api/translations.php"; $locales = array_keys($translations); // check that "en" is first $this->assertEquals("en", $locales[0]); @@ -68,7 +68,7 @@ public function testLocalesSortedAlphabetically(): void */ public function testKeysNormalized(): void { - $translations = include "src/translations.php"; + $translations = include "api/translations.php"; $locales = array_keys($translations); foreach ($locales as $locale) { // normalize locale code @@ -83,7 +83,7 @@ public function testKeysNormalized(): void */ public function testGetTranslations(): void { - $translations = include "src/translations.php"; + $translations = include "api/translations.php"; $en = $translations["en"]; // test alias $this->assertEquals($translations["zh_Hans"] + $en, getTranslations("zh"), "Alias not resolved"); diff --git a/vercel.json b/vercel.json new file mode 100644 index 00000000..e8bc8bf7 --- /dev/null +++ b/vercel.json @@ -0,0 +1,13 @@ +{ + "routes": [ + { "handle": "filesystem" }, + { "src": "/demo/?", "dest": "/api/demo/index.php" }, + { "src": "/demo/(.+)", "dest": "/api/demo/vercel-static.php" }, + { "src": "/", "dest": "/api/index.php" } + ], + "functions": { + "api/**/*": { + "runtime": "vercel-php@0.7.3" + } + } +} pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy