Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions PR_DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Fix: Sitemap Not Updating in CI/CD

## 🐛 The Problem

The user reported that `sitemap.xml` was buggy or not being read correctly by Google Search Console.
Upon investigation, it was found that the deployed `sitemap.xml` might be stale or not reflecting the latest routes because the generation script was not running during the automated deployment.

## 🔍 Root Cause Analysis

In `package.json`, the build script is defined as:

```json
"build": "npm run generate:sitemap && next build"
```

This script ensures that the sitemap is regenerated **before** the Next.js build occurs.

However, the GitHub Actions workflow (`.github/workflows/release.yml`) was explicitly running:

```yaml
run: npx next build
```

By running `next build` directly via `npx`, the CI pipeline was **bypassing** the `npm run generate:sitemap` step defined in `package.json`. Consequently, the sitemap in the `out/` directory was either missing, stale, or relying on a previously committed version.

## 🛠 The Solution

I have updated the `.github/workflows/release.yml` file to use the project's defined build script instead of the default Next.js command.

**Change:**

```diff
- run: npx next build
+ run: npm run build
```

## ✅ Verification Steps

To verify this fix:

1. **Merge** this pull request.
2. Go to the **Actions** tab in GitHub.
3. Open the running **Release and Build** workflow.
4. Click on the **build** step.
5. Verify that you see the output `✅ Sitemap generated...` in the logs before the Next.js build starts.
6. Once deployed, check `https://physicshub.github.io/sitemap.xml` to ensure it matches the latest content.
11 changes: 11 additions & 0 deletions check-local-sitemap.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

const http = require('http');

const url = 'http://localhost:8000/sitemap.xml';

http.get(url, (res) => {
console.log('StatusCode:', res.statusCode);
console.log('Headers:', res.headers);
}).on('error', (e) => {
console.error(e);
});
21 changes: 21 additions & 0 deletions check-sitemap.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

const https = require('https');

const url = 'https://physicshub.github.io/sitemap.xml';

https.get(url, (res) => {
console.log('StatusCode:', res.statusCode);
console.log('Headers:', res.headers);

let data = '';
res.on('data', (chunk) => {
data += chunk;
});

res.on('end', () => {
console.log('Body snippet:', data.substring(0, 200));
});

}).on('error', (e) => {
console.error(e);
});
7 changes: 7 additions & 0 deletions fetch-robots.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

const https = require('https');

https.get('https://physicshub.github.io/robots.txt', (res) => {
console.log('StatusCode:', res.statusCode);
res.pipe(process.stdout);
});
103 changes: 103 additions & 0 deletions sitemap_live.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:news="http://www.google.com/schemas/sitemap-news/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" xmlns:video="http://www.google.com/schemas/sitemap-video/1.1">
<url>
<loc>https://physicshub.github.io/</loc>
<changefreq>weekly</changefreq>
<priority>1.0</priority>
</url>
<url>
<loc>https://physicshub.github.io/contribute</loc>
<changefreq>monthly</changefreq>
<priority>0.8</priority>
</url>
<url>
<loc>https://physicshub.github.io/simulations</loc>
<changefreq>weekly</changefreq>
<priority>0.9</priority>
</url>
<url>
<loc>https://physicshub.github.io/about</loc>
<changefreq>monthly</changefreq>
<priority>0.7</priority>
</url>
<url>
<loc>https://physicshub.github.io/blog</loc>
<changefreq>weekly</changefreq>
<priority>0.9</priority>
</url>
<url>
<loc>https://physicshub.github.io/blog/create</loc>
<changefreq>monthly</changefreq>
<priority>0.7</priority>
</url>
<url>
<loc>https://physicshub.github.io/simulations/BouncingBall</loc>
<changefreq>weekly</changefreq>
<priority>0.7</priority>
</url>
<url>
<loc>https://physicshub.github.io/simulations/VectorsOperations</loc>
<changefreq>weekly</changefreq>
<priority>0.7</priority>
</url>
<url>
<loc>https://physicshub.github.io/simulations/BallAcceleration</loc>
<changefreq>weekly</changefreq>
<priority>0.7</priority>
</url>
<url>
<loc>https://physicshub.github.io/simulations/BallGravity</loc>
<changefreq>weekly</changefreq>
<priority>0.7</priority>
</url>
<url>
<loc>https://physicshub.github.io/simulations/SpringConnection</loc>
<changefreq>weekly</changefreq>
<priority>0.7</priority>
</url>
<url>
<loc>https://physicshub.github.io/simulations/SimplePendulum</loc>
<changefreq>weekly</changefreq>
<priority>0.7</priority>
</url>
<url>
<loc>https://physicshub.github.io/simulations/ParabolicMotion</loc>
<changefreq>weekly</changefreq>
<priority>0.7</priority>
</url>
<url>
<loc>https://physicshub.github.io/blog/physics-bouncing-ball-comprehensive-educational-guide</loc>
<changefreq>monthly</changefreq>
<priority>0.8</priority>
</url>
<url>
<loc>https://physicshub.github.io/blog/comprehensive-guide-to-vector-operations</loc>
<changefreq>monthly</changefreq>
<priority>0.8</priority>
</url>
<url>
<loc>https://physicshub.github.io/blog/ball-uniformly-accelerated-motion</loc>
<changefreq>monthly</changefreq>
<priority>0.8</priority>
</url>
<url>
<loc>https://physicshub.github.io/blog/ball-free-fall-comprehensive-guide</loc>
<changefreq>monthly</changefreq>
<priority>0.8</priority>
</url>
<url>
<loc>https://physicshub.github.io/blog/spring-connection</loc>
<changefreq>monthly</changefreq>
<priority>0.8</priority>
</url>
<url>
<loc>https://physicshub.github.io/blog/pendulum-motion</loc>
<changefreq>monthly</changefreq>
<priority>0.8</priority>
</url>
<url>
<loc>https://physicshub.github.io/blog/projectile-parabolic-motion</loc>
<changefreq>monthly</changefreq>
<priority>0.8</priority>
</url>
</urlset>
22 changes: 22 additions & 0 deletions validate-xml.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

const fs = require('fs');
const { XMLValidator } = require('fast-xml-parser');

try {
const xmlData = fs.readFileSync('sitemap_live.xml', 'utf8');

// Check for leading whitespace
if (xmlData.trimStart() !== xmlData) {
console.log("WARNING: Found leading whitespace/newlines!");
}

// Validate
const result = XMLValidator.validate(xmlData);
if (result === true) {
console.log("XML is Valid");
} else {
console.log("XML Invalid:", result);
}
} catch (err) {
console.error("Error reading file:", err);
}
Loading