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} +

{entry.title}

{@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): Promise> = { visibility: { $in: [ @@ -53,8 +56,13 @@ export async function fetchEntries(options: FetchEntriesOptions): Promise): Promi const newEntry: ReplaceIdWithUuid = { ...entry, _id: entryId, - createdAt: new Date(), + createdAt: new Date() } // insert the entry into the database diff --git a/src/routes/edit/[slug].svelte b/src/routes/edit/[slug].svelte index 50576f11..f340870e 100644 --- a/src/routes/edit/[slug].svelte +++ b/src/routes/edit/[slug].svelte @@ -38,6 +38,7 @@ let entryTitle: string = entry.title let entryContent: string = entry.content + let entryTags: string[] = entry.tags let visibility: Visibility = entry.visibility // automatically update the page title @@ -56,6 +57,7 @@ id: entry.id, title: entryTitle, content: entryContent, + tags: entryTags, visibility: visibility, }), }).then(response => response.json()) @@ -97,6 +99,12 @@ +
+ + + +
+ @@ -112,6 +120,11 @@ margin-bottom: 1rem; } + .tags { + margin-top: 1rem; + margin-bottom: 1rem; + } + /* vertically align */ #editor-container { display: grid; diff --git a/src/routes/edit/index.svelte b/src/routes/edit/index.svelte index 800a6283..8f8cfd34 100644 --- a/src/routes/edit/index.svelte +++ b/src/routes/edit/index.svelte @@ -34,7 +34,8 @@ let entryTitle = '' let entryContent = '' - + let entryTags = [] + // automatically update the page title let pageTitle = 'Create entry' $: { @@ -53,6 +54,7 @@ body: JSON.stringify({ title: entryTitle, content: entryContent, + tags: entryTags, visibility, }), }).then(response => response.json()) @@ -89,10 +91,17 @@ + +
+ + + +
+ @@ -108,6 +117,11 @@ margin-bottom: 1rem; } + .tags { + margin-top: 1rem; + margin-bottom: 1rem; + } + /* vertically align */ #editor-container { display: grid; diff --git a/src/routes/entry/[slug].svelte b/src/routes/entry/[slug].svelte index 29f80afe..6e4f238d 100644 --- a/src/routes/entry/[slug].svelte +++ b/src/routes/entry/[slug].svelte @@ -47,6 +47,13 @@ {:else if entry.visibility === 'hidden'}

Hidden

{/if} + +{#if entry.tags} + {#each entry.tags as tag} +

{tag}

+ {/each} +{/if} +

{entry.title}

{@html markdown.render(entry.content)}
@@ -77,6 +84,16 @@ box-shadow: 0 0 0.5em #0004; } + .tag { + float: right; + border: 2px solid var(--alternate-background-color); + padding: 0.2rem; + border-radius: 0.2rem; + margin: 0; + margin-top: 3rem; + box-shadow: 0 0 0.5em #0004; + } + h1 { margin-top: 3rem; } @@ -92,9 +109,11 @@ h1 { padding-top: 2rem; } + .entry-nav-links { margin-top: 2rem; } + .entry-nav-links { left: 1em; margin-right: 0; From af5f4c8038a33d651745c82bf0fc7bc9b2c1b55d Mon Sep 17 00:00:00 2001 From: selectthegang <66577268+selectthegang@users.noreply.github.com> Date: Sat, 19 Mar 2022 05:54:45 +0000 Subject: [PATCH 02/31] Formatted code because ugly --- src/lib/EntryPreview.svelte | 4 ++-- src/lib/database/entries.ts | 9 ++++----- src/routes/edit/[slug].svelte | 4 ++-- src/routes/edit/index.svelte | 8 ++++---- src/routes/entry/[slug].svelte | 6 +++--- 5 files changed, 15 insertions(+), 16 deletions(-) diff --git a/src/lib/EntryPreview.svelte b/src/lib/EntryPreview.svelte index fd99ca29..ee2605a0 100644 --- a/src/lib/EntryPreview.svelte +++ b/src/lib/EntryPreview.svelte @@ -19,7 +19,7 @@

{tag}

{/each} {/if} - +

{entry.title}

{@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> = { visibility: { $in: [ @@ -56,13 +56,12 @@ export async function fetchEntries(options: FetchEntriesOptions): Promise): Promi const newEntry: ReplaceIdWithUuid = { ...entry, _id: entryId, - createdAt: new Date() + createdAt: new Date(), } // insert the entry into the database diff --git a/src/routes/edit/[slug].svelte b/src/routes/edit/[slug].svelte index f340870e..9fac6d7b 100644 --- a/src/routes/edit/[slug].svelte +++ b/src/routes/edit/[slug].svelte @@ -104,7 +104,7 @@ - + @@ -124,7 +124,7 @@ margin-top: 1rem; margin-bottom: 1rem; } - + /* vertically align */ #editor-container { display: grid; diff --git a/src/routes/edit/index.svelte b/src/routes/edit/index.svelte index 8f8cfd34..16091947 100644 --- a/src/routes/edit/index.svelte +++ b/src/routes/edit/index.svelte @@ -35,7 +35,7 @@ let entryTitle = '' let entryContent = '' let entryTags = [] - + // automatically update the page title let pageTitle = 'Create entry' $: { @@ -91,7 +91,7 @@ - + @@ -101,7 +101,7 @@ - + @@ -121,7 +121,7 @@ margin-top: 1rem; margin-bottom: 1rem; } - + /* vertically align */ #editor-container { display: grid; diff --git a/src/routes/entry/[slug].svelte b/src/routes/entry/[slug].svelte index 6e4f238d..564a87d3 100644 --- a/src/routes/entry/[slug].svelte +++ b/src/routes/entry/[slug].svelte @@ -53,7 +53,7 @@

{tag}

{/each} {/if} - +

{entry.title}

{@html markdown.render(entry.content)}
@@ -109,11 +109,11 @@ h1 { padding-top: 2rem; } - + .entry-nav-links { margin-top: 2rem; } - + .entry-nav-links { left: 1em; margin-right: 0; From 298e0dc5df5b6f770febc1c937c7eeb125669477 Mon Sep 17 00:00:00 2001 From: selectthegang <66577268+selectthegang@users.noreply.github.com> Date: Sat, 19 Mar 2022 06:04:52 +0000 Subject: [PATCH 03/31] Made some mini design changes --- src/lib/EntryPreview.svelte | 3 ++- src/lib/database/entries.ts | 3 --- src/routes/entry/[slug].svelte | 2 ++ 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/lib/EntryPreview.svelte b/src/lib/EntryPreview.svelte index ee2605a0..4d488879 100644 --- a/src/lib/EntryPreview.svelte +++ b/src/lib/EntryPreview.svelte @@ -56,6 +56,7 @@ position: relative; top: -0.5em; right: -0.5em; + margin-left: 5px; box-shadow: 0 0 0.5em #0004; letter-spacing: 0.05ch; } @@ -68,7 +69,7 @@ margin: 0; position: relative; top: -0.5em; - margin-right: 3px; + margin-left: 5px; 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 5001e262..9224d0ce 100644 --- a/src/lib/database/entries.ts +++ b/src/lib/database/entries.ts @@ -59,9 +59,6 @@ export async function fetchEntries(options: FetchEntriesOptions): Promise Date: Sat, 19 Mar 2022 16:50:41 +0000 Subject: [PATCH 04/31] db search for tags now supported, also in api --- src/lib/database/entries.ts | 1 + src/routes/api/entries.json.ts | 2 ++ 2 files changed, 3 insertions(+) diff --git a/src/lib/database/entries.ts b/src/lib/database/entries.ts index 9224d0ce..789eb23c 100644 --- a/src/lib/database/entries.ts +++ b/src/lib/database/entries.ts @@ -58,6 +58,7 @@ export async function fetchEntries(options: FetchEntriesOptions): Promise { const showVisible = req.url.searchParams.get('visible') !== 'false' 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 user = req.locals.user ? await fetchUser({ id: req.locals.user.id }) : null @@ -29,6 +30,7 @@ export const get: RequestHandler = async req => { visible: showVisible, unlisted: showUnlisted, hidden: showHidden, + tags: tags, }) return { From 9bf26a6ecaeb9989e1f98d87775377468db78735 Mon Sep 17 00:00:00 2001 From: Jon Dough <49297268+jetstream0@users.noreply.github.com> Date: Sun, 20 Mar 2022 04:45:48 +0000 Subject: [PATCH 05/31] api accepts query param, added search bar Select + Prussia --- src/lib/EntryPreview.svelte | 12 +++--- src/routes/api/entries.json.ts | 3 ++ src/routes/entry/[slug].svelte | 10 ++--- src/routes/index.svelte | 74 +++++++++++++++++++++++++++++++--- 4 files changed, 82 insertions(+), 17 deletions(-) diff --git a/src/lib/EntryPreview.svelte b/src/lib/EntryPreview.svelte index 4d488879..eb345bbb 100644 --- a/src/lib/EntryPreview.svelte +++ b/src/lib/EntryPreview.svelte @@ -13,15 +13,15 @@ {:else if entry.visibility === 'hidden'}

Hidden

{/if} + +

{entry.title}

+

{@html markdown.render(entry.content)}

{#if entry.tags} {#each entry.tags as tag}

{tag}

{/each} {/if} - -

{entry.title}

-

{@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} +

{entry.title}

+
{@html markdown.render(entry.content)}
+ {#if entry.tags} {#each entry.tags as tag}

{tag}

{/each} {/if} -

{entry.title}

-
{@html markdown.render(entry.content)}
- + \ No newline at end of file From 6d9a65047d2226e78e68d1d2bc0143bd692b27a7 Mon Sep 17 00:00:00 2001 From: selectthegang <66577268+selectthegang@users.noreply.github.com> Date: Mon, 21 Mar 2022 03:40:46 +0000 Subject: [PATCH 06/31] Fixed some mini bugs --- src/lib/EntryPreview.svelte | 4 +-- src/routes/index.svelte | 51 +++++++++++++++++++++---------------- 2 files changed, 31 insertions(+), 24 deletions(-) diff --git a/src/lib/EntryPreview.svelte b/src/lib/EntryPreview.svelte index eb345bbb..6f0783ee 100644 --- a/src/lib/EntryPreview.svelte +++ b/src/lib/EntryPreview.svelte @@ -13,7 +13,7 @@ {:else if entry.visibility === 'hidden'}

Hidden

{/if} - +

{entry.title}

{@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}
@@ -101,7 +108,7 @@ {/if}
- +
@@ -109,7 +116,7 @@ {/each}
- + \ No newline at end of file + From a3efbfccf9da5f48a55daa1723a55f1c22594192 Mon Sep 17 00:00:00 2001 From: selectthegang <66577268+selectthegang@users.noreply.github.com> Date: Mon, 21 Mar 2022 03:42:46 +0000 Subject: [PATCH 07/31] Added space into CONTRIBUTING.md to trigger Vercel --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index d2cb00c2..4c0c9fb5 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,6 +1,6 @@ # Contributing -If the change you'd like to make is simple enough such as fixing a tpyo, you can simply fork the repo, edit the file using GitHub's online editor, and make a pull request. +If the change you'd like to make is simple enough such as fixing a tpyo, you can simply fork the repo, edit the file using GitHub's online editor, and make a pull request. Otherwise, use the following instructions: 1. Fork the repository and clone it with Git. From f98fe33ed940aeb4b77993d62ab49cd4af422c15 Mon Sep 17 00:00:00 2001 From: selectthegang <66577268+selectthegang@users.noreply.github.com> Date: Mon, 21 Mar 2022 04:54:22 +0000 Subject: [PATCH 08/31] uhh, fixed search and broke database --- CONTRIBUTING.md | 2 +- src/routes/index.svelte | 24 ++++++++++++++++++------ 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 4c0c9fb5..d2cb00c2 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,6 +1,6 @@ # Contributing -If the change you'd like to make is simple enough such as fixing a tpyo, you can simply fork the repo, edit the file using GitHub's online editor, and make a pull request. +If the change you'd like to make is simple enough such as fixing a tpyo, you can simply fork the repo, edit the file using GitHub's online editor, and make a pull request. Otherwise, use the following instructions: 1. Fork the repository and clone it with Git. diff --git a/src/routes/index.svelte b/src/routes/index.svelte index 654a28f1..a5b8b47c 100644 --- a/src/routes/index.svelte +++ b/src/routes/index.svelte @@ -38,17 +38,18 @@ fetchIndex += 1 let thisFetchIndex = fetchIndex let search_value = (document.getElementById('search') as HTMLInputElement).value || null + let tags: string let query: string - if (!search_value) { query = null } else { + let all = search_value.split(' ') + query = all.filter(word => !word.startsWith('tags:')).join(' ') 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(' ') + console.log(query) } } @@ -60,12 +61,23 @@ url += `&tags=${tags}` } - // i think i broke the TS compiler, whoops - const res = await fetch(url) const newEntries = await res.json() - if (thisFetchIndex === fetchIndex) entries = newEntries + if (newEntries.length === 0) { + entries = [ + { + title: 'No Results Found', + content: 'Sorry, there are no results found with that query!', + slug: 'entry_does_not_exist', + id: '0', + tags: ['Error'], + visibility: 'visible', + }, + ] + } else { + if (thisFetchIndex === fetchIndex) entries = newEntries + } } $: { From 81f9e3448031cd036e305368d90ae64061b36c3d Mon Sep 17 00:00:00 2001 From: Jon Dough <49297268+jetstream0@users.noreply.github.com> Date: Mon, 21 Mar 2022 15:26:04 +0000 Subject: [PATCH 09/31] bug fix --- src/routes/index.svelte | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/routes/index.svelte b/src/routes/index.svelte index a5b8b47c..d4148976 100644 --- a/src/routes/index.svelte +++ b/src/routes/index.svelte @@ -42,7 +42,7 @@ let tags: string let query: string if (!search_value) { - query = null + query = undefined } else { let all = search_value.split(' ') query = all.filter(word => !word.startsWith('tags:')).join(' ') From 07c595c8aa13c360d68097f6ad0bf08741a1b97c Mon Sep 17 00:00:00 2001 From: Jon Dough <49297268+jetstream0@users.noreply.github.com> Date: Mon, 21 Mar 2022 15:46:11 +0000 Subject: [PATCH 10/31] another fix? --- src/routes/api/entries.json.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/routes/api/entries.json.ts b/src/routes/api/entries.json.ts index aa91bb7c..178ff0f5 100644 --- a/src/routes/api/entries.json.ts +++ b/src/routes/api/entries.json.ts @@ -11,7 +11,11 @@ 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') + let query = req.url.searchParams.get('query') + + if (query == null) { + query = undefined + } const user = req.locals.user ? await fetchUser({ id: req.locals.user.id }) : null From e894c4c2987f098e678c46592846c27ce12f429d Mon Sep 17 00:00:00 2001 From: Jon Dough <49297268+jetstream0@users.noreply.github.com> Date: Mon, 21 Mar 2022 15:52:40 +0000 Subject: [PATCH 11/31] bug fix for reals --- src/routes/api/entries.json.ts | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/routes/api/entries.json.ts b/src/routes/api/entries.json.ts index 178ff0f5..d9cd13b5 100644 --- a/src/routes/api/entries.json.ts +++ b/src/routes/api/entries.json.ts @@ -11,11 +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(',') - let query = req.url.searchParams.get('query') - - if (query == null) { - query = undefined - } + const query = req.url.searchParams.get('query') const user = req.locals.user ? await fetchUser({ id: req.locals.user.id }) : null @@ -36,7 +32,7 @@ export const get: RequestHandler = async req => { unlisted: showUnlisted, hidden: showHidden, tags: tags, - query: query, + query: query ? query : undefined, }) return { From 081969bdeab235000aebb7ced29b91c4211d7ba4 Mon Sep 17 00:00:00 2001 From: Jon Dough <49297268+jetstream0@users.noreply.github.com> Date: Tue, 22 Mar 2022 23:53:17 +0000 Subject: [PATCH 12/31] add basic api docs --- DOCUMENTATION.md | 23 +++++++++++++++++++++++ README.md | 3 +++ 2 files changed, 26 insertions(+) create mode 100644 DOCUMENTATION.md diff --git a/DOCUMENTATION.md b/DOCUMENTATION.md new file mode 100644 index 00000000..4e0961f7 --- /dev/null +++ b/DOCUMENTATION.md @@ -0,0 +1,23 @@ +# API Documentation + +## GET /api/entries.json +Search for entries + +### Params +All parameters should of course be encoded in the request url as URL query string parameters. + +Note: If there are no parameters, it will fetch all entries. + +- **`tags`**: CSV (comma seperated values) of tags to search for. Eg: "web,programming language,discord user" +- **`query`**: String to search for in article titles and content. +- **`visible`**: Boolean (true/false) of whether to show regular (non unlisted or hidden), 'visible' entries. Defaults to true. +- **`unlisted`**: Boolean (true/false) of whether to show unlisted entries. Some users may not have the proper permissions to view these entries. Defaults to false. +- **`hidden`**: Boolean (true/false) of whether to show hidden entries. Some users may not have the proper permissions to view these entries. Defaults to false. +- **`limit`**: Integer of how many entries it should return. Defaults to all. +- **`skip`**: Integer of how many entries should be skipped (useful for pagination). Defaults to 0 (skip none). + +## POST /api/entries.json +Creates entry. Probably should not try and do this programatically. + +## GET /api/random.json +Get random entry. \ No newline at end of file diff --git a/README.md b/README.md index 6bb442cd..77b4514a 100644 --- a/README.md +++ b/README.md @@ -10,3 +10,6 @@ Repldex is the unofficial community-editable encyclopedia of user created entrie # Contributing See [CONTRIBUTING.md](CONTRIBUTING.md) + +# API Docs +Looking for the Repldex api documentation? Go to [DOCUMENTATION.md](DOCUMENTATION.md) \ No newline at end of file From 62c50171cd6a3d2865a4529b17730fc9c0bee9b3 Mon Sep 17 00:00:00 2001 From: selectthegang <66577268+selectthegang@users.noreply.github.com> Date: Wed, 23 Mar 2022 04:53:38 +0000 Subject: [PATCH 13/31] Made .replit automatically format files before starting --- .replit | 2 +- DOCUMENTATION.md | 6 +++++- README.md | 3 ++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/.replit b/.replit index 5ebcdce9..ce0a7216 100644 --- a/.replit +++ b/.replit @@ -1,4 +1,4 @@ -run = "npm run dev:host" +run = "npm run format && npm run dev:host" onBoot = "npm install" [packager] diff --git a/DOCUMENTATION.md b/DOCUMENTATION.md index 4e0961f7..386d5484 100644 --- a/DOCUMENTATION.md +++ b/DOCUMENTATION.md @@ -1,9 +1,11 @@ # API Documentation ## GET /api/entries.json + Search for entries ### Params + All parameters should of course be encoded in the request url as URL query string parameters. Note: If there are no parameters, it will fetch all entries. @@ -17,7 +19,9 @@ Note: If there are no parameters, it will fetch all entries. - **`skip`**: Integer of how many entries should be skipped (useful for pagination). Defaults to 0 (skip none). ## POST /api/entries.json + Creates entry. Probably should not try and do this programatically. ## GET /api/random.json -Get random entry. \ No newline at end of file + +Get random entry. diff --git a/README.md b/README.md index 77b4514a..30556be8 100644 --- a/README.md +++ b/README.md @@ -12,4 +12,5 @@ Repldex is the unofficial community-editable encyclopedia of user created entrie See [CONTRIBUTING.md](CONTRIBUTING.md) # API Docs -Looking for the Repldex api documentation? Go to [DOCUMENTATION.md](DOCUMENTATION.md) \ No newline at end of file + +Looking for the Repldex api documentation? Go to [DOCUMENTATION.md](DOCUMENTATION.md) From 39d03f6efdba0213436086c0d5543a3cde29ca2a Mon Sep 17 00:00:00 2001 From: Jon Dough <49297268+jetstream0@users.noreply.github.com> Date: Thu, 24 Mar 2022 03:41:20 +0000 Subject: [PATCH 14/31] you can now add tags to entries --- src/routes/api/entries.json.ts | 3 ++- src/routes/api/entry/[slug].json.ts | 2 ++ src/routes/edit/[slug].svelte | 7 +++++-- src/routes/edit/index.svelte | 19 ++++++++++++------- 4 files changed, 21 insertions(+), 10 deletions(-) diff --git a/src/routes/api/entries.json.ts b/src/routes/api/entries.json.ts index d9cd13b5..23fea4cd 100644 --- a/src/routes/api/entries.json.ts +++ b/src/routes/api/entries.json.ts @@ -70,6 +70,7 @@ export const post: RequestHandler = async req => { // the typings for req.body are wrong, so we have to do `as any` const entryContent = body.content const entryTitle = body.title + const tags = body.tags const slug = createSlug(entryTitle) @@ -109,7 +110,7 @@ export const post: RequestHandler = async req => { title: entryTitle, slug, visibility, - tags: [], + tags, }) if (entry) { diff --git a/src/routes/api/entry/[slug].json.ts b/src/routes/api/entry/[slug].json.ts index 7d133a51..8da8f130 100644 --- a/src/routes/api/entry/[slug].json.ts +++ b/src/routes/api/entry/[slug].json.ts @@ -32,6 +32,7 @@ export const put: RequestHandler = async req => { const title = (body.title as string) ?? null const entryId = (body.id as string) ?? null const visibility = (body.visibility as Visibility) ?? null + const tags = (body.tags as string[]) ?? null const basicUser = req.locals.user @@ -111,6 +112,7 @@ export const put: RequestHandler = async req => { slug, title, visibility, + tags, }) await createHistoryItem({ entryId: createUuid(entry.id), diff --git a/src/routes/edit/[slug].svelte b/src/routes/edit/[slug].svelte index 9fac6d7b..e8fd92d0 100644 --- a/src/routes/edit/[slug].svelte +++ b/src/routes/edit/[slug].svelte @@ -38,7 +38,7 @@ let entryTitle: string = entry.title let entryContent: string = entry.content - let entryTags: string[] = entry.tags + let entryTags: string = entry.tags.join(',') let visibility: Visibility = entry.visibility // automatically update the page title @@ -47,7 +47,10 @@ async function submitEntry() { // make a put request to /api/entry/.json // if successful, redirect to /entry/ - + entryTags = entryTags.split(',') + if (entryTags.length == 1 && entryTags[0] == '') { + entryTags = [] + } const response: Entry | { error: string } = await fetch(`/api/entry/${entry.id}.json`, { method: 'PUT', headers: { diff --git a/src/routes/edit/index.svelte b/src/routes/edit/index.svelte index 16091947..ae623fc1 100644 --- a/src/routes/edit/index.svelte +++ b/src/routes/edit/index.svelte @@ -34,7 +34,7 @@ let entryTitle = '' let entryContent = '' - let entryTags = [] + let entryTags = '' // automatically update the page title let pageTitle = 'Create entry' @@ -45,7 +45,10 @@ async function submitEntry() { // make a post/put request to /api/entries.json // if successful, redirect to /entry/ - + entryTags = entryTags.split(',') + if (entryTags.length == 1 && entryTags[0] == '') { + entryTags = [] + } const response: Entry | { error: string } = await fetch('/api/entries.json', { method: 'POST', headers: { @@ -96,11 +99,13 @@
-
- - - -
+ {#if isAdmin(user)} +
+ + + +
+ {/if}
From 413c4f9592ea05d355afa9219d2dc70a0f756d8c Mon Sep 17 00:00:00 2001 From: selectthegang <66577268+selectthegang@users.noreply.github.com> Date: Sat, 26 Mar 2022 14:39:45 +0000 Subject: [PATCH 15/31] Made it so the register-commands actually ends rather than stays running for Vercel building --- src/lib/EntryPreview.svelte | 2 +- src/lib/discord/scripts/registerCommands.ts | 13 ++++--------- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/src/lib/EntryPreview.svelte b/src/lib/EntryPreview.svelte index 6f0783ee..e6363bfd 100644 --- a/src/lib/EntryPreview.svelte +++ b/src/lib/EntryPreview.svelte @@ -19,7 +19,7 @@ {#if entry.tags} {#each entry.tags as tag} -

{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 @@ - +
{ + window.location.href = getEntryViewUrl(entry) + }} +> {#if entry.visibility === 'unlisted'}

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} -
+