feat: add util page

This commit is contained in:
Xyphyn committed 2023-09-17 15:55:54 -07:00
1 parent 5a892648fb
commit 39975008c8
10 files changed
+174 -12

No files matched your search

+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "photon-lemmy",
"version": "1.8.2",
"version": "1.8.3",
"private": true,
"scripts": {
"dev": "vite dev",
+5 -4
View File
@@ -5,10 +5,13 @@
export let source: string = ''
export let inline: boolean = false
function replaceURLs(node: HTMLElement) {
function replaceURLs(node: HTMLElement, source: string) {
if (!div) return
console.log('replacing source', source)
const links = node.querySelectorAll('a')
links.forEach((l) => {
console.log('replacing link', l.href)
const photonified = photonify(l.href)
if (photonified) l.href = photonified
})
@@ -16,9 +19,7 @@
let div: HTMLElement
$: if (source && div) {
replaceURLs(div)
}
$: replaceURLs(div, source)
</script>
<div
+8
View File
@@ -10,6 +10,7 @@
import Logo from '$lib/components/ui/Logo.svelte'
import { LINKED_INSTANCE_URL, instance } from '$lib/instance.js'
import { site } from '$lib/lemmy.js'
import { userSettings } from '$lib/settings.js'
import { theme } from '$lib/ui/colors.js'
import {
Button,
@@ -22,6 +23,7 @@
import {
Bars3,
Bookmark,
BugAnt,
Cog6Tooth,
CommandLine,
ComputerDesktop,
@@ -264,6 +266,12 @@
</Select>
</div>
</MenuButton>
{#if $userSettings.debugInfo}
<MenuButton link href="/util">
<Icon src={BugAnt} mini width={16} />
Debug
</MenuButton>
{/if}
<hr class="dark:opacity-10 w-[90%] my-2 mx-auto" />
<li class="flex flex-col px-4 py-1 mx-auto my-1 text-xs w-full">
<div class="flex flex-row gap-2 w-full">
+13 -7
View File
@@ -1,13 +1,19 @@
export const isImage = (url: string | undefined) => {
if (!url) return false
try {
if (!url) return false
return /\.(jpeg|jpg|gif|png|svg|bmp|webp)$/i.test(new URL(url).pathname)
return /\.(jpeg|jpg|gif|png|svg|bmp|webp)$/i.test(new URL(url).pathname)
} catch (err) {
return false
}
}
export const isVideo = (inputUrl: string | undefined) => {
if (!inputUrl) return false
export const isVideo = (url: string | undefined) => {
try {
if (!url) return false
const url = new URL(inputUrl).pathname.toLowerCase()
return url.endsWith('mp4') || url.endsWith('webm') || url.endsWith('mov') || url.endsWith('m4v')
return /\.(mp4|mov|webm|mkv)$/i.test(new URL(url).pathname)
} catch (err) {
return false
}
}
+30
View File
@@ -0,0 +1,30 @@
<script lang="ts">
import { goto } from '$app/navigation'
import { page } from '$app/stores'
import MultiSelect from '$lib/components/input/Switch.svelte'
</script>
<MultiSelect
headless
options={[
'/util',
'/util/photonify',
'/util/placeholder',
'/util/constants',
'/util/functions',
]}
optionNames={[
'Home',
'Photonify links',
'Placeholders',
'Constants',
'Functions',
]}
selected={$page.url.pathname}
on:select={(e) => {
goto(e.detail)
}}
/>
<div class="mt-4 flex flex-col gap-2">
<slot />
</div>
+5
View File
@@ -0,0 +1,5 @@
<h1 class="font-bold text-2xl">Utilities</h1>
<p>
These are mostly for debugging purposes but you can use them to see how Photon
works on the inside. (if you don't feel like reading the source code)
</p>
+34
View File
@@ -0,0 +1,34 @@
<script>
import { DOMAIN_REGEX_FORMS } from '$lib/util'
</script>
<h1 class="font-bold text-2xl">Constants</h1>
<p>Constants used throughout the app.</p>
<table class="table-fixed">
<thead>
<tr>
<td>Name</td>
<td>Value</td>
</tr>
</thead>
<tbody>
<tr>
<td>DOMAIN_REGEX</td>
<td>{DOMAIN_REGEX_FORMS}</td>
</tr>
</tbody>
</table>
<style>
thead td {
font-weight: bold;
}
td {
border: 1px solid;
border-color: #ddd;
font-family: monospace;
font-size: 14px;
}
</style>
+20
View File
@@ -0,0 +1,20 @@
<script lang="ts">
import { isImage, isVideo } from '$lib/ui/image.js'
import { TextInput } from 'mono-svelte'
let imageInput = ''
$: inputIsImage = isImage(imageInput)
$: inputIsVideo = isVideo(imageInput)
</script>
<h1 class="font-bold text-2xl">Functions</h1>
<p>Various utility functions.</p>
<h2 class="font-bold text-xl mt-4">Images</h2>
<TextInput
label="Image/Video URL"
placeholder="image.jpg"
bind:value={imageInput}
/>
<p>Image: {inputIsImage}</p>
<p>Video: {inputIsVideo}</p>
+20
View File
@@ -0,0 +1,20 @@
<script lang="ts">
import { photonify } from '$lib/components/markdown/markdown.js'
import { TextInput } from 'mono-svelte'
let link = ''
$: photonified = photonify(link)
</script>
<h1 class="font-bold text-2xl">Photonify links</h1>
<p>Convert a link from a Lemmy post to a Photon link.</p>
<div class="flex flex-row items-center flex-wrap gap-4">
<TextInput
label="Input"
bind:value={link}
placeholder="https://lemmy.world/post/1"
/>
<TextInput label="Output" bind:value={photonified} />
</div>
+38
View File
@@ -0,0 +1,38 @@
<script lang="ts">
import { placeholders } from '$lib/util.js'
import { Button } from 'mono-svelte'
let post = placeholders.get('post')
let comment = placeholders.get('comment')
let url = placeholders.get('url')
</script>
<h1 class="font-bold text-2xl">Placeholders</h1>
<p>
Photon randomly generates placeholders for use in text inputs and stuff. If
you have "Random Placeholders" disabled in settings, they will be empty.
</p>
<h2 class="font-bold text-xl mt-4">Posts</h2>
<p>
{post}
</p>
<Button on:click={() => (post = placeholders.get('post'))} class="w-max">
Generate
</Button>
<h2 class="font-bold text-xl mt-4">Comments</h2>
<p>
{comment}
</p>
<Button on:click={() => (comment = placeholders.get('comment'))} class="w-max">
Generate
</Button>
<h2 class="font-bold text-xl mt-4">Urls</h2>
<p>
{url}
</p>
<Button on:click={() => (url = placeholders.get('url'))} class="w-max">
Generate
</Button>