diff --git a/.github/workflows/publish-pages.yml b/.github/workflows/publish-pages.yml new file mode 100644 index 0000000..3057898 --- /dev/null +++ b/.github/workflows/publish-pages.yml @@ -0,0 +1,36 @@ +name: Build & Publish Wallpapers (GitHub Pages) + +on: + push: + branches: [main] + workflow_dispatch: + +permissions: + contents: write + +concurrency: + group: pages-publish + cancel-in-progress: true + +jobs: + build-and-publish: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup Node + uses: actions/setup-node@v4 + with: + node-version: 20 + + - name: Build bundle + run: node build-wallpapers.js + + - name: Publish to gh-pages + uses: peaceiris/actions-gh-pages@v4 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + publish_dir: dist + publish_branch: gh-pages + force_orphan: true diff --git a/build-wallpapers.js b/build-wallpapers.js new file mode 100644 index 0000000..2e774c4 --- /dev/null +++ b/build-wallpapers.js @@ -0,0 +1,27 @@ +const fs = require('fs'); +const path = require('path'); + +const OUT_DIR = path.join(__dirname, 'dist'); +fs.mkdirSync(OUT_DIR, { recursive: true }); + +const jsonsDir = path.join(__dirname, 'jsons'); +const wallpapersFile = path.join(OUT_DIR, 'wallpapers.json'); + +const wallpapersData = {}; + +const jsonFiles = fs.readdirSync(jsonsDir) + .filter(file => file.endsWith('.json')) + .sort(); + +const wallpapers = []; +for (const file of jsonFiles) { + const filePath = path.join(jsonsDir, file); + const data = JSON.parse(fs.readFileSync(filePath, 'utf8')); + wallpapers.push(data); +} + +wallpapersData.wallpapers = wallpapers; + +fs.writeFileSync(wallpapersFile, JSON.stringify(wallpapersData, null, 2) + '\n', 'utf8'); + +console.log(`Successfully merged ${wallpapers.length} wallpapers`); \ No newline at end of file