fix some og things; dont hardcode analytics
This commit is contained in:
parent
df1eda0ea5
commit
cc60065d82
|
@ -1,12 +1,18 @@
|
|||
<script>
|
||||
import '../app.postcss';
|
||||
import { env } from "$env/dynamic/public";
|
||||
import { Modal, Toast, initializeStores } from '@skeletonlabs/skeleton';
|
||||
|
||||
initializeStores();
|
||||
|
||||
const umami_url = env.PUBLIC_UMAMI_URL;
|
||||
const umami_site_id = env.PUBLIC_UMAMI_SITE_ID;
|
||||
</script>
|
||||
|
||||
<svelte:head>
|
||||
<script async src="https://analytics.watzon.tech/script.js" data-website-id="542d82bc-7f24-4b96-bc79-b73f2e5f955f"></script>
|
||||
{#if umami_url && umami_site_id}
|
||||
<script async src="{umami_url}/script.js" data-website-id={umami_site_id}></script>
|
||||
{/if}
|
||||
</svelte:head>
|
||||
|
||||
<Modal />
|
||||
|
|
|
@ -13,13 +13,18 @@ export const load: PageLoad = async ({ params }) => {
|
|||
throw error(404, 'Paste not found');
|
||||
}
|
||||
|
||||
const highlight = ext || paste.highlight;
|
||||
const pasteUrl = `${env.SITE_URL}/${id}.${highlight}`;
|
||||
const ogImageUrl = `${env.SITE_URL}/images/paste/${id}.${highlight}`;
|
||||
|
||||
// Build the response object
|
||||
const response = {
|
||||
id: paste.id,
|
||||
url: `${env.SITE_URL}/${id}.${paste.highlight}`,
|
||||
pasteUrl,
|
||||
ogImageUrl,
|
||||
contents: paste.contents,
|
||||
encrypted: paste.encrypted,
|
||||
highlight: ext || paste.highlight,
|
||||
highlight: highlight,
|
||||
burnAfterReading: paste.burnAfterReading,
|
||||
}
|
||||
|
||||
|
|
|
@ -107,8 +107,8 @@
|
|||
<meta name="description" content="Paste69 - Paste {data.id}" />
|
||||
<meta property="og:title" content="Paste69 - Paste {data.id}" />
|
||||
<meta property="og:description" content="Paste69 - Paste {data.id}" />
|
||||
<meta property="og:image" content="/images/paste/{data.id}" />
|
||||
<meta property="og:url" content={data.url} />
|
||||
<meta property="og:image" content={data.ogImageUrl} />
|
||||
<meta property="og:url" content={data.pasteUrl} />
|
||||
<meta property="og:type" content="website" />
|
||||
</svelte:head>
|
||||
|
||||
|
@ -137,7 +137,7 @@
|
|||
{/if}
|
||||
<div class="text-gray-400 tracking-widest" style="writing-mode: vertical-rl;">SHARE</div>
|
||||
</button>
|
||||
<ShareMenu pasteUrl={data.url} on:copy={copyContents} />
|
||||
<ShareMenu pasteUrl={data.pasteUrl} on:copy={copyContents} />
|
||||
</div>
|
||||
|
||||
<div class="fixed bottom-0 right-0 w-full md:w-auto">
|
||||
|
|
|
@ -1,47 +0,0 @@
|
|||
import { Mongo } from "$lib/db/index";
|
||||
import { env } from "$env/dynamic/private";
|
||||
import { error, type RequestHandler } from "@sveltejs/kit";
|
||||
|
||||
export const GET: RequestHandler = async ({ params }) => {
|
||||
const { id } = params;
|
||||
|
||||
const pastes = await Mongo.getNamedCollection("pastes");
|
||||
const paste = await pastes.findOne({ id });
|
||||
|
||||
if (!paste) {
|
||||
throw error(404, 'Paste not found');
|
||||
}
|
||||
|
||||
if (paste.encrypted) {
|
||||
throw error(404, 'Cannot generate image for encrypted paste');
|
||||
}
|
||||
|
||||
if (paste.burnAfterReading) {
|
||||
throw error(404, 'Cannot generate image for burnable paste');
|
||||
}
|
||||
|
||||
const code = paste.contents;
|
||||
|
||||
// Grab at most 15 lines of the paste, if there aren't 15 lines, pad the rest with empty strings.
|
||||
let lines = code.split('\n').slice(0, 15).concat(Array.from({ length: 15 - code.split('\n').length }, () => ''));
|
||||
|
||||
// Truncate each line to 80 characters, and pad the rest with spaces.
|
||||
lines = lines.map(line => line.slice(0, 70).padEnd(70, ' '));
|
||||
|
||||
const title = `${env.SITE_URL}/${id}.${paste.highlight}`;
|
||||
const url = `https://inkify.0x45.st/generate?code=${encodeURIComponent(lines.join('\n'))}&window_title=${encodeURIComponent(title)}&language=${encodeURIComponent(paste.highlight)}&pad_horiz=5&pad_vert=5`;
|
||||
|
||||
const res = await fetch(url);
|
||||
const image = res.body;
|
||||
|
||||
if (image) {
|
||||
return new Response(image, {
|
||||
headers: {
|
||||
'Content-Type': 'image/png',
|
||||
'Cache-Control': 'public, max-age=604800, immutable',
|
||||
},
|
||||
});
|
||||
} else {
|
||||
throw error(500, 'Could not generate image');
|
||||
}
|
||||
};
|
Loading…
Reference in New Issue