From 4c40b68061f55a67a5a60bac84b2075f71dc6168 Mon Sep 17 00:00:00 2001 From: Seania Date: Fri, 6 Jan 2023 22:51:14 +0900 Subject: [PATCH] fix some bugs and Improve the semantics of the controls --- package.json | 1 + pnpm-lock.yaml | 19 +++++++++++++++---- src/app.html | 7 ++++--- src/lib/components/Article.svelte | 16 ++++++++-------- src/lib/components/Nav.svelte | 19 ++++++++++--------- src/lib/notifications/client.ts | 2 +- src/lib/pusher/client.ts | 2 +- src/routes/+page.svelte | 1 + .../community/[id=integer]/+page.svelte | 2 +- .../[article=integer]/+page.svelte | 2 +- src/routes/user/$types.d.ts | 5 +++++ src/routes/user/+layout.server.ts | 11 +++++++++++ src/routes/user/+page.server.ts | 9 +++++++-- src/routes/user/+page.svelte | 2 +- static/css/BinggraeMelona.css | 4 +++- static/robots.txt | 2 ++ svelte.config.js | 1 + vite.config.js | 6 +++++- 18 files changed, 78 insertions(+), 33 deletions(-) create mode 100644 src/routes/user/$types.d.ts create mode 100644 src/routes/user/+layout.server.ts create mode 100644 static/robots.txt diff --git a/package.json b/package.json index b87c989..8486c88 100644 --- a/package.json +++ b/package.json @@ -115,6 +115,7 @@ "tlds": "^1.236.0", "unified": "^10.1.2", "uuid": "^9.0.0", + "vite-plugin-compression": "^0.5.1", "wysiwyg-editor-node-sdk": "^4.0.16", "youtube-player": "^5.5.2" } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 16b44ea..f04dae2 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -99,6 +99,7 @@ specifiers: unified: ^10.1.2 uuid: ^9.0.0 vite: ^4.0.1 + vite-plugin-compression: ^0.5.1 wysiwyg-editor-node-sdk: ^4.0.16 youtube-player: ^5.5.2 @@ -174,6 +175,7 @@ dependencies: tlds: 1.236.0 unified: 10.1.2 uuid: 9.0.0 + vite-plugin-compression: 0.5.1_vite@4.0.1 wysiwyg-editor-node-sdk: 4.0.16 youtube-player: 5.5.2 @@ -2200,7 +2202,6 @@ packages: engines: {node: '>=8'} dependencies: color-convert: 2.0.1 - dev: true /anymatch/3.1.2: resolution: {integrity: sha512-P43ePfOAIupkguHUycrc4qJ9kz8ZiuOUijaETwX7THt0Y/GNK7v0aa8rY816xWjZ7rJdA5XdMcpVFTKMq+RvWg==} @@ -2593,7 +2594,6 @@ packages: dependencies: ansi-styles: 4.3.0 supports-color: 7.2.0 - dev: true /character-entities-html4/2.1.0: resolution: {integrity: sha512-1v7fgQRj6hnSwFpq1Eu0ynr/CDEw0rXo2B61qXrLNdHZmPKgb7fqS1a2JwF0rISo9q77jDI8VMEHoApn8qDoZA==} @@ -3820,7 +3820,6 @@ packages: /has-flag/4.0.0: resolution: {integrity: sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==} engines: {node: '>=8'} - dev: true /has-property-descriptors/1.0.0: resolution: {integrity: sha512-62DVLZGoiEBDHQyqG4w9xCuZ7eJEwNmJRWw2VY84Oedb7WFcA27fiEVe8oUQx9hAUJ4ekurquucTGwsyO1XGdQ==} @@ -6209,7 +6208,6 @@ packages: engines: {node: '>=8'} dependencies: has-flag: 4.0.0 - dev: true /supports-preserve-symlinks-flag/1.0.0: resolution: {integrity: sha512-ot0WnXS9fgdkgIcePe6RHNk1WA8+muPa6cSjeR3V8K27q9BB1rTE3R1p7Hv0z1ZyAc8s6Vvv8DIyWf681MAt0w==} @@ -6700,6 +6698,19 @@ packages: vfile-message: 3.1.2 dev: false + /vite-plugin-compression/0.5.1_vite@4.0.1: + resolution: {integrity: sha512-5QJKBDc+gNYVqL/skgFAP81Yuzo9R+EAf19d+EtsMF/i8kFUpNi3J/H01QD3Oo8zBQn+NzoCIFkpPLynoOzaJg==} + peerDependencies: + vite: '>=2.0.0' + dependencies: + chalk: 4.1.2 + debug: 4.3.4 + fs-extra: 10.1.0 + vite: 4.0.1_sass@1.57.0 + transitivePeerDependencies: + - supports-color + dev: false + /vite/4.0.1_sass@1.57.0: resolution: {integrity: sha512-kZQPzbDau35iWOhy3CpkrRC7It+HIHtulAzBhMqzGHKRf/4+vmh8rPDDdv98SWQrFWo6//3ozwsRmwQIPZsK9g==} engines: {node: ^14.18.0 || >=16.0.0} diff --git a/src/app.html b/src/app.html index f41a10a..a979675 100644 --- a/src/app.html +++ b/src/app.html @@ -9,14 +9,15 @@ - + - %sveltekit.head% -%sveltekit.body% +
+ %sveltekit.body% +
diff --git a/src/lib/components/Article.svelte b/src/lib/components/Article.svelte index 0e1d1ca..4b5e085 100644 --- a/src/lib/components/Article.svelte +++ b/src/lib/components/Article.svelte @@ -224,23 +224,23 @@ {#if ($client?.user ?? data?.user)}
{#if ($client?.user ?? data?.user)?.uid !== article.author._key} - - - + {/if} {#if article.author._key === ($client?.user ?? data?.user)?.uid} - {/if} {#if article.author._key === ($client?.user ?? data?.user)?.uid || ($client?.user ?? data?.user)?.rank >= EUserRanks.Manager} - + {/if} {#if ($client?.user ?? data?.user)?.rank >= EUserRanks.Manager} - + {/if} @@ -261,7 +261,7 @@
-
+
{article.author?.id} diff --git a/src/lib/components/Nav.svelte b/src/lib/components/Nav.svelte index 5674ce3..166188f 100644 --- a/src/lib/components/Nav.svelte +++ b/src/lib/components/Nav.svelte @@ -166,25 +166,26 @@ {#if showSearch}
  • - - +
  • {/if}
  • - - - +
  • {#if $client?.user && $client.user.rank > EUserRanks.User}
  • - @@ -198,7 +199,7 @@
  • {:else}
  • - diff --git a/src/lib/notifications/client.ts b/src/lib/notifications/client.ts index 59788d8..5a62c1d 100644 --- a/src/lib/notifications/client.ts +++ b/src/lib/notifications/client.ts @@ -13,7 +13,7 @@ export class NotificationsClient { static init(uid: string, preloaded: IPublicNotify[] = []) { if (!this.isUnloadEventRegistered) { this.isUnloadEventRegistered = true; - window.addEventListener('unload', () => this.pusher.close()); + window.addEventListener('pagehide', () => this.pusher.close()); } if (this.pusher) { this.pusher.close(); diff --git a/src/lib/pusher/client.ts b/src/lib/pusher/client.ts index e8da2dc..4754244 100644 --- a/src/lib/pusher/client.ts +++ b/src/lib/pusher/client.ts @@ -28,7 +28,7 @@ export class Pusher { constructor(context: string) { this.target = context; if (window) { - window.addEventListener('unload', this.close); + window.addEventListener('pagehide', this.close); window.addEventListener('online', this.online, true); window.addEventListener('offline', this.offline, true); // @ts-ignore diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index 541ee5b..c9197de 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -3,6 +3,7 @@ 루헨 - 홈 +
    { + // console.log('user/+layout.server.ts:', !locals.user); + if (!locals.user) { + // @ts-ignore + throw redirect(HttpStatus.MOVED_TEMPORARILY, '/login'); + } +} \ No newline at end of file diff --git a/src/routes/user/+page.server.ts b/src/routes/user/+page.server.ts index 9682919..9c56ea5 100644 --- a/src/routes/user/+page.server.ts +++ b/src/routes/user/+page.server.ts @@ -1,10 +1,15 @@ import type {ServerLoadEvent} from '@sveltejs/kit'; import {redirect} from '$lib/kit'; import HttpStatus from 'http-status-codes'; +import {User} from '$lib/auth/user/server'; export async function load({locals}: ServerLoadEvent): Promise { - console.log('user/+page.server.ts:', !locals.user); - if (!locals.user) { + if (!locals || !locals.user) { + // @ts-ignore throw redirect(HttpStatus.MOVED_TEMPORARILY, '/login'); } + const id = locals.user.sub.split('/')[1]!; + const user = new User(id); + const isAdult = await user.isAdult(); + return {isAdult}; } \ No newline at end of file diff --git a/src/routes/user/+page.svelte b/src/routes/user/+page.svelte index fd2f492..112ae37 100644 --- a/src/routes/user/+page.svelte +++ b/src/routes/user/+page.svelte @@ -31,7 +31,7 @@ href="/user/profile/edit"> 내 프로필 수정 - {#if !$client?.user.adult || !data?.user?.adult} + {#if !data.isAdult} diff --git a/static/css/BinggraeMelona.css b/static/css/BinggraeMelona.css index 3333d79..0ff0dc9 100644 --- a/static/css/BinggraeMelona.css +++ b/static/css/BinggraeMelona.css @@ -3,10 +3,12 @@ src: url('https://s3.ru.hn/fonts/BinggraeMelona.woff2') format('woff2'); font-weight: normal; font-style: normal; + font-display: swap; } @font-face { font-family: 'BinggraeMelona'; /* 'Tanugo'; */ - src: url("https://s3.ru.hn/fonts/umeboshi_.woff2") format('woff2'); + src: url('https://s3.ru.hn/fonts/umeboshi_.woff2') format('woff2'); unicode-range: U+4e00-9fbf, U+3040-309f, U+30A0-30FF; + font-display: swap; } \ No newline at end of file diff --git a/static/robots.txt b/static/robots.txt new file mode 100644 index 0000000..14267e9 --- /dev/null +++ b/static/robots.txt @@ -0,0 +1,2 @@ +User-agent: * +Allow: / \ No newline at end of file diff --git a/svelte.config.js b/svelte.config.js index d00d23b..c90938d 100644 --- a/svelte.config.js +++ b/svelte.config.js @@ -13,6 +13,7 @@ const config = { kit: { adapter: adapter({ out: './build', + precompress: true, }), alias: { '@root': path.resolve('./src'), diff --git a/vite.config.js b/vite.config.js index f7ea16b..61173c5 100644 --- a/vite.config.js +++ b/vite.config.js @@ -1,9 +1,13 @@ // vite.config.js import {sveltekit} from '@sveltejs/kit/vite'; +import compression from 'vite-plugin-compression'; /** @type {import('vite').UserConfig} */ const config = { - plugins: [sveltekit()], + plugins: [ + sveltekit(), + compression({algorithm: 'brotliCompress'}) + ], }; export default config; \ No newline at end of file