Skip to content

Commit

Permalink
sitemap
Browse files Browse the repository at this point in the history
  • Loading branch information
chibat committed Dec 10, 2023
1 parent f111305 commit c376167
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 10 deletions.
9 changes: 4 additions & 5 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
{
"deno.enable": true,
"deno.inlayHints.variableTypes.enabled": false,
"deno.inlayHints.parameterNames.enabled": "none",
"deno.inlayHints.parameterTypes.enabled": false,
"deno.inlayHints.functionLikeReturnTypes.enabled": false,
"editor.defaultFormatter": "denoland.vscode-deno",
"editor.formatOnSave": true
"editor.formatOnSave": true,
"[typescriptreact]": {
"editor.defaultFormatter": "denoland.vscode-deno"
}
}
4 changes: 4 additions & 0 deletions fresh.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import * as $posts_new from "./routes/posts/new.tsx";
import * as $search from "./routes/search.tsx";
import * as $settings from "./routes/settings.tsx";
import * as $signout from "./routes/signout.ts";
import * as $sitemap_userId_ from "./routes/sitemap/[userId].tsx";
import * as $sitemap_index from "./routes/sitemap/index.tsx";
import * as $users_userId_ from "./routes/users/[userId].tsx";
import * as $AllPosts from "./islands/AllPosts.tsx";
import * as $DeleteAccount from "./islands/DeleteAccount.tsx";
Expand Down Expand Up @@ -57,6 +59,8 @@ const manifest = {
"./routes/search.tsx": $search,
"./routes/settings.tsx": $settings,
"./routes/signout.ts": $signout,
"./routes/sitemap/[userId].tsx": $sitemap_userId_,
"./routes/sitemap/index.tsx": $sitemap_index,
"./routes/users/[userId].tsx": $users_userId_,
},
islands: {
Expand Down
9 changes: 6 additions & 3 deletions routes/_app.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { AppProps } from "$fresh/server.ts";
import { PageProps } from "$fresh/server.ts";

export default function App({ Component }: AppProps) {
export default function App({ Component }: PageProps) {
return (
<html>
<head>
Expand All @@ -20,7 +20,7 @@ export default function App({ Component }: AppProps) {
<link rel="stylesheet" href="/app.css" />
<link rel="manifest" href="/manifest.json" />
{
/*
/*
<script async src="/register_sw.js" />
<script async src="https://www.googletagmanager.com/gtag/js?id=G-SZVLRW13Y8"></script>
<script>
Expand Down Expand Up @@ -51,6 +51,9 @@ export default function App({ Component }: AppProps) {
<li class="nav-item">
<a href="/about" class="nav-link px-2 text-muted">About</a>
</li>
<li class="nav-item">
<a href="/sitemap" class="nav-link px-2 text-muted">Sitemap</a>
</li>
</ul>
</footer>
<script
Expand Down
4 changes: 2 additions & 2 deletions routes/_middleware.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { MiddlewareHandlerContext } from "$fresh/server.ts";
import { FreshContext } from "$fresh/server.ts";
import { selectPostIds, selectUsers } from "~/server/db.ts";

export async function handler(
_req: Request,
ctx: MiddlewareHandlerContext,
ctx: FreshContext,
) {
const resp = await ctx.next();
if (resp.status === 500) {
Expand Down
25 changes: 25 additions & 0 deletions routes/sitemap/[userId].tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { defineRoute } from "$fresh/server.ts";
import { Head } from "$fresh/runtime.ts";
import { selectUserPostIds } from "~/server/db.ts";

export default defineRoute(async (_req, ctx) => {
const userId = Number(ctx.params.userId);
const postIds = await selectUserPostIds(userId);
return (
<>
<Head>
<title>Sitemap Posts - Leaves</title>
</Head>
<main class="container" style={{ wordBreak: "break-word" }}>
<h1>Sitemap Posts</h1>
{postIds.map((postId) => (
<>
<a href={`/posts/${postId}`}>
{postId}
</a>&nbsp;
</>
))}
</main>
</>
);
});
23 changes: 23 additions & 0 deletions routes/sitemap/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { defineRoute } from "$fresh/server.ts";
import { Head } from "$fresh/runtime.ts";
import { selectUsers } from "~/server/db.ts";

export default defineRoute(async (_req, _ctx) => {
const users = await selectUsers();

return (
<>
<Head>
<title>Sitemap Users - Leaves</title>
</Head>
<main class="container" style={{ wordBreak: "break-word" }}>
<h1>Sitemap Users</h1>
{users.map((user) => (
<>
<a href={`/sitemap/${user.user_id}`}>{user.user_id}</a>&nbsp;
</>
))}
</main>
</>
);
});
17 changes: 17 additions & 0 deletions server/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,23 @@ export async function selectUserPost(
return data ?? [];
}

export async function selectUserPostIds(userId: number) {
const { data, error } = await supabase.from("post").select("id").eq(
"user_id",
userId,
).eq(
"draft",
false,
).order(
"id",
{ ascending: false },
).limit(1000);
if (error) {
throw error;
}
return data.map((row) => row.id) ?? [];
}

export async function selectFollowingUsersPosts(
params: { userId: number; ltId: number | null },
) {
Expand Down

0 comments on commit c376167

Please sign in to comment.