From 6fc92c067311c595a6bbcf9a3dd1ae89a73cf9de Mon Sep 17 00:00:00 2001 From: usernamenotfound Date: Sat, 31 Aug 2024 21:17:26 +0000 Subject: [PATCH] set base urls dynamically --- .github/workflows/static.yml | 15 +++++++++++++++ config.json | 3 --- index.js | 25 +++++++++++++------------ 3 files changed, 28 insertions(+), 15 deletions(-) delete mode 100644 config.json diff --git a/.github/workflows/static.yml b/.github/workflows/static.yml index 331eee7a..e0f5fcb1 100644 --- a/.github/workflows/static.yml +++ b/.github/workflows/static.yml @@ -35,8 +35,23 @@ jobs: uses: actions/setup-node@v2.5.2 with: node-version: 18.x + - name: Set Github Page Url Variable + id: get_page_url + run: | + if [ -f "CNAME" ]; then + DOMAIN=$(cat CNAME) + echo "Custom domain found: $DOMAIN" + else + DOMAIN="${{ github.repository_owner }}.github.io" + echo "No custom domain found. Using default domain: $DOMAIN" + fi + REPOSITORY_NAME="${{ github.event.repository.name }}" + FULL_URL="$DOMAIN/$REPOSITORY_NAME" + echo "::set-output name=url::$FULL_URL" - name: Build index run: node index.js + env: + GITHUB_PAGES_URL: ${{ steps.get_page_url.outputs.url }} - name: Setup Pages uses: actions/configure-pages@v3 - name: Upload artifact diff --git a/config.json b/config.json deleted file mode 100644 index 9cb99bc1..00000000 --- a/config.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "url": "https://azukaar.github.io/cosmos-servapps-official/servapps.json" -} \ No newline at end of file diff --git a/index.js b/index.js index 345061cc..be47d8b1 100644 --- a/index.js +++ b/index.js @@ -1,6 +1,7 @@ const fs = require('fs') -const { config } = require('process') -const configFile = require('./config.json') +const githubPagesUrl = `https://${process.env.GITHUB_PAGES_URL}` +const localhost = "http://localhost:3000" + // list all directories in the directory servapps and compile them in servapps.json @@ -17,24 +18,24 @@ for (const file of servapps) { // list all screenshots in the directory servapps/${file}/screenshots const screenshots = fs.readdirSync(`./servapps/${file}/screenshots`) for (const screenshot of screenshots) { - servapp.screenshots.push(`https://azukaar.github.io/cosmos-servapps-official/servapps/${file}/screenshots/${screenshot}`) + servapp.screenshots.push(`${githubPagesUrl}/servapps/${file}/screenshots/${screenshot}`) } if(fs.existsSync(`./servapps/${file}/artefacts`)) { const artefacts = fs.readdirSync(`./servapps/${file}/artefacts`) for(const artefact of artefacts) { - servapp.artefacts[artefact] = (`https://azukaar.github.io/cosmos-servapps-official/servapps/${file}/artefacts/${artefact}`) + servapp.artefacts[artefact] = (`${githubPagesUrl}/servapps/${file}/artefacts/${artefact}`) } } - servapp.icon = `https://azukaar.github.io/cosmos-servapps-official/servapps/${file}/icon.png` + servapp.icon = `${githubPagesUrl}/servapps/${file}/icon.png` //Common Format,used by most - const YMLComposeSource = `https://azukaar.github.io/cosmos-servapps-official/servapps/${file}/docker-compose.yml`; + const YMLComposeSource = `${githubPagesUrl}/servapps/${file}/docker-compose.yml`; if(fs.existsSync(`./servapps/${file}/docker-compose.yml`)) { servapp.compose = YMLComposeSource; } //Cosmos Legacy Format - const CosmosComposeSource = `https://azukaar.github.io/cosmos-servapps-official/servapps/${file}/cosmos-compose.json`; + const CosmosComposeSource = `${githubPagesUrl}/servapps/${file}/cosmos-compose.json`; if(fs.existsSync(`./servapps/${file}/cosmos-compose.json`)) { servapp.compose = CosmosComposeSource; } @@ -47,7 +48,7 @@ const _sc = ["Jellyfin", "Home Assistant", "Nextcloud"]; const showcases = servappsJSON.filter((app) => _sc.includes(app.name)); let apps = { - "source": configFile.url, + "source": `${githubPagesUrl}/servapps.json`, "showcase": showcases, "all": servappsJSON } @@ -56,13 +57,13 @@ fs.writeFileSync('./servapps.json', JSON.stringify(servappsJSON, null, 2)) fs.writeFileSync('./index.json', JSON.stringify(apps, null, 2)) for (const servapp of servappsJSON) { - servapp.compose = `http://localhost:3000/servapps/${servapp.id}/cosmos-compose.json` - servapp.icon = `http://localhost:3000/servapps/${servapp.id}/icon.png` + servapp.compose = `${localhost}/servapps/${servapp.id}/cosmos-compose.json` + servapp.icon = `${localhost}/servapps/${servapp.id}/icon.png` for (let i = 0; i < servapp.screenshots.length; i++) { - servapp.screenshots[i] = servapp.screenshots[i].replace('https://azukaar.github.io/cosmos-servapps-official', 'http://localhost:3000') + servapp.screenshots[i] = servapp.screenshots[i].replace('${githubPagesUrl}', '${localhost}') } for (const artefact in servapp.artefacts) { - servapp.artefacts[artefact] = servapp.artefacts[artefact].replace('https://azukaar.github.io/cosmos-servapps-official', 'http://localhost:3000') + servapp.artefacts[artefact] = servapp.artefacts[artefact].replace('${githubPagesUrl}', '${localhost}') } }