www: add redirect for init script (#266)

This commit is contained in:
Luca Casonato
2022-06-21 15:08:41 +00:00
committed by GitHub
parent 1a10cbda3a
commit 871985a172
3 changed files with 22 additions and 6 deletions
+1 -1
View File
@@ -35,7 +35,7 @@ You can scaffold a new project by running the Fresh init script. To scaffold a
project in the `myproject` folder, run the following: project in the `myproject` folder, run the following:
```sh ```sh
deno run -A https://raw.githubusercontent.com/lucacasonato/fresh/main/init.ts my-project deno run -A https://fresh.deno.dev my-project
``` ```
To now start the project, use `deno task`: To now start the project, use `deno task`:
+1 -1
View File
@@ -10,7 +10,7 @@ will scaffold out a new project with some example files to get you started.
To create a new project in the directory `"my-project"`, run: To create a new project in the directory `"my-project"`, run:
``` ```
$ deno run -A https://raw.githubusercontent.com/lucacasonato/fresh/main/init.ts my-project $ deno run -A https://fresh.deno.dev my-project
The manifest has been generated for 3 routes and 1 islands. The manifest has been generated for 3 routes and 1 islands.
Project created! Project created!
+20 -4
View File
@@ -2,13 +2,28 @@
/** @jsxFrag Fragment */ /** @jsxFrag Fragment */
import { ComponentChildren, Fragment, h } from "preact"; import { ComponentChildren, Fragment, h } from "preact";
import { asset, Head } from "$fresh/runtime.ts"; import { asset, Head } from "$fresh/runtime.ts";
import { PageProps } from "$fresh/server.ts"; import { Handlers, PageProps } from "$fresh/server.ts";
import { tw } from "../utils/twind.ts"; import { tw } from "../utils/twind.ts";
import Counter from "../islands/Counter.tsx"; import Counter from "../islands/Counter.tsx";
import LemonDrop from "../islands/LemonDrop.tsx"; import LemonDrop from "../islands/LemonDrop.tsx";
import Footer from "../components/Footer.tsx"; import Footer from "../components/Footer.tsx";
import WarningBanner from "../components/WarningBanner.tsx"; import WarningBanner from "../components/WarningBanner.tsx";
import { Leaf } from "../components/Icons.tsx"; import { Leaf } from "../components/Icons.tsx";
import VERSIONS from "../../versions.json" assert { type: "json" };
export const handler: Handlers = {
GET(req, ctx) {
const accept = req.headers.get("accept");
if (accept && !accept.includes("text/html")) {
const path = `/@${VERSIONS[0]}/init.ts`;
return new Response(`Redirecting to ${path}`, {
headers: { "Location": path },
status: 307,
});
}
return ctx.render();
},
};
const TITLE = "fresh - The next-gen web framework."; const TITLE = "fresh - The next-gen web framework.";
const DESCRIPTION = const DESCRIPTION =
@@ -16,6 +31,7 @@ const DESCRIPTION =
export default function MainPage(props: PageProps) { export default function MainPage(props: PageProps) {
const ogImageUrl = new URL(asset("/home-og.png"), props.url).href; const ogImageUrl = new URL(asset("/home-og.png"), props.url).href;
const origin = `${props.url.protocol}//${props.url.host}`;
return ( return (
<> <>
@@ -30,7 +46,7 @@ export default function MainPage(props: PageProps) {
</Head> </Head>
<Hero /> <Hero />
<Intro /> <Intro />
<GettingStarted /> <GettingStarted origin={origin} />
<Example /> <Example />
<Footer /> <Footer />
</> </>
@@ -138,7 +154,7 @@ function Intro() {
); );
} }
function GettingStarted() { function GettingStarted(props: { origin: string }) {
return ( return (
<section <section
class={tw`max-w-screen-sm mx-auto my-16 px(4 sm:6 md:8) space-y-4`} class={tw`max-w-screen-sm mx-auto my-16 px(4 sm:6 md:8) space-y-4`}
@@ -160,7 +176,7 @@ function GettingStarted() {
Then you can use the Fresh init script to bootstrap a new project: Then you can use the Fresh init script to bootstrap a new project:
</p> </p>
<pre class={tw`overflow-x-auto py-2 px-4 bg(gray-100)`}> <pre class={tw`overflow-x-auto py-2 px-4 bg(gray-100)`}>
{"deno run -A https://raw.githubusercontent.com/lucacasonato/fresh/main/init.ts my-app"} {`deno run -A ${props.origin} my-app`}
</pre> </pre>
<p class={tw`text-gray-600`}> <p class={tw`text-gray-600`}>
Enter the newly created project directory and run the following command Enter the newly created project directory and run the following command