Skip to content

Commit

Permalink
refactor(layout): generalize LayoutPage
Browse files Browse the repository at this point in the history
  • Loading branch information
LuanRoger committed Apr 13, 2024
1 parent b653e08 commit b3d42c2
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 50 deletions.
99 changes: 63 additions & 36 deletions src/layouts/LayoutBase.astro
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@ import "@fontsource/jetbrains-mono";
import { ViewTransitions } from "astro:transitions";
import BackToTopButton from "../components/BackToTopButton.astro";
import '@/styles/global.css'
import "@/styles/global.css";
interface Props {
title: string;
bttEnable: boolean;
metaDescription?: string;
bttEnable?: boolean | undefined;
metaDescription?: string | undefined;
className?: string | undefined;
}
const { title, bttEnable, metaDescription } = Astro.props;
const { title, bttEnable = false, metaDescription, className } = Astro.props;
---

<html lang="pt-BR">
Expand All @@ -24,48 +25,74 @@ const { title, bttEnable, metaDescription } = Astro.props;
<link rel="icon" href="/favicon/favicon.ico" />
<link rel="icon" type="image/x-icon" href="/favicon/favicon.ico" />
<link rel="shortcut icon" href="/favicon/favicon.ico" />
<link rel="icon" type="image/png" sizes="16x16" href="/favicon/favicon16.png" />
<link rel="icon" type="image/png" sizes="32x32" href="/favicon/favicon32.png" />
<link rel="icon" type="image/png" sizes="32x32" href="/favicon/favicon32.png" />
<link rel="icon" type="image/png" sizes="192x192" href="/favicon/android-chrome192.png" />
<link rel="icon" type="image/png" sizes="512x512" href="/favicon/android-chrome512.png" />
<link
rel="icon"
type="image/png"
sizes="16x16"
href="/favicon/favicon16.png"
/>
<link
rel="icon"
type="image/png"
sizes="32x32"
href="/favicon/favicon32.png"
/>
<link
rel="icon"
type="image/png"
sizes="32x32"
href="/favicon/favicon32.png"
/>
<link
rel="icon"
type="image/png"
sizes="192x192"
href="/favicon/android-chrome192.png"
/>
<link
rel="icon"
type="image/png"
sizes="512x512"
href="/favicon/android-chrome512.png"
/>
<meta name="viewport" content="width=device-width" />
<meta name="generator" content={Astro.generator} />
<meta name="description" content={metaDescription ??
"Blog de tecnologia com conteúdo técnico sobre programação e software."} />
<meta
name="description"
content={metaDescription ??
"Blog de tecnologia com conteúdo técnico sobre programação e software."}
/>
<title>{title}</title>
<ViewTransitions/>
<ViewTransitions />
</head>
<body>
<div class="p-7">
<TopBar />
<NavBar />
<main>
<main class={className}>
<slot />
<BackToTopButton enable={bttEnable}/>
</main>
<BackToTopButton enable={bttEnable} />
</div>
<Footer />
</body>
</html>

<script>
import { getCurrentThemeMode } from "../scripts/theme";
</body><script>
import { getCurrentThemeMode } from "../scripts/theme";

document.addEventListener("astro:after-swap", () => {
const currentTheme = getCurrentThemeMode();
if (currentTheme === "dark") {
document.documentElement.classList.add("dark");
} else {
document.documentElement.classList.remove("dark");
}
})
document.addEventListener("astro:page-load", () => {
const currentTheme = getCurrentThemeMode();
if (currentTheme === "dark") {
document.documentElement.classList.add("dark");
} else {
document.documentElement.classList.remove("dark");
}
})
</script>
document.addEventListener("astro:after-swap", () => {
const currentTheme = getCurrentThemeMode();
if (currentTheme === "dark") {
document.documentElement.classList.add("dark");
} else {
document.documentElement.classList.remove("dark");
}
});
document.addEventListener("astro:page-load", () => {
const currentTheme = getCurrentThemeMode();
if (currentTheme === "dark") {
document.documentElement.classList.add("dark");
} else {
document.documentElement.classList.remove("dark");
}
});
</script>
</html>
23 changes: 13 additions & 10 deletions src/layouts/LayoutPage.astro
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,20 @@
import LayoutBase from "./LayoutBase.astro";
interface Props {
title?: string
title?: string | undefined;
bttEnabled?: boolean | undefined;
metaDescription?: string | undefined;
}
const { title } = Astro.props
const defaultTitle = "LR Tech Blog"
const { title, bttEnabled, metaDescription } = Astro.props;
const defaultTitle = "LR Tech Blog";
---

<LayoutBase title={title ?? defaultTitle} bttEnable={false} >
<div class="mx-10">
<main>
<slot/>
</main>
</div>
</LayoutBase>
<LayoutBase
title={title ?? defaultTitle}
bttEnable={bttEnabled}
metaDescription={metaDescription}
className="px-10"
>
<slot />
</LayoutBase>
6 changes: 3 additions & 3 deletions src/layouts/PostLayout.astro → src/layouts/LayoutPost.astro
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
import LayoutBase from "./LayoutBase.astro";
import LayoutPage from "./LayoutPage.astro";
import Prose from "../components/Prose.astro";
import type { AuthorProfile, PostData } from "../scripts/types/post_types";
import PostSideBarLeft from "../components/PostShareSection.astro";
Expand All @@ -22,7 +22,7 @@ const { minutesRead } = remark;
const formatedDate = date.toLocaleDateString("pt-br");
---

<LayoutBase title={title} bttEnable metaDescription={description}>
<LayoutPage title={title} bttEnabled={true} metaDescription={description}>
<div class="flex flex-col gap-5 mb-5">
<PostSideBarLeft />
<header class="flex flex-col">
Expand All @@ -48,4 +48,4 @@ const formatedDate = date.toLocaleDateString("pt-br");
<slot />
</Prose>
</article>
</LayoutBase>
</LayoutPage>
2 changes: 1 addition & 1 deletion src/pages/post/[slug].astro
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
import PostLayout from "../../layouts/PostLayout.astro";
import PostLayout from "../../layouts/LayoutPost.astro";
import { type CollectionEntry, getEntry } from "astro:content"
import type { AuthorProfile, PostData } from "../../scripts/types/post_types";
import { getPosts } from "../../scripts/content_fetcher";
Expand Down

0 comments on commit b3d42c2

Please sign in to comment.