mirror of
https://github.com/catdevnull/transicion-desordenada-diablo
synced 2024-11-15 02:21:39 +00:00
frontend: generar titulo de página
This commit is contained in:
parent
2ac17883a9
commit
c9347b583b
2 changed files with 19 additions and 7 deletions
|
@ -1,7 +1,7 @@
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { inject } from "regexparam";
|
import { inject } from "regexparam";
|
||||||
import ChevronRight from "eva-icons/outline/svg/chevron-right-outline.svg?component";
|
import ChevronRight from "eva-icons/outline/svg/chevron-right-outline.svg?component";
|
||||||
import { routes } from "../router";
|
import { generateDumpName, routes } from "../router";
|
||||||
import Portal from "../routes/Portal.svelte";
|
import Portal from "../routes/Portal.svelte";
|
||||||
|
|
||||||
export let params:
|
export let params:
|
||||||
|
@ -9,11 +9,6 @@
|
||||||
| { dumpUrl: string; portal: string }
|
| { dumpUrl: string; portal: string }
|
||||||
| { dumpUrl: string; portal: string; id: string };
|
| { dumpUrl: string; portal: string; id: string };
|
||||||
|
|
||||||
function generateDumpName(dumpUrl: string) {
|
|
||||||
const clean = decodeURIComponent(dumpUrl).replace(/\/+$/, "");
|
|
||||||
return clean.slice(clean.lastIndexOf("/") + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
$: dumpName = generateDumpName(params.dumpUrl);
|
$: dumpName = generateDumpName(params.dumpUrl);
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
|
@ -8,13 +8,30 @@ export const routes = {
|
||||||
Dataset: "/dump/:dumpUrl/:portal/dataset/:id",
|
Dataset: "/dump/:dumpUrl/:portal/dataset/:id",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export function generateDumpName(dumpUrl: string) {
|
||||||
|
const clean = decodeURIComponent(dumpUrl).replace(/\/+$/, "");
|
||||||
|
return clean.slice(clean.lastIndexOf("/") + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
const title = "Archivo de portales de datos de Argentina";
|
||||||
|
const titles: { [key in ComponentType]: (params: Params) => string } = {
|
||||||
|
Home: () => title,
|
||||||
|
NotFound: () => title,
|
||||||
|
Dump: (params) => `${generateDumpName(params.dumpUrl)} - ${title}`,
|
||||||
|
Portal: (params) => `${params.portal} - ${title}`,
|
||||||
|
Dataset: (params) => `${params.id} - ${title}`,
|
||||||
|
};
|
||||||
|
|
||||||
export type ComponentType = "NotFound" | keyof typeof routes;
|
export type ComponentType = "NotFound" | keyof typeof routes;
|
||||||
|
|
||||||
type Route = {
|
type Route = {
|
||||||
component: ComponentType;
|
component: ComponentType;
|
||||||
params?: Params;
|
params?: Params;
|
||||||
};
|
};
|
||||||
export const currentRoute = writable<Route>();
|
export const currentRoute = writable<Route>({ component: "Home" });
|
||||||
|
currentRoute.subscribe(
|
||||||
|
(route) => (document.title = titles[route.component](route.params!)),
|
||||||
|
);
|
||||||
|
|
||||||
export const router = navaid(undefined, () =>
|
export const router = navaid(undefined, () =>
|
||||||
currentRoute.set({ component: "NotFound" }),
|
currentRoute.set({ component: "NotFound" }),
|
||||||
|
|
Loading…
Reference in a new issue