From d960cbf6c7b61b76dbe25d7d7019f9c3f8d4c394 Mon Sep 17 00:00:00 2001 From: nyaomaru Date: Sat, 28 Sep 2024 09:21:56 +0900 Subject: [PATCH] refactor: pages heading --- src/components/Heading.tsx | 58 ++++++++++++++++++++++++++++++ src/routes/about.tsx | 19 +++++----- src/routes/chart.tsx | 3 +- src/routes/countdown.tsx | 1 + src/routes/greet/[name].tsx | 3 +- src/routes/index.tsx | 24 ++++++------- src/routes/map.tsx | 6 +++- src/routes/markdowns/[slug].tsx | 14 +++++--- src/routes/partials/about/[id].tsx | 3 +- src/routes/projects/[id].tsx | 9 +++-- src/routes/search.tsx | 3 +- 11 files changed, 111 insertions(+), 32 deletions(-) create mode 100644 src/components/Heading.tsx diff --git a/src/components/Heading.tsx b/src/components/Heading.tsx new file mode 100644 index 0000000..8825751 --- /dev/null +++ b/src/components/Heading.tsx @@ -0,0 +1,58 @@ +import { JSX } from "preact"; + +type HeadingProps = { + variant: "h1" | "h2" | "h3" | "h4" | "h5" | "h6"; + text: string; +} & JSX.HTMLAttributes; + +export function Heading({ variant, text, ...props }: HeadingProps) { + if (variant === "h1") { + return ( +

+ {text} +

+ ); + } + + if (variant === "h2") { + return ( +

+ {text} +

+ ); + } + + if (variant === "h3") { + return ( +

+ {text} +

+ ); + } + + if (variant === "h4") { + return ( +

+ {text} +

+ ); + } + + if (variant === "h5") { + return ( +
+ {text} +
+ ); + } + + if (variant === "h6") { + return ( +
+ {text} +
+ ); + } + + return
; +} diff --git a/src/routes/about.tsx b/src/routes/about.tsx index 3b3045e..98c7893 100644 --- a/src/routes/about.tsx +++ b/src/routes/about.tsx @@ -1,6 +1,7 @@ import { Handlers, PageProps, RouteContext } from "$fresh/server.ts"; import { Partial } from "$fresh/runtime.ts"; import NextContentButton from "#src/islands/NextContentButton.tsx"; +import { Heading } from "#src/components/Heading.tsx"; import { PageLayout } from "#src/components/PageLayout.tsx"; const loadFooValue = () => { @@ -34,14 +35,16 @@ export default async function AboutPage(props: PageProps, ctx: RouteContext) { return (
-

About

-

This is the about page.

- -
You are on the page '{props.url.href}'.
-

foo is: {value}

-
-
- + +
+

This is the about page.

+ +
You are on the page '{props.url.href}'.
+

foo is: {value}

+
+
+ +
diff --git a/src/routes/chart.tsx b/src/routes/chart.tsx index 0b67685..b21c2dd 100644 --- a/src/routes/chart.tsx +++ b/src/routes/chart.tsx @@ -1,5 +1,6 @@ import ChartIsland from "#src/islands/Chart.tsx"; import { ChartColors } from "$fresh_charts/utils.ts"; +import { Heading } from "#src/components/Heading.tsx"; import { PageLayout } from "#src/components/PageLayout.tsx"; const createRandomNumber = () => { @@ -13,7 +14,7 @@ const createChartNumberArray = () => { export default function Home() { return ( -

Chart

+
{ date.setHours(date.getHours() + 1); return ( +

Count Down

The big event is happening . diff --git a/src/routes/greet/[name].tsx b/src/routes/greet/[name].tsx index fde67a7..e542b42 100644 --- a/src/routes/greet/[name].tsx +++ b/src/routes/greet/[name].tsx @@ -1,5 +1,6 @@ import { Head } from "$fresh/runtime.ts"; import { PageProps, RouteConfig } from "$fresh/server.ts"; +import { Heading } from "#src/components/Heading.tsx"; import { PageLayout } from "#src/components/PageLayout.tsx"; export const config: RouteConfig = { @@ -16,7 +17,7 @@ export default function GreetPage(props: PageProps) {

-

Greetings to you, {name}!

+

This page is not{" "} applied layout because I want to check ignore layout config. diff --git a/src/routes/index.tsx b/src/routes/index.tsx index 77f0b00..05a5baf 100644 --- a/src/routes/index.tsx +++ b/src/routes/index.tsx @@ -1,6 +1,7 @@ import { Handlers, PageProps, RouteConfig } from "$fresh/server.ts"; import { type ContentSecurityPolicy, useCSP } from "$fresh/runtime.ts"; import { useSignal } from "@preact/signals"; +import { Heading } from "#src/components/Heading.tsx"; import { Link } from "#src/components/Link.tsx"; import Counter from "#src/islands/Counter.tsx"; @@ -59,15 +60,16 @@ export default function Home({ data }: PageProps) { src="/logo.svg" alt="the Fresh logo: a sliced lemon dripping with juice" /> -

Nyaomaru Deno Sample

-

I am a cat being!!

-
-
-

- Counter -

+
+ +
+

I am a cat being!!

+
+ +
+

@@ -77,17 +79,15 @@ export default function Home({ data }: PageProps) {

-
-

- Page Buttons -

+
+
-
+
{ return ( - + +
+ +
); }); diff --git a/src/routes/markdowns/[slug].tsx b/src/routes/markdowns/[slug].tsx index d4293e1..161e8ea 100644 --- a/src/routes/markdowns/[slug].tsx +++ b/src/routes/markdowns/[slug].tsx @@ -2,6 +2,7 @@ import { Handlers, PageProps } from "$fresh/server.ts"; import { extract } from "$std/front_matter/yaml.ts"; import { CSS, render } from "$gfm"; import { Head } from "$fresh/runtime.ts"; +import { Heading } from "#src/components/Heading.tsx"; import { PageLayout } from "#src/components/PageLayout.tsx"; const markdownText = `--- @@ -64,11 +65,14 @@ export default function MarkdownPage({ data }: PageProps) {
-
{JSON.stringify(data.data)}
-
+ +
+
{JSON.stringify(data.data)}
+
+
diff --git a/src/routes/partials/about/[id].tsx b/src/routes/partials/about/[id].tsx index fbdf14a..47e45cc 100644 --- a/src/routes/partials/about/[id].tsx +++ b/src/routes/partials/about/[id].tsx @@ -1,5 +1,6 @@ import { defineRoute, RouteConfig } from "$fresh/server.ts"; import { Partial } from "$fresh/runtime.ts"; +import { Heading } from "#src/components/Heading.tsx"; const contents = [ "This is the documentation page. It should contain all the \n information you need to get started with the project.", @@ -11,7 +12,7 @@ const loadContent = (id: string) => { return (
-

Documentation: {id}

+

{currentContent}

diff --git a/src/routes/projects/[id].tsx b/src/routes/projects/[id].tsx index 80768c8..9c02d6e 100644 --- a/src/routes/projects/[id].tsx +++ b/src/routes/projects/[id].tsx @@ -1,4 +1,5 @@ import { Handlers, PageProps } from "$fresh/server.ts"; +import { Heading } from "#src/components/Heading.tsx"; import { PageLayout } from "#src/components/PageLayout.tsx"; const projects = [{ id: 1, name: "Project 1", stars: 10 }, { @@ -36,8 +37,12 @@ export default function ProjectPage(props: PageProps) { return ( -

{props.data.name}

-

{props.data.stars} stars

+ + +
+ +

{props.data.stars} stars

+
); } diff --git a/src/routes/search.tsx b/src/routes/search.tsx index 48cfcf7..1571f1d 100644 --- a/src/routes/search.tsx +++ b/src/routes/search.tsx @@ -1,4 +1,5 @@ import { Handlers, PageProps } from "$fresh/server.ts"; +import { Heading } from "#src/components/Heading.tsx"; import { PageLayout } from "#src/components/PageLayout.tsx"; const NAMES = ["Alice", "Bob", "Charlie", "Dave", "Eve", "Frank"]; @@ -21,7 +22,7 @@ export default function Page({ data }: PageProps) { const { results, query } = data; return ( -

Search

+