Compare commits

...

4 Commits

6 changed files with 44 additions and 13 deletions

View File

@ -13,6 +13,10 @@ npm/codemirror@5.65.16/lib/codemirror.min.css,
npm/codemirror@5.65.16/theme/nord.min.css" npm/codemirror@5.65.16/theme/nord.min.css"
/> />
<meta name="viewport" content="width=device-width, initial-scale=1" /> <meta name="viewport" content="width=device-width, initial-scale=1" />
<meta property="og:title" content="Paste - No-database paste service" />
<meta property="og:image" content="https://cdn.jsdelivr.net/gh/bokub/nopaste@images/logo.png" />
<meta property="og:url" content="https://paste.scambier.xyz" />
<meta property="og:type" content="website" />
%sveltekit.head% %sveltekit.head%
</head> </head>
<body data-sveltekit-preload-data="hover"> <body data-sveltekit-preload-data="hover">

View File

@ -5,6 +5,7 @@
import { shareUrl, selectedLang } from '../store' import { shareUrl, selectedLang } from '../store'
import ComboBox from './ComboBox.svelte' import ComboBox from './ComboBox.svelte'
import Icon from '@iconify/svelte' import Icon from '@iconify/svelte'
import { goto } from '$app/navigation'
type Language = { type Language = {
text: string text: string
@ -80,6 +81,11 @@
function closeUrlInput() { function closeUrlInput() {
isUrlInputVisible = false isUrlInputVisible = false
} }
async function goToPreview() {
await updateShareUrl()
goto($shareUrl)
}
</script> </script>
<div class={cssClass}> <div class={cssClass}>
@ -116,9 +122,9 @@
</button> </button>
<!-- Switch to readonly view --> <!-- Switch to readonly view -->
<a class="button" href={$shareUrl}> <button class="button" on:click={goToPreview}>
<Icon class="text-xl" icon="fluent:eye-12-regular" /> <Icon class="text-xl" icon="fluent:eye-12-regular" />
</a> </button>
</div> </div>
{/if} {/if}
</div> </div>

View File

@ -5,7 +5,7 @@
<h1 class="text-xl">Paste</h1> <h1 class="text-xl">Paste</h1>
<span class="ml-8 text-xs"> <span class="ml-8 text-xs">
<a <a
href="/?l=md#G0oEIKySx5UfTkdu1XoEsNFTBka+1+MnKOMEeLUaweWLc/oYlbttJz93QOgIkhdODeUmDs/+u3T5RANkM7+ktGLRxbTN0WIKyb2AWJbsnIoNDvzMtbcgQpsQY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ed+Ywf1urDGbT92ILFgpZ+4VpQg0yY1RwBbgVZwqmsUFbcfNLLJIticha+GM6vi5k9FHqXND1s57VyV1Q5IhAP4zRimzipR2rEkKpHjeRpAoJIa0qLaLkNfN8HgcCA0gec+bDZ206cfvqtdJqnkvNWhsTFGQw="
target="_blank" target="_blank"
> >
About About

View File

@ -33,3 +33,6 @@ export function getLangFromUrl() {
} }
export const byId = (id: string) => document.getElementById(id) export const byId = (id: string) => document.getElementById(id)
export const staticMetaDescription =
'Paste is a client-side paste service with no database, and no back-end code. The data is stored entirely in the shared link'

View File

@ -10,15 +10,26 @@
import 'highlight.js/styles/nord.min.css' import 'highlight.js/styles/nord.min.css'
import TopBar from '../components/TopBar.svelte' import TopBar from '../components/TopBar.svelte'
import Icon from '@iconify/svelte' import Icon from '@iconify/svelte'
import { getLangFromUrl } from '$lib/utils' import { getLangFromUrl, staticMetaDescription } from '$lib/utils'
let decompressed: string let decompressed: string
let htmlContent: string
let isMarkdown = false let isMarkdown = false
let isPlainText = false let isPlainText = false
// Meta description
$: metaDescription = (() => {
if (decompressed) {
const text = decompressed.slice(0, 100)
return text + (text.length === 100 ? '...' : '')
}
return staticMetaDescription
})()
onMount(async () => { onMount(async () => {
let lang = getLangFromUrl() let lang = getLangFromUrl()
lang = lang === 'mrwn' || lang === 'gflm' ? 'md' : lang // back compatiblity with old links // Remove github flavored markdown, redundant with markdown
lang = lang === 'gflm' ? 'md' : lang
// extract the part in the url after the hash // extract the part in the url after the hash
const hash = window.location.hash.slice(1) const hash = window.location.hash.slice(1)
@ -37,7 +48,7 @@
.use(rehypeStringify) .use(rehypeStringify)
.process(decompressed) .process(decompressed)
isMarkdown = true isMarkdown = true
decompressed = html.toString() htmlContent = html.toString()
} }
// Plain text // Plain text
else if (lang === 'plt' || !lang) { else if (lang === 'plt' || !lang) {
@ -45,7 +56,7 @@
} }
// Code // Code
else { else {
decompressed = hljs.highlight(lang, decompressed).value htmlContent = hljs.highlight(lang, decompressed).value
} }
} else { } else {
// Redirect to editor page // Redirect to editor page
@ -59,7 +70,7 @@
</script> </script>
<div class="overflow-hidden h-screen flex flex-col"> <div class="overflow-hidden h-screen flex flex-col">
{#if decompressed} {#if htmlContent || decompressed}
<TopBar> <TopBar>
<a <a
href={'/editor' + getUrlDataPart()} href={'/editor' + getUrlDataPart()}
@ -72,19 +83,23 @@
<div class="overflow-y-auto grow"> <div class="overflow-y-auto grow">
<div class="prose dark:prose-invert lg:py-12 p-[0.5em] md:max-w-3xl md:mx-auto lg:max-w-4xl"> <div class="prose dark:prose-invert lg:py-12 p-[0.5em] md:max-w-3xl md:mx-auto lg:max-w-4xl">
{#if isMarkdown} {#if isMarkdown}
{@html decompressed} {@html htmlContent}
{:else if isPlainText} {:else if isPlainText}
<div class="whitespace-pre-line"> <div class="whitespace-pre-line">
{decompressed} {decompressed}
</div> </div>
{:else} {:else}
<pre><code>{@html decompressed}</code></pre> <pre><code>{@html htmlContent}</code></pre>
{/if} {/if}
</div> </div>
</div> </div>
{/if} {/if}
</div> </div>
<svelte:head>
<meta name="description" property="og:description" content={metaDescription} />
</svelte:head>
<style lang="scss"> <style lang="scss">
:global(pre code.hljs) { :global(pre code.hljs) {
background-color: transparent; background-color: transparent;

View File

@ -2,7 +2,7 @@
import type { Editor } from 'codemirror' import type { Editor } from 'codemirror'
import { debounce } from 'lodash-es' import { debounce } from 'lodash-es'
import * as brotli from '$lib/brotli' import * as brotli from '$lib/brotli'
import { byId } from '$lib/utils' import { byId, staticMetaDescription } from '$lib/utils'
import TopBar from '../../components/TopBar.svelte' import TopBar from '../../components/TopBar.svelte'
import { selectedLang, shareUrl } from '../../store' import { selectedLang, shareUrl } from '../../store'
import EditForm from '../../components/EditForm.svelte' import EditForm from '../../components/EditForm.svelte'
@ -18,7 +18,8 @@
if (editor) { if (editor) {
const url = new URL(window.location.origin) const url = new URL(window.location.origin)
compressed = await brotli.compress(editor.getValue()) compressed = await brotli.compress(editor.getValue())
if ($selectedLang) { // Set the language (ignore for plain text, since it's the default)
if ($selectedLang && $selectedLang !== 'plt') {
url.searchParams.set('l', $selectedLang) url.searchParams.set('l', $selectedLang)
} }
url.hash = compressed url.hash = compressed
@ -32,6 +33,8 @@
}, 1000) }, 1000)
async function initCodeEditor() { async function initCodeEditor() {
$selectedLang = new URLSearchParams(window.location.search).get('l') ?? ' plt'
CodeMirror.modeURL = 'https://cdn.jsdelivr.net/npm/codemirror@5.65.16/mode/%N/%N.js' CodeMirror.modeURL = 'https://cdn.jsdelivr.net/npm/codemirror@5.65.16/mode/%N/%N.js'
editor = new CodeMirror(byId('editor'), { editor = new CodeMirror(byId('editor'), {
lineNumbers: true, lineNumbers: true,
@ -64,11 +67,11 @@
} }
} }
$selectedLang = new URLSearchParams(window.location.search).get('l') ?? ' plt'
} }
</script> </script>
<svelte:head> <svelte:head>
<meta name="description" property="og:description" content={staticMetaDescription} />
<script <script
src="https://cdn.jsdelivr.net/combine/ src="https://cdn.jsdelivr.net/combine/
npm/codemirror@5.65.16, npm/codemirror@5.65.16,