|
1 | 1 | import { fileURLToPath, URL } from 'node:url' |
2 | | - |
3 | 2 | import { defineConfig } from 'vite' |
4 | 3 | 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] |
5 | 46 |
|
6 | | -// https://vitejs.dev/config/ |
7 | 47 | export default defineConfig({ |
8 | 48 | plugins: [ |
9 | 49 | 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 | + }) |
10 | 56 | ], |
11 | 57 | resolve: { |
12 | 58 | alias: { |
|
0 commit comments