Skip to content

Commit 1bdde1d

Browse files
authored
Merge pull request #285 from SmartAPI/fix-sitemap
fix: 🔨 generate sitemap dynamically
2 parents 0a34aab + e63ba74 commit 1bdde1d

File tree

4 files changed

+63
-4
lines changed

4 files changed

+63
-4
lines changed

web-app/package-lock.json

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

web-app/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"type": "module",
23
"name": "vite-app ready",
34
"version": "0.0.0",
45
"private": true,
@@ -60,6 +61,7 @@
6061
"prettier": "^3.0.3",
6162
"start-server-and-test": "^2.0.1",
6263
"vite": "^4.4.11",
64+
"vite-plugin-sitemap": "^0.7.1",
6365
"vitest": "^0.34.6"
6466
}
6567
}

web-app/public/robots.txt

Lines changed: 0 additions & 2 deletions
This file was deleted.

web-app/vite.config.js

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,58 @@
11
import { fileURLToPath, URL } from 'node:url'
2-
32
import { defineConfig } from 'vite'
43
import vue from '@vitejs/plugin-vue'
4+
import Sitemap from 'vite-plugin-sitemap'
5+
import axios from 'axios'
6+
7+
// Static routes
8+
const staticRoutes = [
9+
'/',
10+
'/about',
11+
'/faq',
12+
'/privacy',
13+
'/branding',
14+
'/guide',
15+
'/dashboard',
16+
'/extensions/smartapi',
17+
'/extensions/x-bte',
18+
'/extensions/x-translator?',
19+
'/registry',
20+
'/registry/translator',
21+
'/documentation/getting-started',
22+
'/documentation/smartapi-extensions',
23+
'/documentation/openapi-specification',
24+
'/ui', // For routes like /ui/:smartapi_id
25+
'/editor',
26+
]
27+
28+
// Fetch dynamic slugs asynchronously
29+
async function fetchDynamicRoutes() {
30+
try {
31+
const response = await axios.get('https://smart-api.info/api/query?&q=__all__&fields=_id&size=1000&raw=1')
32+
const dynamicRoutes = response.data.hits.map(item => `/ui/${item._id}`) // Only return URLs as strings
33+
console.log('Fetched dynamic routes:', dynamicRoutes) // Log the dynamic routes
34+
return dynamicRoutes
35+
} catch (error) {
36+
console.error('Error fetching dynamic routes:', error)
37+
return [] // Return an empty array in case of error
38+
}
39+
}
40+
41+
// Fetch dynamic routes before config execution
42+
const routes = await fetchDynamicRoutes()
43+
44+
// Combine static and dynamic routes
45+
const dynamicRoutes = [...staticRoutes, ...routes]
546

6-
// https://vitejs.dev/config/
747
export default defineConfig({
848
plugins: [
949
vue(),
50+
Sitemap({
51+
hostname: 'https://www.smart-api.info',
52+
readable: true,
53+
changefreq: 'monthly',
54+
dynamicRoutes // Provide the combined routes as an array of strings
55+
})
1056
],
1157
resolve: {
1258
alias: {

0 commit comments

Comments
 (0)