diff --git a/web-app/package-lock.json b/web-app/package-lock.json index 4bd8be53..08f0f84b 100644 --- a/web-app/package-lock.json +++ b/web-app/package-lock.json @@ -55,6 +55,7 @@ "prettier": "^3.0.3", "start-server-and-test": "^2.0.1", "vite": "^4.4.11", + "vite-plugin-sitemap": "^0.7.1", "vitest": "^0.34.6" } }, @@ -10014,6 +10015,12 @@ "url": "https://opencollective.com/vitest" } }, + "node_modules/vite-plugin-sitemap": { + "version": "0.7.1", + "resolved": "https://registry.npmjs.org/vite-plugin-sitemap/-/vite-plugin-sitemap-0.7.1.tgz", + "integrity": "sha512-4NRTkiWytLuAmcikckrLcLl9iYA20+5v6l8XshcOrzxH1WR8H0O3S6sTQYfjMrE8su/LG6Y0cTodvOdcOIxaLw==", + "dev": true + }, "node_modules/vite/node_modules/rollup": { "version": "3.29.4", "resolved": "https://registry.npmjs.org/rollup/-/rollup-3.29.4.tgz", @@ -18141,6 +18148,12 @@ "vite": "^3.0.0 || ^4.0.0 || ^5.0.0-0" } }, + "vite-plugin-sitemap": { + "version": "0.7.1", + "resolved": "https://registry.npmjs.org/vite-plugin-sitemap/-/vite-plugin-sitemap-0.7.1.tgz", + "integrity": "sha512-4NRTkiWytLuAmcikckrLcLl9iYA20+5v6l8XshcOrzxH1WR8H0O3S6sTQYfjMrE8su/LG6Y0cTodvOdcOIxaLw==", + "dev": true + }, "vitest": { "version": "0.34.6", "resolved": "https://registry.npmjs.org/vitest/-/vitest-0.34.6.tgz", diff --git a/web-app/package.json b/web-app/package.json index 1285913c..6d771cc3 100644 --- a/web-app/package.json +++ b/web-app/package.json @@ -1,4 +1,5 @@ { + "type": "module", "name": "vite-app ready", "version": "0.0.0", "private": true, @@ -60,6 +61,7 @@ "prettier": "^3.0.3", "start-server-and-test": "^2.0.1", "vite": "^4.4.11", + "vite-plugin-sitemap": "^0.7.1", "vitest": "^0.34.6" } } diff --git a/web-app/public/robots.txt b/web-app/public/robots.txt deleted file mode 100644 index eb053628..00000000 --- a/web-app/public/robots.txt +++ /dev/null @@ -1,2 +0,0 @@ -User-agent: * -Disallow: diff --git a/web-app/vite.config.js b/web-app/vite.config.js index 5c45e1d9..9ee6fdb4 100644 --- a/web-app/vite.config.js +++ b/web-app/vite.config.js @@ -1,12 +1,58 @@ import { fileURLToPath, URL } from 'node:url' - import { defineConfig } from 'vite' import vue from '@vitejs/plugin-vue' +import Sitemap from 'vite-plugin-sitemap' +import axios from 'axios' + +// Static routes +const staticRoutes = [ + '/', + '/about', + '/faq', + '/privacy', + '/branding', + '/guide', + '/dashboard', + '/extensions/smartapi', + '/extensions/x-bte', + '/extensions/x-translator?', + '/registry', + '/registry/translator', + '/documentation/getting-started', + '/documentation/smartapi-extensions', + '/documentation/openapi-specification', + '/ui', // For routes like /ui/:smartapi_id + '/editor', +] + +// Fetch dynamic slugs asynchronously +async function fetchDynamicRoutes() { + try { + const response = await axios.get('https://smart-api.info/api/query?&q=__all__&fields=_id&size=1000&raw=1') + const dynamicRoutes = response.data.hits.map(item => `/ui/${item._id}`) // Only return URLs as strings + console.log('Fetched dynamic routes:', dynamicRoutes) // Log the dynamic routes + return dynamicRoutes + } catch (error) { + console.error('Error fetching dynamic routes:', error) + return [] // Return an empty array in case of error + } +} + +// Fetch dynamic routes before config execution +const routes = await fetchDynamicRoutes() + +// Combine static and dynamic routes +const dynamicRoutes = [...staticRoutes, ...routes] -// https://vitejs.dev/config/ export default defineConfig({ plugins: [ vue(), + Sitemap({ + hostname: 'https://www.smart-api.info', + readable: true, + changefreq: 'monthly', + dynamicRoutes // Provide the combined routes as an array of strings + }) ], resolve: { alias: {