From 0f9faa45f070e634f40b38df48cdf2c5130ab398 Mon Sep 17 00:00:00 2001 From: Simon Cambier Date: Fri, 24 Nov 2023 18:15:30 +0100 Subject: [PATCH] Preview & editor --- src/app.html | 16 +-- src/components/EditForm.svelte | 122 +++++++++++++++++ src/components/TopBar.svelte | 128 +----------------- src/lib/utils.ts | 4 + src/routes/+layout.svelte | 2 +- src/routes/+page.svelte | 16 ++- src/routes/editor/+page.svelte | 70 +++++----- src/store.ts | 2 +- static/favicon.ico | Bin 1406 -> 4286 bytes static/favicon.svg | 1 + static/fonts/JetBrainsMono-Bold.woff2 | Bin 94588 -> 0 bytes static/fonts/JetBrainsMono-BoldItalic.woff2 | Bin 98152 -> 0 bytes static/fonts/JetBrainsMono-ExtraBold.woff2 | Bin 93692 -> 0 bytes .../fonts/JetBrainsMono-ExtraBoldItalic.woff2 | Bin 96864 -> 0 bytes static/fonts/JetBrainsMono-ExtraLight.woff2 | Bin 92712 -> 0 bytes .../JetBrainsMono-ExtraLightItalic.woff2 | Bin 95816 -> 0 bytes static/fonts/JetBrainsMono-Italic.woff2 | Bin 95864 -> 0 bytes static/fonts/JetBrainsMono-Light.woff2 | Bin 93856 -> 0 bytes static/fonts/JetBrainsMono-LightItalic.woff2 | Bin 97280 -> 0 bytes static/fonts/JetBrainsMono-Medium.woff2 | Bin 93824 -> 0 bytes static/fonts/JetBrainsMono-MediumItalic.woff2 | Bin 97808 -> 0 bytes static/fonts/JetBrainsMono-Regular.woff2 | Bin 92164 -> 0 bytes static/fonts/JetBrainsMono-SemiBold.woff2 | Bin 94472 -> 0 bytes .../fonts/JetBrainsMono-SemiBoldItalic.woff2 | Bin 98124 -> 0 bytes static/fonts/JetBrainsMono-Thin.woff2 | Bin 90612 -> 0 bytes static/fonts/JetBrainsMono-ThinItalic.woff2 | Bin 94316 -> 0 bytes static/fonts/hack-bold-subset.woff | Bin 0 -> 30212 bytes static/fonts/hack-bold-subset.woff2 | Bin 0 -> 23512 bytes static/fonts/hack-bolditalic-subset.woff | Bin 0 -> 33668 bytes static/fonts/hack-bolditalic-subset.woff2 | Bin 0 -> 26460 bytes static/fonts/hack-italic-subset.woff | Bin 0 -> 32648 bytes static/fonts/hack-italic-subset.woff2 | Bin 0 -> 25740 bytes static/fonts/hack-regular-subset.woff | Bin 0 -> 29640 bytes static/fonts/hack-regular-subset.woff2 | Bin 0 -> 23244 bytes static/hack-subset.css | 34 +++++ static/hack.css | 34 +++++ static/{fonts.css => jetbrainsmono.css} | 0 tailwind.config.js | 2 +- 38 files changed, 259 insertions(+), 172 deletions(-) create mode 100644 src/components/EditForm.svelte create mode 100644 static/favicon.svg delete mode 100644 static/fonts/JetBrainsMono-Bold.woff2 delete mode 100644 static/fonts/JetBrainsMono-BoldItalic.woff2 delete mode 100644 static/fonts/JetBrainsMono-ExtraBold.woff2 delete mode 100644 static/fonts/JetBrainsMono-ExtraBoldItalic.woff2 delete mode 100644 static/fonts/JetBrainsMono-ExtraLight.woff2 delete mode 100644 static/fonts/JetBrainsMono-ExtraLightItalic.woff2 delete mode 100644 static/fonts/JetBrainsMono-Italic.woff2 delete mode 100644 static/fonts/JetBrainsMono-Light.woff2 delete mode 100644 static/fonts/JetBrainsMono-LightItalic.woff2 delete mode 100644 static/fonts/JetBrainsMono-Medium.woff2 delete mode 100644 static/fonts/JetBrainsMono-MediumItalic.woff2 delete mode 100644 static/fonts/JetBrainsMono-Regular.woff2 delete mode 100644 static/fonts/JetBrainsMono-SemiBold.woff2 delete mode 100644 static/fonts/JetBrainsMono-SemiBoldItalic.woff2 delete mode 100644 static/fonts/JetBrainsMono-Thin.woff2 delete mode 100644 static/fonts/JetBrainsMono-ThinItalic.woff2 create mode 100644 static/fonts/hack-bold-subset.woff create mode 100644 static/fonts/hack-bold-subset.woff2 create mode 100644 static/fonts/hack-bolditalic-subset.woff create mode 100644 static/fonts/hack-bolditalic-subset.woff2 create mode 100644 static/fonts/hack-italic-subset.woff create mode 100644 static/fonts/hack-italic-subset.woff2 create mode 100644 static/fonts/hack-regular-subset.woff create mode 100644 static/fonts/hack-regular-subset.woff2 create mode 100644 static/hack-subset.css create mode 100644 static/hack.css rename static/{fonts.css => jetbrainsmono.css} (100%) diff --git a/src/app.html b/src/app.html index 5e866b0..c241b90 100644 --- a/src/app.html +++ b/src/app.html @@ -3,8 +3,8 @@ Paste - - + + %sveltekit.head% + +
%sveltekit.body%
- - diff --git a/src/components/EditForm.svelte b/src/components/EditForm.svelte new file mode 100644 index 0000000..cc79ce7 --- /dev/null +++ b/src/components/EditForm.svelte @@ -0,0 +1,122 @@ + + +
+ {#if isUrlInputVisible} +
+ + + +
+ {:else} +
+
+ +
+ + + + + + + + + + +
+ {/if} +
+ + diff --git a/src/components/TopBar.svelte b/src/components/TopBar.svelte index 5c33941..ea94954 100644 --- a/src/components/TopBar.svelte +++ b/src/components/TopBar.svelte @@ -1,135 +1,17 @@ - -

Paste

- About + About + Source
- - {#if isUrlInputVisible} -
- - - -
- {:else} -
-
- -
- -
- -
-
- {/if} +
- - diff --git a/src/lib/utils.ts b/src/lib/utils.ts index c98e3d9..ec930ae 100644 --- a/src/lib/utils.ts +++ b/src/lib/utils.ts @@ -28,4 +28,8 @@ export const shorten = (name: string) => { return n.substr(0, 2) + n.substr(n.length - 2, 2) } +export function getLangFromUrl() { + return new URLSearchParams(window.location.search).get('l') ?? 'plt' +} + export const byId = (id: string) => document.getElementById(id) diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte index 9fa1502..19dc1f4 100644 --- a/src/routes/+layout.svelte +++ b/src/routes/+layout.svelte @@ -2,4 +2,4 @@ import '../app.postcss' - + \ No newline at end of file diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index 52275bb..eb3a128 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -10,13 +10,16 @@ import rehypeStringify from 'rehype-stringify' import hljs from 'highlight.js' import 'highlight.js/styles/nord.min.css' + import TopBar from '../components/TopBar.svelte' + import Icon from '@iconify/svelte' + import { getLangFromUrl } from '$lib/utils' let decompressed: string let isMarkdown = false let isPlainText = false onMount(async () => { - let lang = new URLSearchParams(window.location.search).get('l') + let lang = getLangFromUrl() lang = lang === 'mrwn' || lang === 'gflm' ? 'md' : lang // back compatiblity with old links // extract the part in the url after the hash @@ -30,7 +33,7 @@ } // Markdown - if (lang === 'md' || lang === 'gflm') { + if (lang === 'md') { const html = await unified() .use(remarkParse) .use(remarkGfm) @@ -54,9 +57,18 @@ window.location.href = '/editor' } }) + + function getUrlDataPart(): string { + return window.location.search + window.location.hash + }
+ + + + +
{#if isMarkdown} {@html decompressed} diff --git a/src/routes/editor/+page.svelte b/src/routes/editor/+page.svelte index 1b5d74c..cf5681d 100644 --- a/src/routes/editor/+page.svelte +++ b/src/routes/editor/+page.svelte @@ -1,13 +1,12 @@ - + + + +
- + + +
@@ -98,13 +104,13 @@ ? '?' : Math.round(($shareUrl.length / charLen) * 100)}% of original)
-