svelte-migrate: updated files

This commit is contained in:
Maxime Cannoodt
2022-11-13 13:56:17 +01:00
parent 52bcb9974b
commit 308fffbefe
20 changed files with 70 additions and 106 deletions

View File

@@ -19,7 +19,7 @@
},
"devDependencies": {
"@sveltejs/adapter-auto": "next",
"@sveltejs/kit": "^1.0.0-next.350",
"@sveltejs/kit": "^1.0.0-next.544",
"@tailwindcss/typography": "^0.5.2",
"@testing-library/jest-dom": "^5.16.4",
"@testing-library/svelte": "^3.1.3",

2
webapp/pnpm-lock.yaml generated
View File

@@ -3,7 +3,7 @@ lockfileVersion: 5.4
specifiers:
'@sveltejs/adapter-auto': next
'@sveltejs/adapter-node': ^1.0.0-next.78
'@sveltejs/kit': ^1.0.0-next.350
'@sveltejs/kit': ^1.0.0-next.544
'@tailwindcss/typography': ^0.5.2
'@testing-library/jest-dom': ^5.16.4
'@testing-library/svelte': ^3.1.3

View File

@@ -1,42 +1,21 @@
<script context="module" lang="ts">
import type { Load } from '@sveltejs/kit';
export const load: Load = ({ error, status }) => {
let explainText = '';
let title = '';
if (status == 404) {
title = `404: No note found 🕵️`;
explainText = `No note was found at this link. Are you from the future?`;
}
if (status == 410) {
title = '📝💨 This note is no longer here! ';
explainText = `Notes are stored for a limited amount of time. The note at this link was either set to expire, or deleted due to inactivity. Sorry!`;
}
return {
props: {
status: status,
title: title,
explainText: explainText
}
};
};
</script>
<script lang="ts">
export let status: number;
export let title: string;
export let explainText: string;
import { page } from '$app/stores';
</script>
<div class="prose max-w-2xl prose-zinc dark:prose-invert">
<h1>{title}</h1>
<p class="prose-xl">{explainText}</p>
{#if $page.status === 404}
<h1>404: No note found 🕵️</h1>
<p class="prose-xl">No note was found at this link. Are you from the future?</p>
{:else if $page.status === 410}
<h1>📝💨 This note is no longer here!</h1>
<p class="prose-xl">
Notes are stored for a limited amount of time. The note at this link was either set to expire,
or deleted due to inactivity. Sorry!
</p>
{/if}
<div class="not-prose w-full flex justify-center mt-16">
{#if status == 404 || status == 410}
{#if $page.status === 404 || $page.status === 410}
<img src="/expired_note.svg" alt="encrypted-art" class="w-80" />
{/if}
</div>

View File

@@ -0,0 +1,2 @@
// try making this false to prevent LinkedIn crawler returning 416
export const prerender = false;

View File

@@ -1,8 +1,3 @@
<script context="module">
// try making this false to prevent LinkedIn crawler returning 416
export const prerender = false;
</script>
<script>
import Tile from '$lib/components/index/tile.svelte';
</script>

View File

@@ -0,0 +1 @@
export const prerender = true;

View File

@@ -1,7 +1,3 @@
<script context="module">
export const prerender = true;
</script>
<svelte:head>
<title>About | {import.meta.env.VITE_BRANDING}</title>
</svelte:head>

View File

@@ -1,8 +1,5 @@
<script context="module" lang="ts">
export const prerender = true;
// @ts-expect-error - Markdown files are not recognized by Svelte
import { toc, html } from '/CHANGELOG.md';
<script lang="ts">
export let html: string;
</script>
<div class="md:py-8 prose prose-md max-w-3xl dark:prose-invert">

View File

@@ -0,0 +1,8 @@
export const prerender = true;
// @ts-expect-error - Markdown files are not recognized by Vite
import { html } from '/CHANGELOG.md';
export function load() {
return { html };
}

View File

@@ -0,0 +1 @@
export const prerender = true;

View File

@@ -1,7 +1,3 @@
<script context="module">
export const prerender = true;
</script>
<svelte:head>
<title>Contact | {import.meta.env.VITE_BRANDING}</title>
</svelte:head>

View File

@@ -1,8 +1,5 @@
<script context="module" lang="ts">
export const prerender = true;
// @ts-expect-error - Markdown files are not recognized by Svelte
import { toc, html } from './funding.md';
<script lang="ts">
export let html: string;
</script>
<div class="md:py-8 prose prose-md max-w-3xl dark:prose-invert">

View File

@@ -0,0 +1,8 @@
export const prerender = true;
// @ts-expect-error - Markdown files are not recognized by Svelte
import { html } from '../funding.md';
export function load() {
return { html };
}

View File

@@ -0,0 +1 @@
export const prerender = true;

View File

@@ -1,7 +1,3 @@
<script context="module">
export const prerender = true;
</script>
<svelte:head>
<title>Get the plugin | {import.meta.env.VITE_BRANDING}</title>
<script src="https://tarptaeya.github.io/repo-card/repo-card.js"></script>

View File

@@ -1,7 +1,9 @@
import type { EncryptedNote } from '$lib/model/EncryptedNote';
import type { RequestHandler } from '@sveltejs/kit';
import type { PageServerLoad } from './$types';
export const get: RequestHandler = async ({ request, clientAddress, params }) => {
import { error } from '@sveltejs/kit';
export const get: PageServerLoad = async ({ request, clientAddress, params, setHeaders }) => {
const ip = (request.headers.get('x-forwarded-for') || clientAddress) as string;
const url = `${import.meta.env.VITE_SERVER_INTERNAL}/api/note/${params.id}`;
const response = await fetch(url, {
@@ -16,27 +18,16 @@ export const get: RequestHandler = async ({ request, clientAddress, params }) =>
note.insert_time = new Date(note.insert_time as unknown as string);
note.expire_time = new Date(note.expire_time as unknown as string);
const maxage = Math.floor((note.expire_time.valueOf() - note.insert_time.valueOf()) / 1000);
return {
status: response.status,
headers: {
'Cache-Control': `public, max-age=${maxage}`
},
cache: {
maxage: maxage,
private: false
},
body: { note }
};
setHeaders({
maxage: maxage,
'Cache-Control': `max-age=${maxage}, public`
});
return { note };
} catch {
return {
status: 500,
error: response.statusText
};
error(500, response.statusText);
}
} else {
return {
status: response.status,
error: response.statusText
};
error(response.status, response.statusText);
}
};

View File

@@ -1,34 +1,19 @@
<script context="module" , lang="ts">
import type { Load } from '@sveltejs/kit';
export const load: Load = async ({ props }) => {
const note: EncryptedNote = props.note;
const maxage = Math.floor((note.expire_time.valueOf() - note.insert_time.valueOf()) / 1000);
return {
status: 200,
cache: {
maxage: maxage,
private: false
},
props: { note }
};
};
</script>
<script lang="ts">
import { onMount } from 'svelte';
import { decrypt } from '$lib/crypto/decrypt';
import MarkdownRenderer from '$lib/components/MarkdownRenderer.svelte';
import LogoMarkdown from 'svelte-icons/io/IoLogoMarkdown.svelte';
import IconEncrypted from 'svelte-icons/md/MdLockOutline.svelte';
import type { EncryptedNote } from '$lib/model/EncryptedNote';
import { browser } from '$app/env';
import RawRenderer from '$lib/components/RawRenderer.svelte';
import LogoDocument from 'svelte-icons/md/MdUndo.svelte';
import Dismissable from '$lib/components/Dismissable.svelte';
// Auto-loaded from [id].ts endpoint
export let note: EncryptedNote;
/** @type {import('./$types').PageData} */
export let data;
let { note } = data;
let plaintext: string;
let timeString: string;
let decryptFailed = false;

View File

@@ -0,0 +1,14 @@
import type { EncryptedNote } from '$lib/model/EncryptedNote';
import type { PageLoad } from './$types';
export const load: PageLoad = async ({ data, setHeaders }) => {
const note: EncryptedNote = data.note;
const maxage = Math.floor((note.expire_time.valueOf() - note.insert_time.valueOf()) / 1000);
setHeaders({
maxage: maxage,
'Cache-Control': `max-age=${maxage}, public`
});
return { note };
};

View File

@@ -0,0 +1 @@
export const prerender = true;

View File

@@ -1,7 +1,3 @@
<script context="module">
export const prerender = true;
</script>
<svelte:head>
<title>Roadmap | {import.meta.env.VITE_BRANDING}</title>
</svelte:head>