Meta tags

This commit is contained in:
Simon Cambier 2023-11-25 08:09:44 +01:00
parent 7a0b49364f
commit f44cb83657
4 changed files with 29 additions and 7 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"
/>
<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%
</head>
<body data-sveltekit-preload-data="hover">

View File

@ -33,3 +33,6 @@ export function getLangFromUrl() {
}
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,12 +10,22 @@
import 'highlight.js/styles/nord.min.css'
import TopBar from '../components/TopBar.svelte'
import Icon from '@iconify/svelte'
import { getLangFromUrl } from '$lib/utils'
import { getLangFromUrl, staticMetaDescription } from '$lib/utils'
let decompressed: string
let htmlContent: string
let isMarkdown = false
let isPlainText = false
// Meta description
$: metaDescription = (() => {
if (decompressed) {
const text = decompressed.slice(0, 100)
return text + (text.length === 100 ? '...' : '')
}
return staticMetaDescription
})()
onMount(async () => {
let lang = getLangFromUrl()
lang = lang === 'mrwn' || lang === 'gflm' ? 'md' : lang // back compatiblity with old links
@ -37,7 +47,7 @@
.use(rehypeStringify)
.process(decompressed)
isMarkdown = true
decompressed = html.toString()
htmlContent = html.toString()
}
// Plain text
else if (lang === 'plt' || !lang) {
@ -45,7 +55,7 @@
}
// Code
else {
decompressed = hljs.highlight(lang, decompressed).value
htmlContent = hljs.highlight(lang, decompressed).value
}
} else {
// Redirect to editor page
@ -59,7 +69,7 @@
</script>
<div class="overflow-hidden h-screen flex flex-col">
{#if decompressed}
{#if htmlContent || decompressed}
<TopBar>
<a
href={'/editor' + getUrlDataPart()}
@ -72,19 +82,23 @@
<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">
{#if isMarkdown}
{@html decompressed}
{@html htmlContent}
{:else if isPlainText}
<div class="whitespace-pre-line">
{decompressed}
</div>
{:else}
<pre><code>{@html decompressed}</code></pre>
<pre><code>{@html htmlContent}</code></pre>
{/if}
</div>
</div>
{/if}
</div>
<svelte:head>
<meta name="description" property="og:description" content={metaDescription} />
</svelte:head>
<style lang="scss">
:global(pre code.hljs) {
background-color: transparent;

View File

@ -2,7 +2,7 @@
import type { Editor } from 'codemirror'
import { debounce } from 'lodash-es'
import * as brotli from '$lib/brotli'
import { byId } from '$lib/utils'
import { byId, staticMetaDescription } from '$lib/utils'
import TopBar from '../../components/TopBar.svelte'
import { selectedLang, shareUrl } from '../../store'
import EditForm from '../../components/EditForm.svelte'
@ -69,6 +69,7 @@
</script>
<svelte:head>
<meta name="description" property="og:description" content={staticMetaDescription} />
<script
src="https://cdn.jsdelivr.net/combine/
npm/codemirror@5.65.16,