quash: query parameters for just, has, and do, and some general simplification
This commit is contained in:
parent
f2f4e2e704
commit
4720d408f4
14 changed files with 156 additions and 164 deletions
|
|
@ -25,9 +25,9 @@ const related = post.data.related ? resolveRelatedPosts(post.data.related, allPo
|
|||
<Content />
|
||||
</article>
|
||||
{related.length > 0 && (
|
||||
<details open>
|
||||
<summary>related</summary>
|
||||
<section>
|
||||
<span class="section-label">related</span>
|
||||
<pre set:html={related.map(p => formatListItem(p.dates.created, `/${getSlug(p.id)}`, p.data.title)).join('\n')} />
|
||||
</details>
|
||||
</section>
|
||||
)}
|
||||
</Layout>
|
||||
|
|
|
|||
|
|
@ -1,11 +1,17 @@
|
|||
import type { APIRoute } from 'astro';
|
||||
import { createEntry } from '../../lib/db';
|
||||
import { jsonResponse, errorResponse } from '../../lib/api';
|
||||
import { isRateLimited } from '../../lib/rate-limit';
|
||||
|
||||
export const prerender = false;
|
||||
|
||||
export const POST: APIRoute = async ({ request }) => {
|
||||
try {
|
||||
const ip = request.headers.get('x-forwarded-for')?.split(',')[0]?.trim() ?? 'unknown';
|
||||
if (isRateLimited(ip, 3, 60_000)) {
|
||||
return errorResponse('Too many requests, try again later', 429);
|
||||
}
|
||||
|
||||
const data = await request.json();
|
||||
const { name, message, url } = data;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,16 +0,0 @@
|
|||
---
|
||||
import { getCollection } from 'astro:content';
|
||||
import Layout from '../../layouts/Layout.astro';
|
||||
import { formatListItem, extractDomain } from '../../lib/format';
|
||||
|
||||
const bookmarksCollection = await getCollection('bookmarks');
|
||||
const bookmarks = bookmarksCollection
|
||||
.sort((a, b) => b.data.date.getTime() - a.data.date.getTime());
|
||||
---
|
||||
<Layout title="bookmarks - lewis m.w.">
|
||||
|
||||
<details open>
|
||||
<summary>bookmarks</summary>
|
||||
<pre set:html={bookmarks.map(b => formatListItem(b.data.date, b.data.url, b.data.title, { suffix: `<span class="muted">(${extractDomain(b.data.url)})</span>` })).join('\n')} />
|
||||
</details>
|
||||
</Layout>
|
||||
|
|
@ -1,35 +0,0 @@
|
|||
---
|
||||
import Layout from '../../layouts/Layout.astro';
|
||||
import { getApprovedEntries, type GuestbookEntry } from '../../lib/db';
|
||||
import { formatDate } from '../../lib/format';
|
||||
|
||||
let guestbookEntries: GuestbookEntry[] = [];
|
||||
try {
|
||||
guestbookEntries = await getApprovedEntries();
|
||||
} catch {
|
||||
// DB not available during dev without env vars
|
||||
}
|
||||
---
|
||||
<Layout title="guestbook - lewis m.w.">
|
||||
|
||||
<details open>
|
||||
<summary>guestbook</summary>
|
||||
<div class="guestbook-entries">
|
||||
{guestbookEntries.map(e => (
|
||||
<div class="guestbook-entry">
|
||||
<span class="muted">{formatDate(e.createdAt)}</span>
|
||||
<span><b set:html={e.url ? `<a href="${e.url}">${e.name}</a>` : e.name} /> {e.message}</span>
|
||||
</div>
|
||||
))}
|
||||
<div class="guestbook-entry">
|
||||
<span></span>
|
||||
<span><a href="#" id="sign-guestbook">sign</a><span id="guestbook-status"></span></span>
|
||||
</div>
|
||||
</div>
|
||||
</details>
|
||||
|
||||
<script>
|
||||
import { initGuestbookSign } from '../../scripts/guestbook-sign';
|
||||
initGuestbookSign();
|
||||
</script>
|
||||
</Layout>
|
||||
|
|
@ -22,56 +22,57 @@ try {
|
|||
} catch {
|
||||
// DB not available during dev without env vars
|
||||
}
|
||||
|
||||
const urls = [
|
||||
...posts.map(post => ({ url: `/${getSlug(post.id)}`, date: post.dates.created.getTime() })),
|
||||
...txtFiles.map(f => ({ url: `/${f.name}`, date: f.date.getTime() })),
|
||||
...bookmarksCollection.map(b => ({ url: b.data.url, date: b.data.date.getTime() })),
|
||||
].sort((a, b) => b.date - a.date).map(e => e.url);
|
||||
---
|
||||
<Layout title="lewis m.w." isHome>
|
||||
<Layout title="lewis m.w." isHome urls={urls}>
|
||||
|
||||
{sortedCategories.map(category => {
|
||||
const categoryPosts = grouped[category];
|
||||
return (
|
||||
<details open>
|
||||
<summary>{category}</summary>
|
||||
<pre set:html={[
|
||||
...categoryPosts.slice(0, 10).map(post => formatListItem(post.dates.created, `/${getSlug(post.id)}`, post.data.title, { pinned: post.data.pinned })),
|
||||
...(categoryPosts.length > 10 ? [`<a href="/md/">+${categoryPosts.length - 10} more</a>`] : [])
|
||||
].join('\n')} />
|
||||
</details>
|
||||
<section data-section={category}>
|
||||
<a class="section-label" href={`?just=${category}`}>{category}</a>
|
||||
<pre set:html={categoryPosts.map(post => formatListItem(post.dates.created, `/${getSlug(post.id)}`, post.data.title, { pinned: post.data.pinned })).join('\n')} />
|
||||
</section>
|
||||
);
|
||||
})}
|
||||
|
||||
<details open>
|
||||
<summary>txt</summary>
|
||||
<pre set:html={[
|
||||
...txtFiles.slice(0, 10).map(f => formatListItem(f.date, `/${f.name}`, f.name, { pinned: f.pinned })),
|
||||
...(txtFiles.length > 10 ? [`<a href="/txt/">+${txtFiles.length - 10} more</a>`] : [])
|
||||
].join('\n')} />
|
||||
</details>
|
||||
<section data-section="txt">
|
||||
<a class="section-label" href="?just=txt">txt</a>
|
||||
<pre set:html={txtFiles.map(f => formatListItem(f.date, `/${f.name}`, f.name, { pinned: f.pinned })).join('\n')} />
|
||||
</section>
|
||||
|
||||
<details open>
|
||||
<summary>bookmarks</summary>
|
||||
<pre set:html={[
|
||||
...bookmarks.slice(0, 10).map(b => formatListItem(b.data.date, b.data.url, b.data.title, { suffix: `<span class="muted">(${extractDomain(b.data.url)})</span>` })),
|
||||
...(bookmarks.length > 10 ? [`<a href="/bookmarks/">+${bookmarks.length - 10} more</a>`] : [])
|
||||
].join('\n')} />
|
||||
</details>
|
||||
<section data-section="bookmarks">
|
||||
<a class="section-label" href="?just=bookmarks">bookmarks</a>
|
||||
<pre set:html={bookmarks.map(b => formatListItem(b.data.date, b.data.url, b.data.title, { suffix: `<span class="muted">(${extractDomain(b.data.url)})</span>` })).join('\n')} />
|
||||
</section>
|
||||
|
||||
<details open>
|
||||
<summary>guestbook</summary>
|
||||
<section data-section="guestbook">
|
||||
<a class="section-label" href="?just=guestbook">guestbook</a>
|
||||
<div class="guestbook-entries">
|
||||
{guestbookEntries.slice(0, 10).map(e => (
|
||||
{guestbookEntries.map(e => (
|
||||
<div class="guestbook-entry">
|
||||
<span class="muted">{formatDate(e.createdAt)}</span>
|
||||
<span><b set:html={e.url ? `<a href="${e.url}">${e.name}</a>` : e.name} /> {e.message}</span>
|
||||
</div>
|
||||
))}
|
||||
<div class="guestbook-entry">
|
||||
<span>{guestbookEntries.length > 10 && <a href="/guestbook/">+{guestbookEntries.length - 10} more</a>}</span>
|
||||
<span><a href="#" id="sign-guestbook">sign</a><span id="guestbook-status"></span></span>
|
||||
</div>
|
||||
</div>
|
||||
</details>
|
||||
<form id="guestbook-form" class="guestbook-form">
|
||||
<input type="text" name="name" placeholder="name" required maxlength="100" /><br />
|
||||
<input type="text" name="message" placeholder="message" required maxlength="500" /><br />
|
||||
<input type="url" name="url" placeholder="url (optional)" maxlength="200" /><br />
|
||||
<button type="submit">sign</button>
|
||||
<span id="guestbook-status"></span>
|
||||
</form>
|
||||
</section>
|
||||
|
||||
<script>
|
||||
import { initGuestbookSign } from '../scripts/guestbook-sign';
|
||||
initGuestbookSign();
|
||||
import { initGuestbookForm } from '../scripts/guestbook-sign';
|
||||
initGuestbookForm();
|
||||
|
||||
</script>
|
||||
</Layout>
|
||||
|
|
|
|||
|
|
@ -1,19 +0,0 @@
|
|||
---
|
||||
import { getCollection } from 'astro:content';
|
||||
import Layout from '../../layouts/Layout.astro';
|
||||
import { formatListItem } from '../../lib/format';
|
||||
import { organizePostsByCategory, getSlug, enrichPostsWithDates } from '../../lib/md';
|
||||
|
||||
const rawPosts = await getCollection('md');
|
||||
const posts = enrichPostsWithDates(rawPosts);
|
||||
const { grouped, categories: sortedCategories } = organizePostsByCategory(posts);
|
||||
---
|
||||
<Layout title="md - lewis m.w.">
|
||||
|
||||
{sortedCategories.map(category => (
|
||||
<details open>
|
||||
<summary>{category}</summary>
|
||||
<pre set:html={grouped[category].map(post => formatListItem(post.dates.created, `/${getSlug(post.id)}`, post.data.title, { pinned: post.data.pinned })).join('\n')} />
|
||||
</details>
|
||||
))}
|
||||
</Layout>
|
||||
|
|
@ -1,24 +0,0 @@
|
|||
import { getCollection } from 'astro:content';
|
||||
import type { APIContext } from 'astro';
|
||||
import { getSlug } from '../lib/md';
|
||||
import { getTxtFileNames } from '../lib/txt';
|
||||
|
||||
export const prerender = false;
|
||||
|
||||
export async function GET(context: APIContext) {
|
||||
const site = context.site?.origin ?? 'https://wynne.rs';
|
||||
const posts = await getCollection('md');
|
||||
const bookmarks = await getCollection('bookmarks');
|
||||
const txtFiles = getTxtFileNames();
|
||||
|
||||
const urls = [
|
||||
...posts.map(post => `/${getSlug(post.id)}`),
|
||||
...txtFiles.map(txt => `/${txt}`),
|
||||
...bookmarks.map(b => b.data.url),
|
||||
];
|
||||
|
||||
const random = urls[Math.floor(Math.random() * urls.length)];
|
||||
const redirectUrl = random.startsWith('http') ? random : `${site}${random}`;
|
||||
|
||||
return Response.redirect(redirectUrl, 302);
|
||||
}
|
||||
|
|
@ -15,10 +15,7 @@ export async function GET(context: APIContext) {
|
|||
const urls = [
|
||||
'/',
|
||||
...posts.map(post => `/${getSlug(post.id)}`),
|
||||
'/txt',
|
||||
...txtFiles.map(txt => `/${txt}`),
|
||||
'/bookmarks',
|
||||
'/guestbook',
|
||||
].map(p => `${site}${p}`);
|
||||
|
||||
return new Response([...urls, ...SUBDOMAINS].join('\n'), {
|
||||
|
|
|
|||
|
|
@ -1,14 +0,0 @@
|
|||
---
|
||||
import Layout from '../../layouts/Layout.astro';
|
||||
import { formatListItem } from '../../lib/format';
|
||||
import { getTxtFiles } from '../../lib/txt';
|
||||
|
||||
const txtFiles = getTxtFiles();
|
||||
---
|
||||
<Layout title="txt - lewis m.w.">
|
||||
|
||||
<details open>
|
||||
<summary>txt</summary>
|
||||
<pre set:html={txtFiles.map(f => formatListItem(f.date, `/${f.name}`, f.name, { pinned: f.pinned })).join('\n')} />
|
||||
</details>
|
||||
</Layout>
|
||||
Loading…
Add table
Add a link
Reference in a new issue