From 871985a172724edc4499dfb12697e54d037a1989 Mon Sep 17 00:00:00 2001 From: Luca Casonato Date: Tue, 21 Jun 2022 17:08:41 +0200 Subject: [PATCH] www: add redirect for init script (#266) --- README.md | 2 +- docs/getting-started/create-a-project.md | 2 +- www/routes/index.tsx | 24 ++++++++++++++++++++---- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index cec48872..968c5d28 100644 --- a/README.md +++ b/README.md @@ -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: ```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`: diff --git a/docs/getting-started/create-a-project.md b/docs/getting-started/create-a-project.md index df3e3579..b780e3bc 100644 --- a/docs/getting-started/create-a-project.md +++ b/docs/getting-started/create-a-project.md @@ -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: ``` -$ 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. Project created! diff --git a/www/routes/index.tsx b/www/routes/index.tsx index ce949c3a..0ad43d7b 100644 --- a/www/routes/index.tsx +++ b/www/routes/index.tsx @@ -2,13 +2,28 @@ /** @jsxFrag Fragment */ import { ComponentChildren, Fragment, h } from "preact"; 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 Counter from "../islands/Counter.tsx"; import LemonDrop from "../islands/LemonDrop.tsx"; import Footer from "../components/Footer.tsx"; import WarningBanner from "../components/WarningBanner.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 DESCRIPTION = @@ -16,6 +31,7 @@ const DESCRIPTION = export default function MainPage(props: PageProps) { const ogImageUrl = new URL(asset("/home-og.png"), props.url).href; + const origin = `${props.url.protocol}//${props.url.host}`; return ( <> @@ -30,7 +46,7 @@ export default function MainPage(props: PageProps) { - +