Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,025 changes: 925 additions & 100 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion sites/hn.svelte.dev/jsconfig.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
{
"extends": "./.svelte-kit/tsconfig.json"
"extends": "./.svelte-kit/tsconfig.json",
"compilerOptions": {
"noImplicitAny": true,
"checkJs": true
}
}
14 changes: 7 additions & 7 deletions sites/hn.svelte.dev/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@
"build": "vite build",
"preview": "vite preview",
"lint": "prettier --ignore-path .gitignore --check --plugin-search-dir=. .",
"format": "prettier --ignore-path .gitignore --write --plugin-search-dir=. ."
"format": "prettier --ignore-path .gitignore --write --plugin-search-dir=. .",
"check": "svelte-check --tsconfig ./jsconfig.json"
},
"devDependencies": {
"@sveltejs/adapter-auto": "^2.0.0",
"@sveltejs/kit": "^1.5.0",
"@sveltejs/vite-plugin-svelte": "^2.0.2",
"@sveltejs/adapter-vercel": "^3.0.2",
"@sveltejs/kit": "^1.22.3",
"prettier": "^2.7.1",
"prettier-plugin-svelte": "^2.7.0",
"svelte": "^3.55.0",
"vite": "^4.0.1"
"prettier-plugin-svelte": "^2.10.1",
"svelte": "^4.0.5",
"vite": "^4.4.4"
},
"type": "module"
}
4 changes: 2 additions & 2 deletions sites/hn.svelte.dev/src/app.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!DOCTYPE html>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
Expand All @@ -21,7 +21,7 @@
</script>
%sveltekit.head%
</head>
<body data-sveltekit-prefetch>
<body data-sveltekit-preload-data="hover">
<div>%sveltekit.body%</div>
</body>
</html>
8 changes: 8 additions & 0 deletions sites/hn.svelte.dev/src/global.d.ts
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
/// <reference types="@sveltejs/kit" />

declare global {
namespace App {
interface Error {
frame?: string;
}
}
}
1 change: 1 addition & 0 deletions sites/hn.svelte.dev/src/lib/Nav.svelte
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<script>
/** @type {string} */
export let section;
</script>

Expand Down
7 changes: 0 additions & 7 deletions sites/hn.svelte.dev/src/routes/+error.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,6 @@

<pre>{message}</pre>

{#if dev && $page.error.frame}
<pre>{$page.error.frame}</pre>
{/if}
{#if dev && $page.error.stack}
<pre>{$page.error.stack}</pre>
{/if}

<style>
h1 {
margin: 0 auto;
Expand Down
6 changes: 3 additions & 3 deletions sites/hn.svelte.dev/src/routes/+page.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { dev } from '$app/environment';
import { redirect } from '@sveltejs/kit';

/** @type {import('./$types').PageLoad} */
export function load({ url }) {
throw redirect(url.hostname === 'localhost' || url.hostname === '127.0.0.1' ? 302 : 301, '/top/1');
export function load() {
throw redirect(dev ? 302 : 301, '/top/1');
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
/** @type {import('./$types').PageLoad} */
export async function load({ params, fetch }) {
const list = params.list === 'top' ? 'news' : params.list === 'new' ? 'newest' : params.list;

return {
list: params.list,
page: +params.page,
items: await fetch(`https://api.hnpwa.com/v0/${list}/${params.page}.json`).then((r) => r.json())
items: fetch(`https://api.hnpwa.com/v0/${list}/${params.page}.json`).then((r) => r.json())
};
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
<script>
/**
* @type {{
* domain?: string;
* id: string;
* url: string;
* title: string;
* type: string;
* time_ago: string;
* points: number;
* user: string;
* comments_count: number;
* }}
*/
export let item;

/** @type {number} */
export let index;
</script>

Expand Down
3 changes: 0 additions & 3 deletions sites/hn.svelte.dev/src/routes/[list=category]/rss/+server.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@ const render = (list, items) => `<?xml version="1.0" encoding="UTF-8" ?>
</channel>
</rss>`;

/**
* @type {import('@sveltejs/kit').RequestHandler}
*/
export async function GET({ params }) {
const list = params.list === 'top' ? 'news' : params.list === 'new' ? 'newest' : params.list;
const res = await fetch(`https://api.hnpwa.com/v0/${list}/1.json`);
Expand Down
4 changes: 1 addition & 3 deletions sites/hn.svelte.dev/src/routes/item/[id]/+page.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/** @type {import('./$types').PageLoad} */
export async function load({ params, fetch }) {
const res = await fetch(`https://api.hnpwa.com/v0/item/${params.id}.json`);
return await res.json();
return fetch(`https://api.hnpwa.com/v0/item/${params.id}.json`).then((r) => r.json());
}
17 changes: 16 additions & 1 deletion sites/hn.svelte.dev/src/routes/item/[id]/Comment.svelte
Original file line number Diff line number Diff line change
@@ -1,12 +1,27 @@
<script>
/**
* @type {{
* deleted?: boolean;
* user: string;
* time_ago: number;
* content: string;
* comments: any[];
* }}
*/
export let comment;

let hidden = false;
</script>

{#if !comment.deleted}
<article class="comment" class:hidden>
<div class="meta-bar" on:click={() => (hidden = !hidden)}>
<div
class="meta-bar"
role="button"
tabindex="0"
on:click={() => (hidden = !hidden)}
on:keyup={(e) => e.key === ' ' && (hidden = !hidden)}
>
<span class="meta">
<a href="/user/{comment.user}">{comment.user}</a>
{comment.time_ago}
Expand Down
1 change: 0 additions & 1 deletion sites/hn.svelte.dev/src/routes/rss/+server.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { dev } from '$app/environment';
import { redirect } from '@sveltejs/kit';

/** @type {import('@sveltejs/kit').RequestHandler} */
export function GET() {
throw redirect(dev ? 301 : 302, '/top/rss');
}
4 changes: 1 addition & 3 deletions sites/hn.svelte.dev/src/routes/user/[name]/+page.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
export const csr = false;

/** @type {import('./$types').PageLoad} */
export async function load({ params, fetch }) {
const res = await fetch(`https://api.hnpwa.com/v0/user/${params.name}.json`);
return res.json();
return fetch(`https://api.hnpwa.com/v0/user/${params.name}.json`).then((r) => r.json());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

making it one line makes sense, but why not use await still?

Suggested change
return fetch(`https://api.hnpwa.com/v0/user/${params.name}.json`).then((r) => r.json());
return (await fetch(`https://api.hnpwa.com/v0/user/${params.name}.json`)).json();

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dunno, await has felt weird when surrounded by brackets. .then feels cleaner for this case somehow

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if invalid JSON is returned from the API? I think the two ways of writing it would behave differently, but I'm not exactly sure what the behavior of the .then() version is

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's the same. If it errors, then .json() errors out, giving the same error as await version

}
6 changes: 4 additions & 2 deletions sites/hn.svelte.dev/svelte.config.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import adapter from '@sveltejs/adapter-auto';
import adapter from '@sveltejs/adapter-vercel';

/** @type {import('@sveltejs/kit').Config} */
const config = {
kit: {
adapter: adapter(),
// new projects use adapter-auto by default
// we use adapter-vercel here to use more efficient edge serving
adapter: adapter({ runtime: 'edge' }),

inlineStyleThreshold: 5000
}
Expand Down