Dynamic manifest.json and move projects under project/

This commit is contained in:
Brieuc Dubois 2024-01-10 14:22:43 +01:00
parent c8edc250a1
commit b6e36fdf00
4 changed files with 48 additions and 2 deletions

View File

@ -6,6 +6,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="stylesheet" type="text/css" href="/css/global.css" />
<title>Focus.</title>
<link rel="manifest" href="/manifest.json" />
%sveltekit.head%
</head>
<body data-sveltekit-preload-data="hover">

View File

@ -40,10 +40,10 @@
{:else}
<div
class="title"
on:click={() => (location.href = `/${project.id}`)}
on:click={() => (location.href = `/project/${project.id}`)}
on:keydown={(e) => {
if (e.key === 'Enter') {
location.href = `/${project.id}`;
location.href = `/project/${project.id}`;
}
}}
tabindex="0"

View File

@ -0,0 +1,45 @@
import projectsApi from '$lib/api/projectsApi';
interface Shortcut {
name: string;
description: string;
url: string;
icons: {
src: string;
sizes: string;
}[];
}
export async function GET() {
const icon = {
src: '/img/icon.svg',
type: 'image/svg+xml',
sizes: 'any'
};
const projects = await projectsApi.getAll();
const shortcuts: Shortcut[] = projects.map((project) => {
return {
name: `Project ${project.title}`,
description: `Shortcut for project ${project.title}`,
url: `/${project.id}`,
icons: [icon]
};
});
const manifest = {
short_name: 'Focus',
name: 'Focus',
start_url: '/',
display: 'standalone',
icons: [icon],
shortcuts
};
return new Response(JSON.stringify(manifest), {
headers: {
'Content-Type': 'application/manifest+json'
}
});
}