From 3a2350b1500e781db7cb57d90dda0ec68ade9693 Mon Sep 17 00:00:00 2001 From: selectthegang <66577268+selectthegang@users.noreply.github.com> Date: Sat, 19 Mar 2022 05:52:13 +0000 Subject: [PATCH 01/31] Added baseplate, will require much more changes --- src/lib/EntryPreview.svelte | 22 ++++++++++++++++++++++ src/lib/database/entries.ts | 12 ++++++++++-- src/routes/edit/[slug].svelte | 13 +++++++++++++ src/routes/edit/index.svelte | 16 +++++++++++++++- src/routes/entry/[slug].svelte | 19 +++++++++++++++++++ 5 files changed, 79 insertions(+), 3 deletions(-) diff --git a/src/lib/EntryPreview.svelte b/src/lib/EntryPreview.svelte index c9ae4149..fd99ca29 100644 --- a/src/lib/EntryPreview.svelte +++ b/src/lib/EntryPreview.svelte @@ -13,6 +13,13 @@ {:else if entry.visibility === 'hidden'}
Hidden
{/if} + + {#if entry.tags} + {#each entry.tags as tag} +{tag}
+ {/each} + {/if} +{@html markdown.render(entry.content)}
@@ -26,6 +33,7 @@ color: inherit; text-decoration: none; } + .entry-preview-content { display: -webkit-box; -webkit-box-orient: vertical; @@ -51,4 +59,18 @@ box-shadow: 0 0 0.5em #0004; letter-spacing: 0.05ch; } + + .tag { + float: right; + border: 2px solid var(--alternate-background-color); + padding: 0.2rem; + border-radius: 0.2rem; + margin: 0; + position: relative; + top: -0.5em; + margin-right: 3px; + right: -0.5em; + box-shadow: 0 0 0.5em #0004; + letter-spacing: 0.05ch; + } diff --git a/src/lib/database/entries.ts b/src/lib/database/entries.ts index 9f76b4e5..25e22095 100644 --- a/src/lib/database/entries.ts +++ b/src/lib/database/entries.ts @@ -10,6 +10,7 @@ export interface Entry { slug: string visibility: Visibility createdAt: Date + tags: string[] } let triedCreatingSearchIndex = false @@ -33,6 +34,7 @@ interface FilterEntriesOptions { interface FetchEntriesOptions extends FilterEntriesOptions { limit: number skip: number + tags?: string[] } /** @@ -43,7 +45,8 @@ export async function fetchEntries(options: FetchEntriesOptions): PromiseHidden
{/if} + +{#if entry.tags} + {#each entry.tags as tag} +{tag}
+ {/each} +{/if} +{tag}
{/each} {/if} - +{@html markdown.render(entry.content)}
@@ -33,7 +33,7 @@ color: inherit; text-decoration: none; } - + .entry-preview-content { display: -webkit-box; -webkit-box-orient: vertical; diff --git a/src/lib/database/entries.ts b/src/lib/database/entries.ts index 25e22095..5001e262 100644 --- a/src/lib/database/entries.ts +++ b/src/lib/database/entries.ts @@ -46,7 +46,7 @@ export async function fetchEntries(options: FetchEntriesOptions): Promise{tag}
{/each} {/if} - +Hidden
{/if} + +{@html markdown.render(entry.content)}
{#if entry.tags} {#each entry.tags as tag}{tag}
{/each} {/if} - -{@html markdown.render(entry.content)}
+ \ No newline at end of file diff --git a/src/routes/api/entries.json.ts b/src/routes/api/entries.json.ts index cd1d0263..aa91bb7c 100644 --- a/src/routes/api/entries.json.ts +++ b/src/routes/api/entries.json.ts @@ -11,6 +11,7 @@ export const get: RequestHandler = async req => { const showUnlisted = req.url.searchParams.get('unlisted') === 'true' const showHidden = req.url.searchParams.get('hidden') === 'true' const tags = req.url.searchParams.get('tags')?.split(',') + const query = req.url.searchParams.get('query') const user = req.locals.user ? await fetchUser({ id: req.locals.user.id }) : null @@ -31,6 +32,7 @@ export const get: RequestHandler = async req => { unlisted: showUnlisted, hidden: showHidden, tags: tags, + query: query, }) return { @@ -107,6 +109,7 @@ export const post: RequestHandler = async req => { title: entryTitle, slug, visibility, + tags: [], }) if (entry) { diff --git a/src/routes/entry/[slug].svelte b/src/routes/entry/[slug].svelte index a16abc9c..3537039a 100644 --- a/src/routes/entry/[slug].svelte +++ b/src/routes/entry/[slug].svelte @@ -48,15 +48,15 @@Hidden
{/if} +{tag}
{/each} {/if} -Hidden
{/if} - +{@html markdown.render(entry.content)}
@@ -74,4 +74,4 @@ box-shadow: 0 0 0.5em #0004; letter-spacing: 0.05ch; } - \ No newline at end of file + diff --git a/src/routes/index.svelte b/src/routes/index.svelte index 9e690bae..654a28f1 100644 --- a/src/routes/index.svelte +++ b/src/routes/index.svelte @@ -35,26 +35,33 @@ let fetchIndex = 0 async function updateEntries() { - // example search with tags: "selectthegang tag:projects,mobile app" fetchIndex += 1 let thisFetchIndex = fetchIndex let search_value = (document.getElementById('search') as HTMLInputElement).value || null let tags: string - - if (!search_value) return - - let all = search_value.split(' '); - if (search_value.includes('tags:')) { - let tags_raw = all.filter(word => word.startsWith('tags:'))[0]; - // users must use underscores instead of spaces when it comes to tag searches - tags = tags_raw.slice(5).replaceAll('_', '%20'); + let query: string + + if (!search_value) { + query = null + } else { + if (search_value.includes('tags:')) { + let all = search_value.split(' ') + let tags_raw = all.filter(word => word.startsWith('tags:'))[0] + tags = tags_raw.slice(5).replaceAll('_', '%20') + query = all.filter(word => !word.startsWith('tags:')).join(' ') + } } - const query: string = all.filter(word => !word.startsWith('tags:')).join(' ') //|| "" - let url = `/api/entries.json?visible=${showVisible}&unlisted=${showUnlisted}&hidden=${showHidden}&query=${query}` - if (tags) { + let url = `/api/entries.json?visible=${showVisible}&unlisted=${showUnlisted}&hidden=${showHidden}` + + if (query) { + url += `&query=${query}` + } else if (tags) { url += `&tags=${tags}` } + + // i think i broke the TS compiler, whoops + const res = await fetch(url) const newEntries = await res.json() @@ -76,7 +83,7 @@ Repldex - + {#if canShowUnlisted}{tag}
+}>{tag}
{/each} {/if} diff --git a/src/lib/discord/scripts/registerCommands.ts b/src/lib/discord/scripts/registerCommands.ts index d23e231d..b85a4823 100644 --- a/src/lib/discord/scripts/registerCommands.ts +++ b/src/lib/discord/scripts/registerCommands.ts @@ -14,9 +14,7 @@ import fetch from 'node-fetch' async function registerCommands() { const bulkUpdate: RESTPutAPIApplicationCommandsJSONBody = commands.map(c => c.json) - console.log(JSON.stringify(bulkUpdate, null, 2)) - - const json = await fetch(GLOBAL_COMMAND_API_URL, { + fetch(GLOBAL_COMMAND_API_URL, { method: 'PUT', headers: { 'Content-Type': 'application/json', @@ -25,11 +23,8 @@ async function registerCommands() { body: JSON.stringify(bulkUpdate), }).then(res => res.json()) - console.log(JSON.stringify(json, null, 2)) - console.log('Registered commands :)') - console.log( - 'Please note that you only have to run this whenever the syntax of a command is changed, i.e. not on every code change.' - ) + console.log('Registered commands, Please note that you only have to run this whenever the syntax of a command is changed, i.e. not on every code change. :)'); + process.exit(0) } -registerCommands() +registerCommands() \ No newline at end of file From 95e4672d4d3f1b50ef4d64055832798652e3147b Mon Sep 17 00:00:00 2001 From: Jon Dough <49297268+jetstream0@users.noreply.github.com> Date: Mon, 28 Mar 2022 00:46:30 +0000 Subject: [PATCH 16/31] clicking on tags search - does not work completely (onclicks overlap) --- src/lib/EntryPreview.svelte | 7 ++++++- src/lib/discord/scripts/registerCommands.ts | 6 ++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/lib/EntryPreview.svelte b/src/lib/EntryPreview.svelte index e6363bfd..3f755be3 100644 --- a/src/lib/EntryPreview.svelte +++ b/src/lib/EntryPreview.svelte @@ -5,6 +5,11 @@ import * as markdown from './markdown' import { getEntryViewUrl } from './utils' + + function setTagSearch(tag) { + let search_bar = document.getElementById('search') as HTMLInputElement + search_bar.value = 'tags:' + tag.tag.replaceAll(' ', '_') + } @@ -19,7 +24,7 @@ {#if entry.tags} {#each entry.tags as tag} -}>{tag}
+setTagSearch({ tag })}>{tag}
{/each} {/if} diff --git a/src/lib/discord/scripts/registerCommands.ts b/src/lib/discord/scripts/registerCommands.ts index b85a4823..42e75a9e 100644 --- a/src/lib/discord/scripts/registerCommands.ts +++ b/src/lib/discord/scripts/registerCommands.ts @@ -23,8 +23,10 @@ async function registerCommands() { body: JSON.stringify(bulkUpdate), }).then(res => res.json()) - console.log('Registered commands, Please note that you only have to run this whenever the syntax of a command is changed, i.e. not on every code change. :)'); + console.log( + 'Registered commands, Please note that you only have to run this whenever the syntax of a command is changed, i.e. not on every code change. :)' + ) process.exit(0) } -registerCommands() \ No newline at end of file +registerCommands() From d5553036525e73dffadf0fbf7b8d741e2ec994d2 Mon Sep 17 00:00:00 2001 From: Jon Dough <49297268+jetstream0@users.noreply.github.com> Date: Sat, 18 Jun 2022 01:01:16 +0000 Subject: [PATCH 17/31] fixed tag search with extensive help of select, fixed the actual db search of tags --- src/lib/EntryPreview.svelte | 32 +++++++++++++++++++++++++------- src/lib/database/entries.ts | 11 ++++++++++- src/routes/edit/index.svelte | 15 +++++++-------- 3 files changed, 42 insertions(+), 16 deletions(-) diff --git a/src/lib/EntryPreview.svelte b/src/lib/EntryPreview.svelte index 3f755be3..f60954cd 100644 --- a/src/lib/EntryPreview.svelte +++ b/src/lib/EntryPreview.svelte @@ -1,18 +1,27 @@ - +Unlisted
{:else if entry.visibility === 'hidden'} @@ -24,10 +33,18 @@ {#if entry.tags} {#each entry.tags as tag} -setTagSearch({ tag })}>{tag}
+{ + setTagSearch({ tag }) + event.cancelBubble = true + }} + > + {tag} +
{/each} {/if} - +