Skip to content

Commit d3bd234

Browse files
Merge pull request #153 from appwrite/fix-sitemap
fix: sitemap
2 parents 185de58 + 5fd8c55 commit d3bd234

File tree

5 files changed

+72
-91
lines changed

5 files changed

+72
-91
lines changed

.github/workflows/tests.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: Tests
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v3
14+
- name: Use Node.js
15+
uses: actions/setup-node@v3
16+
with:
17+
node-version: 18
18+
- uses: pnpm/action-setup@v2
19+
name: Install pnpm
20+
with:
21+
version: 8
22+
run_install: false
23+
- name: Get pnpm store directory
24+
shell: bash
25+
run: |
26+
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
27+
28+
- uses: actions/cache@v3
29+
name: Setup pnpm cache
30+
with:
31+
path: ${{ env.STORE_PATH }}
32+
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
33+
restore-keys: |
34+
${{ runner.os }}-pnpm-store-
35+
- name: Install dependencies
36+
run: pnpm install --frozen-lockfile
37+
- name: Build Website
38+
env:
39+
NODE_OPTIONS: '--max_old_space_size=4096'
40+
run: pnpm run build

create_sitemap.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { writeFileSync } from 'fs';
2+
3+
const isVercel = process.env.VERCEL === '1';
4+
5+
if (isVercel) {
6+
console.log('Skipping sitemap.xml creation on Vercel preview.');
7+
process.exit(0);
8+
}
9+
10+
async function createSitemap() {
11+
console.log('Building sitemap.xml ...');
12+
const manifest = await import('./build/server/manifest.js');
13+
const prerendered = manifest.prerendered;
14+
15+
const sitemap = `<?xml version="1.0" encoding="UTF-8"?>
16+
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
17+
${[...prerendered].filter(route => !route.endsWith('.json')).map(route => `<url>
18+
<loc>https://appwrite.io${route}</loc>
19+
</url>
20+
`).join('')}
21+
</urlset>`;
22+
23+
writeFileSync('./build/sitemap.xml', sitemap, { encoding: 'utf8', flag: 'w' });
24+
console.log('sitemap.xml created successfully!');
25+
}
26+
27+
createSitemap();

package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
"scripts": {
66
"dev": "vite dev",
77
"build": "vite build",
8-
"postbuild": "svelte-sitemap --domain https://appwrite.io",
8+
"build:sitemap": "node create_sitemap.js",
9+
"postbuild": "pnpm build:sitemap",
910
"preview": "vite preview",
1011
"test": "npm run test:integration && npm run test:unit",
1112
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
@@ -26,7 +27,6 @@
2627
"@types/markdown-it": "^13.0.1",
2728
"@typescript-eslint/eslint-plugin": "^5.62.0",
2829
"@typescript-eslint/parser": "^5.62.0",
29-
"dotenv": "^16.3.1",
3030
"eslint": "^8.49.0",
3131
"eslint-config-prettier": "^8.10.0",
3232
"eslint-plugin-svelte": "^2.33.1",
@@ -39,7 +39,6 @@
3939
"svelte-check": "^3.5.1",
4040
"svelte-markdoc-preprocess": "^1.0.0",
4141
"svelte-sequential-preprocessor": "^2.0.1",
42-
"svelte-sitemap": "^2.6.0",
4342
"svgo": "^3.0.2",
4443
"svgtofont": "^4.0.0",
4544
"tslib": "^2.6.2",

pnpm-lock.yaml

Lines changed: 3 additions & 87 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

svelte.config.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import 'dotenv/config';
21
import { dirname, join } from 'path';
32
import { fileURLToPath } from 'url';
43
import { vitePreprocess } from '@sveltejs/kit/vite';

0 commit comments

Comments
 (0)