docs: new website (#66)
This commit is contained in:
@@ -36,4 +36,4 @@ jobs:
|
||||
run: deno cache --no-check src/*/deps.ts
|
||||
|
||||
- name: Run tests
|
||||
run: deno test -A --unstable --no-check
|
||||
run: deno test -A --no-check
|
||||
|
||||
@@ -46,7 +46,7 @@ fresh init myproject
|
||||
To now start the project, call `deno run`:
|
||||
|
||||
```
|
||||
deno run -A --unstable --watch main.ts
|
||||
deno run -A --watch main.ts
|
||||
```
|
||||
|
||||
To deploy the script to [Deno Deploy](https://deno.com/deploy), push your
|
||||
|
||||
@@ -45,7 +45,7 @@ To learn more about how projects are structured, take a look at the
|
||||
You can now run your new project locally using the `deno` CLI:
|
||||
|
||||
```
|
||||
deno run -A --unstable --watch main.ts
|
||||
deno run -A --watch main.ts
|
||||
```
|
||||
|
||||
The `--watch` option will cause your script to be reloaded on any changes to the
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
/** @jsx h */
|
||||
|
||||
import { h } from "../deps.ts";
|
||||
|
||||
interface Props {
|
||||
params: Record<string, string | string[]>;
|
||||
}
|
||||
|
||||
export default function Greet(props: Props) {
|
||||
return <div>Hello {props.params.name}</div>;
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
import { HandlerContext } from "../../../server.ts";
|
||||
|
||||
// Jokes courtesy of https://punsandoneliners.com/randomness/programmer-jokes/
|
||||
const JOKES = [
|
||||
"Why do Java developers often wear glasses? They can’t C#.",
|
||||
"A SQL query walks into a bar, goes up to two tables and says “can I join you?",
|
||||
"Wasn’t hard to crack Forrest Gump’s password. 1forrest1.",
|
||||
"I love pressing the F5 key. It’s refreshing.",
|
||||
"Called IT support and a chap from Australia came to fix my network connection. I asked “Do you come from a LAN down under?”",
|
||||
"There are 10 types of people in the world. Those who understand binary and those who don’t.",
|
||||
"Why are assembly programmers often wet? They work below C level.",
|
||||
"My favourite computer based band is the Black IPs.",
|
||||
"What programme do you use to predict the music tastes of former US presidential candidates? An Al Gore Rhythm.",
|
||||
"An SEO expert walked into a bar, pub, inn, tavern, hostelry, public house.",
|
||||
];
|
||||
|
||||
export const handler = (_ctx: HandlerContext): Response => {
|
||||
const randomIndex = Math.floor(Math.random() * 10);
|
||||
const body = JOKES[randomIndex];
|
||||
return new Response(body);
|
||||
};
|
||||
@@ -1,47 +0,0 @@
|
||||
/** @jsx h */
|
||||
|
||||
import { RoundedButton } from "../components/Button.tsx";
|
||||
import { IconMinus, IconPlus } from "../components/Icons.tsx";
|
||||
import { h, IS_BROWSER, PageConfig, tw, useState } from "../deps.ts";
|
||||
|
||||
export default function Home() {
|
||||
return (
|
||||
<div class={tw`max-w-screen-md px-4 mx-auto my-8`}>
|
||||
<p class={tw`font-bold`}>
|
||||
Welcome to `fresh`. Try update this message in the ./pages/index.tsx
|
||||
file, and refresh.
|
||||
</p>
|
||||
<Counter />
|
||||
<p class={tw`mt-4`}>
|
||||
{IS_BROWSER ? "Viewing browser render." : "Viewing JIT render."}
|
||||
</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function Counter() {
|
||||
const [count, setCount] = useState(0);
|
||||
return (
|
||||
<div class={tw`mt-4 border rounded p-4 text-center`}>
|
||||
<p class={tw`text-lg font-medium`}>Current count: {count}</p>
|
||||
<div class={tw`flex gap-2 mt-4 justify-center`}>
|
||||
<RoundedButton
|
||||
type="button"
|
||||
onClick={() => setCount(count - 1)}
|
||||
disabled={!IS_BROWSER}
|
||||
>
|
||||
<IconMinus />
|
||||
</RoundedButton>
|
||||
<RoundedButton
|
||||
type="button"
|
||||
onClick={() => setCount(count + 1)}
|
||||
disabled={!IS_BROWSER}
|
||||
>
|
||||
<IconPlus />
|
||||
</RoundedButton>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export const config: PageConfig = { runtimeJS: true };
|
||||
@@ -1,28 +0,0 @@
|
||||
/** @jsx h */
|
||||
|
||||
import { h, Suspense, tw, useData } from "../deps.ts";
|
||||
|
||||
export default function SuspensePage() {
|
||||
return (
|
||||
<Suspense
|
||||
fallback={(
|
||||
<p class={tw`text-red-500 hover:text-purple-500`}>
|
||||
Loading...
|
||||
</p>
|
||||
)}
|
||||
>
|
||||
<SuspendedComponent />
|
||||
</Suspense>
|
||||
);
|
||||
}
|
||||
|
||||
export function SuspendedComponent() {
|
||||
const data = useData("Loaded", delayer);
|
||||
return <p class={tw`text-blue-500 hover:text-green-500`}>{data}!</p>;
|
||||
}
|
||||
|
||||
// A function that returns a promise that resolves after a delay with the given
|
||||
// value.
|
||||
function delayer(key: string) {
|
||||
return new Promise((resolve) => setTimeout(() => resolve(key), 2000));
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
/** @jsx h */
|
||||
|
||||
import { h, PageConfig, PageProps, useData } from "../../deps.ts";
|
||||
|
||||
export default function ModuleInfoPage({ params }: PageProps) {
|
||||
const module = params.module;
|
||||
|
||||
if (module.includes("/")) {
|
||||
return <div>Invalid module name.</div>;
|
||||
}
|
||||
|
||||
const url = `https://cdn.deno.land/${params.module}/meta/versions.json`;
|
||||
const info = useData(url, fetcher);
|
||||
|
||||
if (info === null) {
|
||||
return <div>No module found with name `{params.module}`.</div>;
|
||||
}
|
||||
|
||||
const { latest, versions } = info;
|
||||
return (
|
||||
<p>
|
||||
The module `{params.module}` has {versions.length} versions, with {latest}
|
||||
{" "}
|
||||
being the most recent.
|
||||
</p>
|
||||
);
|
||||
}
|
||||
|
||||
interface ModuleInfo {
|
||||
latest: string;
|
||||
versions: string[];
|
||||
}
|
||||
|
||||
async function fetcher(url: string): Promise<ModuleInfo | null> {
|
||||
const resp = await fetch(url);
|
||||
if (resp.status === 200) return resp.json();
|
||||
return null;
|
||||
}
|
||||
|
||||
export const config: PageConfig = { runtimeJS: false };
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"deno.enable": true,
|
||||
"deno.lint": true,
|
||||
"deno.unstable": true
|
||||
}
|
||||
@@ -5,7 +5,7 @@
|
||||
Start the project:
|
||||
|
||||
```
|
||||
deno run -A --unstable --watch main.ts
|
||||
deno run -A --watch main.ts
|
||||
```
|
||||
|
||||
After adding, removing, or moving a page in the `pages` directory, run:
|
||||
@@ -0,0 +1,2 @@
|
||||
export * from "../../runtime.ts";
|
||||
export * from "../../server.ts";
|
||||
@@ -0,0 +1,11 @@
|
||||
/// <reference no-default-lib="true" />
|
||||
/// <reference lib="dom" />
|
||||
/// <reference lib="dom.iterable" />
|
||||
/// <reference lib="dom.asynciterable" />
|
||||
/// <reference lib="deno.ns" />
|
||||
/// <reference lib="deno.unstable" />
|
||||
|
||||
import { start } from "../../server.ts";
|
||||
import routes from "./routes.gen.ts";
|
||||
|
||||
await start(routes);
|
||||
@@ -0,0 +1,50 @@
|
||||
/** @jsx h */
|
||||
import { h, HandlerContext, Suspense, useData } from "../deps.ts";
|
||||
import { getDatabase, Todo } from "../utils/database.ts";
|
||||
|
||||
export default function TodoListPage() {
|
||||
return (
|
||||
<div>
|
||||
<h1>Your TODOs</h1>
|
||||
<AddTodoForm />
|
||||
<Suspense fallback={<p>Loading...</p>}>
|
||||
<TodoList />
|
||||
</Suspense>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function AddTodoForm() {
|
||||
return (
|
||||
<form method="POST">
|
||||
<input type="text" name="text" />
|
||||
<button type="submit" style="margin-left: 4px">Add</button>
|
||||
</form>
|
||||
);
|
||||
}
|
||||
|
||||
function TodoList() {
|
||||
const todos = useData<Todo[]>("todos", async () => {
|
||||
const db = await getDatabase();
|
||||
const todos = await db.listTodos();
|
||||
return todos;
|
||||
});
|
||||
return (
|
||||
<ul>
|
||||
{todos.map((todo) => <li key={todo.id}>{todo.text}</li>)}
|
||||
</ul>
|
||||
);
|
||||
}
|
||||
|
||||
export const handler = {
|
||||
async POST(ctx: HandlerContext): Promise<Response> {
|
||||
const form = await ctx.req.formData();
|
||||
const text = form.get("text");
|
||||
if (typeof text !== "string") {
|
||||
return new Response("misformed form", { status: 400 });
|
||||
}
|
||||
const db = await getDatabase();
|
||||
await db.addTodo(text);
|
||||
return Response.redirect(ctx.req.url, 303);
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,14 @@
|
||||
// DO NOT EDIT. This file is generated by `fresh`.
|
||||
// This file SHOULD be checked into source version control.
|
||||
// To update this file, run `fresh routes`.
|
||||
|
||||
import * as $0 from "./pages/index.tsx";
|
||||
|
||||
const routes = {
|
||||
pages: {
|
||||
"./pages/index.tsx": $0,
|
||||
},
|
||||
baseUrl: import.meta.url,
|
||||
};
|
||||
|
||||
export default routes;
|
||||
@@ -0,0 +1,43 @@
|
||||
import { Client } from "https://raw.githubusercontent.com/denodrivers/postgres/72f523cb9d8f863204a3fa02f52d534e7ce30ccf/mod.ts";
|
||||
|
||||
export interface Todo {
|
||||
id: number;
|
||||
text: string;
|
||||
}
|
||||
|
||||
class Database {
|
||||
#client: Client;
|
||||
|
||||
constructor(client: Client) {
|
||||
this.#client = client;
|
||||
}
|
||||
|
||||
static async connect() {
|
||||
const client = new Client(Deno.env.get("DATABASE_URL"));
|
||||
await client.connect();
|
||||
await client.queryObject`CREATE TABLE IF NOT EXISTS todos (
|
||||
id SERIAL PRIMARY KEY,
|
||||
text TEXT NOT NULL
|
||||
)`;
|
||||
return new Database(client);
|
||||
}
|
||||
|
||||
async listTodos(): Promise<Todo[]> {
|
||||
const { rows } = await this.#client.queryObject<Todo>`SELECT * FROM todos`;
|
||||
return rows;
|
||||
}
|
||||
|
||||
async addTodo(text: string): Promise<Todo> {
|
||||
const { rows } = await this.#client.queryObject<Todo>`
|
||||
INSERT INTO todos (text) VALUES (${text})
|
||||
RETURNING *
|
||||
`;
|
||||
return rows[0];
|
||||
}
|
||||
}
|
||||
|
||||
const db: Database | Promise<Database> = Database.connect();
|
||||
|
||||
export async function getDatabase(): Promise<Database> {
|
||||
return await db;
|
||||
}
|
||||
@@ -7,5 +7,5 @@ lint:
|
||||
test:
|
||||
deno test -A
|
||||
|
||||
watch_example:
|
||||
deno run -A --unstable --watch --no-check example/main.ts
|
||||
dev:
|
||||
deno run -A --watch --no-check www/main.ts
|
||||
+1
-1
@@ -165,7 +165,7 @@ await start(routes);
|
||||
Start the project:
|
||||
|
||||
\`\`\`
|
||||
deno run -A --unstable --watch main.ts
|
||||
deno run -A --watch main.ts
|
||||
\`\`\`
|
||||
|
||||
After adding, removing, or moving a page in the \`pages\` directory, run:
|
||||
|
||||
@@ -272,6 +272,9 @@ export function template(opts: TemplateOptions): string {
|
||||
const page = (
|
||||
<html lang={opts.lang}>
|
||||
<head>
|
||||
<meta charSet="UTF-8" />
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
{opts.preloads.map((src) => <link rel="modulepreload" href={src} />)}
|
||||
{opts.imports.map((src) => <script src={src} type="module"></script>)}
|
||||
<style
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
Start the project:
|
||||
|
||||
```
|
||||
deno run -A --unstable --watch main.ts
|
||||
deno run -A --watch main.ts
|
||||
```
|
||||
|
||||
After adding, removing, or moving a page in the `pages` directory, run:
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
# fresh website
|
||||
|
||||
This is the fresh website source. The fresh website contains:
|
||||
|
||||
- a homepage
|
||||
- a documentation page
|
||||
|
||||
### Usage
|
||||
|
||||
Start the project:
|
||||
|
||||
```
|
||||
deno run -A --watch main.ts
|
||||
```
|
||||
|
||||
After adding, removing, or moving a page in the `pages` directory, run:
|
||||
|
||||
```
|
||||
fresh routes
|
||||
```
|
||||
@@ -0,0 +1,155 @@
|
||||
/** @jsx h */
|
||||
/** @jsxFrag Fragment */
|
||||
|
||||
import { Fragment, h, tw } from "../deps.ts";
|
||||
|
||||
export default function MainPage() {
|
||||
return (
|
||||
<>
|
||||
<Hero />
|
||||
<NavigationBar active="/" />
|
||||
<Intro />
|
||||
<GettingStarted />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
function Hero() {
|
||||
const container = tw`w-full h-64 flex justify-center items-center flex-col`;
|
||||
const title = tw
|
||||
`text(4xl sm:5xl lg:6xl gray-900) sm:tracking-tight font-extrabold`;
|
||||
const subtitle = tw`mt-4 text(2xl gray-600)`;
|
||||
|
||||
return (
|
||||
<section class={container}>
|
||||
<h1 class={title}>
|
||||
fresh
|
||||
</h1>
|
||||
<h3 class={subtitle}>
|
||||
The next-gen web framework.
|
||||
</h3>
|
||||
</section>
|
||||
);
|
||||
}
|
||||
|
||||
function NavigationBar(props: { active: string }) {
|
||||
const items = [
|
||||
{
|
||||
name: "Home",
|
||||
href: "/",
|
||||
},
|
||||
{
|
||||
name: "Docs",
|
||||
href: "/docs",
|
||||
},
|
||||
];
|
||||
|
||||
return (
|
||||
<nav class={tw`bg(gray-50) py-2 border(t-2 b-2 gray-100)`}>
|
||||
<ul class={tw`flex justify-center gap-8 mx-4`}>
|
||||
{items.map((item) => (
|
||||
<li>
|
||||
<a
|
||||
href={item.href}
|
||||
class={tw`text-gray-600 hover:underline ${
|
||||
props.active == item.href ? "font-bold" : ""
|
||||
}`}
|
||||
>
|
||||
{item.name}
|
||||
</a>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</nav>
|
||||
);
|
||||
}
|
||||
|
||||
function Intro() {
|
||||
return (
|
||||
<section class={tw`max-w-screen-sm mx-auto my-16 px(4 sm:6 md:8)`}>
|
||||
<p class={tw`my-4 text-gray-600`}>
|
||||
Fresh is a next generation web framework, built for speed, reliability,
|
||||
and simplicity. Some stand out features:
|
||||
</p>
|
||||
<ul class={tw`my-4 text-gray-600 list-disc list-inside pl-4`}>
|
||||
<li>
|
||||
<b>Just-in-time rendering</b> on the edge.
|
||||
</li>
|
||||
<li>
|
||||
<b>Selective client hydration</b> for maximum interactivity.
|
||||
</li>
|
||||
<li>
|
||||
<b>Zero runtime overhead</b>: no JS is shipped to the client by
|
||||
default.
|
||||
</li>
|
||||
<li>
|
||||
<b>No build step</b>.
|
||||
</li>
|
||||
<li>
|
||||
<b>No configuration</b> necessary.
|
||||
</li>
|
||||
<li>
|
||||
<b>TypeScript support</b> out of the box.
|
||||
</li>
|
||||
</ul>
|
||||
<p class={tw`my-4 text-gray-600`}>
|
||||
Fresh embraces the tried and true design of server side rendering and
|
||||
processing.
|
||||
</p>
|
||||
</section>
|
||||
);
|
||||
}
|
||||
|
||||
function GettingStarted() {
|
||||
return (
|
||||
<section class={tw`max-w-screen-sm mx-auto my-16 px(4 sm:6 md:8)`}>
|
||||
<h3 id="getting-started" class={tw`text(xl gray-600) font-bold`}>
|
||||
<a href="#getting-started" class={tw`hover:underline`}>
|
||||
Getting started
|
||||
</a>
|
||||
</h3>
|
||||
<p class={tw`my-4 text-gray-600`}>
|
||||
To get started, make sure you have the{" "}
|
||||
<a href="https://deno.land" class={tw`text-blue-500 hover:underline`}>
|
||||
Deno CLI
|
||||
</a>{" "}
|
||||
installed.
|
||||
</p>
|
||||
<p class={tw`my-4 text-gray-600`}>
|
||||
Then, run the following command to install the `fresh` CLI:
|
||||
</p>
|
||||
<pre class={tw`overflow-x-auto py-2 px-4 bg(gray-100)`}>
|
||||
deno install -A -f --no-check -n fresh
|
||||
https://raw.githubusercontent.com/lucacasonato/fresh/main/cli.ts
|
||||
</pre>
|
||||
<p class={tw`my-4 text-gray-600`}>
|
||||
Once installed, you can use the `fresh` command to bootstrap a new
|
||||
project:
|
||||
</p>
|
||||
<pre class={tw`overflow-x-auto py-2 px-4 bg(gray-100)`}>
|
||||
fresh init my-app
|
||||
</pre>
|
||||
<p class={tw`my-4 text-gray-600`}>
|
||||
Enter the newly created project directory and run the following command
|
||||
to start the development server:
|
||||
</p>
|
||||
<pre class={tw`overflow-x-auto py-2 px-4 bg(gray-100)`}>
|
||||
deno run -A --watch main.ts
|
||||
</pre>
|
||||
<p class={tw`my-4 text-gray-600`}>
|
||||
You can now open{" "}
|
||||
<a
|
||||
href="http://localhost:8000"
|
||||
class={tw`text-blue-500 hover:underline`}
|
||||
>
|
||||
http://localhost:8000
|
||||
</a>{" "}
|
||||
in your browser to view the page.
|
||||
</p>
|
||||
<p class={tw`my-4 text-gray-600`}>
|
||||
A more in-depth getting started guide is available in{" "}
|
||||
<a href="/docs" class={tw`text-blue-500 hover:underline`}>the docs</a>.
|
||||
</p>
|
||||
</section>
|
||||
);
|
||||
}
|
||||
@@ -4,19 +4,11 @@
|
||||
|
||||
import * as $0 from "./pages/index.tsx";
|
||||
import * as $1 from "./pages/_render.ts";
|
||||
import * as $2 from "./pages/suspense.tsx";
|
||||
import * as $3 from "./pages/api/joke.ts";
|
||||
import * as $4 from "./pages/[name].tsx";
|
||||
import * as $5 from "./pages/x/[module].tsx";
|
||||
|
||||
const routes = {
|
||||
pages: {
|
||||
"./pages/index.tsx": $0,
|
||||
"./pages/_render.ts": $1,
|
||||
"./pages/suspense.tsx": $2,
|
||||
"./pages/api/joke.ts": $3,
|
||||
"./pages/[name].tsx": $4,
|
||||
"./pages/x/[module].tsx": $5,
|
||||
},
|
||||
baseUrl: import.meta.url,
|
||||
};
|
||||
|
Before Width: | Height: | Size: 18 KiB After Width: | Height: | Size: 18 KiB |
Reference in New Issue
Block a user