basic sitemap

This commit is contained in:
Anton Tranelis 2024-07-23 10:36:15 +02:00
parent 57b69b36ee
commit 546fde0bf6
3 changed files with 39 additions and 2 deletions

View File

@ -0,0 +1,36 @@
import { useEffect, useState } from 'react';
import { useItems } from '../Map/hooks/useItems';
export const Sitemap = ({url}:{url:string}) => {
const [sitemap, setSitemap] = useState('');
const items = useItems();
useEffect(() => {
if (items.length) {
const generateSitemap = () => {
let sitemapXML = `<?xml version="1.0" encoding="UTF-8"?>\n`;
sitemapXML += `<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">\n`;
items.forEach(item => {
sitemapXML += ` <url>\n`;
sitemapXML += ` <loc>${url}/${item.slug}</loc>\n`;
sitemapXML += ` </url>\n`;
});
sitemapXML += `</urlset>`;
return sitemapXML;
};
setSitemap(generateSitemap());
}
}, [items]);
return (
<div>
<h1>Sitemap</h1>
<textarea value={sitemap} readOnly rows={items.length + 4} cols={80} />
</div>
);
};

View File

@ -1,3 +1,4 @@
export {AppShell} from "./AppShell" export {AppShell} from "./AppShell"
export {SideBar} from "./SideBar" export {SideBar} from "./SideBar"
export {Content} from "./Content" export {Content} from "./Content"
export {Sitemap} from "./Sitemap"

View File

@ -1,5 +1,5 @@
export { UtopiaMap, Layer, Tags, Permissions, ItemForm, ItemView, PopupTextAreaInput, PopupStartEndInput, PopupTextInput, PopupButton, TextView, StartEndView, PopupCheckboxInput } from './Components/Map'; export { UtopiaMap, Layer, Tags, Permissions, ItemForm, ItemView, PopupTextAreaInput, PopupStartEndInput, PopupTextInput, PopupButton, TextView, StartEndView, PopupCheckboxInput } from './Components/Map';
export {AppShell, Content, SideBar} from "./Components/AppShell" export {AppShell, Content, SideBar, Sitemap } from "./Components/AppShell"
export {AuthProvider, useAuth, LoginPage, SignupPage, RequestPasswordPage, SetNewPasswordPage} from "./Components/Auth" export {AuthProvider, useAuth, LoginPage, SignupPage, RequestPasswordPage, SetNewPasswordPage} from "./Components/Auth"
export {UserSettings, ProfileSettings, OverlayProfile, OverlayProfileSettings, OverlayUserSettings, OverlayItemProfile, OverlayItemProfileSettings} from './Components/Profile' export {UserSettings, ProfileSettings, OverlayProfile, OverlayProfileSettings, OverlayUserSettings, OverlayItemProfile, OverlayItemProfileSettings} from './Components/Profile'
export {Quests, Modal} from './Components/Gaming' export {Quests, Modal} from './Components/Gaming'