Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to add a CSS file to all pages as the default header ? #371

Closed
razvn opened this issue Jul 2, 2022 · 4 comments
Closed

How to add a CSS file to all pages as the default header ? #371

razvn opened this issue Jul 2, 2022 · 4 comments

Comments

@razvn
Copy link

razvn commented Jul 2, 2022

Hi.

New to Fresh and new to Preact so maybe the question is trivial but, I can't figure out how to customized the main html file in order to include a css valid for all site.

Thanks

@ajf-sa
Copy link
Contributor

ajf-sa commented Jul 2, 2022

make components as layout to wrap the route with children in fresh some thing like this

// componets/layout/container.tsx

/** @jsx h */
/** @jsxFrag Fragment */
import { ComponentChildren, Fragment, h } from "preact";
import { tw } from "@twind";
import { Head } from "https://deno.land/x/[email protected]/runtime.ts";
import Footer from "../../components/Footer.tsx";

export type Props = {
  children: ComponentChildren;
  title?: string;
  name?: string;
  description?: string;
};

export const Container = ({ children, ...customMeta }: Props) => {
  return (
    <>
      <div style={{ minHeight: "100vh" }}>
        <Seo {...customMeta} />
        <div className="container">{children}</div>
        <Footer />
      </div>
    </>
  );
};

const Seo = ({ ...customMeta }) => {
  const meta = {
    title: " بحوث عروض برمجة",
    description: "بحوث عروض برمجة تصميم تصوير مونتاج",
    type: "website",
    ...customMeta,
  };

  return (
    <Head>
      <title>{meta.title}</title>
      <meta content={meta.description} name="description" />
      <link rel="icon" href="/favicon.ico" />
 {/* 
    add javascript css what ever you want
  */}
    </Head>
  );
};

and in routes you can use container components to warp as layout

// routes/index.tsx

import { Container } from "../components/layouts/container.tsx";
export default function Home(props: PageProps<H>) {
  const meta = {
    title: "Some Meta Title",
    description: "I am a description, and I can create multiple tags",
    canonical: "http://example.com/path/to/page",
    meta: {
      charset: "utf-8",
      name: {
        keywords: "react,meta,document,html,tags",
      },
    },
  };
  return (
    <>
      <Container {...meta}>
       
         <h1>fresh is really fresh</h1>
      
      </Container>
    </>
  );
}

I hope this help you

@razvn
Copy link
Author

razvn commented Jul 3, 2022

Thank you very helpful.

@HaQadosch
Copy link

When I try the example, <Head> is being ignored. 🤷🏻
It does work if I import it this way

import { Head } from "$fresh/runtime.ts";

@lucacasonato
Copy link
Member

@HaQadosch Yes, you should import it like that.

Closing this as the example works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants