Skip to content

Commit eb5cbf4

Browse files
authored
refactor: extract redundant max-width into utility (satnaing#525)
* refactor: extract redundant max-width into utility Extract redundant max-width into a universal tailwind utility class. By doing so, the width of the layout in different pages can be customized easily. * docs: update docs for modifying `max-w-app` utility
1 parent 35f5926 commit eb5cbf4

10 files changed

Lines changed: 27 additions & 10 deletions

File tree

src/components/BackButton.astro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { SITE } from "@/config";
66

77
{
88
SITE.showBackButton && (
9-
<div class="mx-auto flex w-full max-w-3xl items-center justify-start px-2">
9+
<div class="mx-auto flex w-full max-w-app items-center justify-start px-2">
1010
<LinkButton
1111
id="back-button"
1212
href="/"

src/components/Breadcrumb.astro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ if (breadcrumbList[0] === "tags" && !isNaN(Number(breadcrumbList[2]))) {
2323
}
2424
---
2525

26-
<nav class="mx-auto mt-8 mb-1 w-full max-w-3xl px-4" aria-label="breadcrumb">
26+
<nav class="mx-auto mt-8 mb-1 w-full max-w-app px-4" aria-label="breadcrumb">
2727
<ul
2828
class="font-light [&>li]:inline [&>li:not(:last-child)>a]:hover:opacity-100"
2929
>

src/components/Header.astro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const isActive = (path: string) => {
3333
</a>
3434
<div
3535
id="nav-container"
36-
class="mx-auto flex max-w-3xl flex-col items-center justify-between sm:flex-row"
36+
class="mx-auto flex max-w-app flex-col items-center justify-between sm:flex-row"
3737
>
3838
<div
3939
id="top-nav-wrap"

src/components/Hr.astro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ export interface Props {
77
const { noPadding = false, ariaHidden = true } = Astro.props;
88
---
99

10-
<div class={`max-w-3xl mx-auto ${noPadding ? "px-0" : "px-4"}`}>
10+
<div class:list={["mx-auto max-w-app", noPadding ? "px-0" : "px-4"]}>
1111
<hr class="border-border" aria-hidden={ariaHidden} />
1212
</div>

src/data/blog/how-to-configure-astropaper-theme.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,19 @@ Here are SITE configuration options
6969
| `lang` | Used as HTML ISO Language code in `<html lang"en">`. Default is `en`. |
7070
| `timezone` | This option allows you to specify your timezone using the [IANA format](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones). Setting this ensures consistent timestamps across your localhost and deployed site, eliminating time differences. |
7171

72+
## Update layout width
73+
74+
The default `max-width` for the entire blog is `768px` (`max-w-3xl`). If you'd like to change it, you can easily update the `max-w-app` utility in your `src/styles/global.css` file:
75+
76+
```css
77+
@utility max-w-app {
78+
@apply max-w-4xl xl:max-w-5xl;
79+
/* eg: max-w-4xl xl:max-w-5xl */
80+
}
81+
```
82+
83+
You can explore more `max-width` values in the [Tailwind CSS docs](https://tailwindcss.com/docs/max-width).
84+
7285
## Configuring logo or title
7386

7487
Prior to AstroPaper v5, you can update your site name/logo in `LOGO_IMAGE` object inside `src/config.ts` file. However, in AstroPaper v5, this option has been removed in favor of Astro's built-in SVG and Image components.

src/layouts/AboutLayout.astro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const { frontmatter } = Astro.props;
1919
<Header />
2020
<Breadcrumb />
2121
<main id="main-content">
22-
<section id="about" class="prose mb-28 max-w-3xl prose-img:border-0">
22+
<section id="about" class="prose mb-28 max-w-app prose-img:border-0">
2323
<h1 class="text-2xl tracking-wider sm:text-3xl">{frontmatter.title}</h1>
2424
<slot />
2525
</section>

src/layouts/Main.astro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const backUrl = SITE.showBackButton ? Astro.url.pathname : "/";
2424
<main
2525
data-backUrl={backUrl}
2626
id="main-content"
27-
class="mx-auto w-full max-w-3xl px-4 pb-4"
27+
class="mx-auto w-full max-w-app px-4 pb-4"
2828
>
2929
{
3030
"titleTransition" in props ? (

src/layouts/PostDetails.astro

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ const nextPost =
8787
<main
8888
id="main-content"
8989
class:list={[
90-
"mx-auto w-full max-w-3xl px-4 pb-12",
90+
"mx-auto w-full max-w-app px-4 pb-12",
9191
{ "mt-8": !SITE.showBackButton },
9292
]}
9393
data-pagefind-body
@@ -102,7 +102,7 @@ const nextPost =
102102
<Datetime {pubDatetime} {modDatetime} {timezone} size="lg" class="my-2" />
103103
<EditPost class="max-sm:hidden" {hideEditPost} {post} />
104104
</div>
105-
<article id="article" class="mx-auto prose mt-8 max-w-3xl">
105+
<article id="article" class="mx-auto prose mt-8 max-w-app">
106106
<Content />
107107
</article>
108108

src/pages/404.astro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { SITE } from "@/config";
1111

1212
<main
1313
id="main-content"
14-
class="mx-auto flex max-w-3xl flex-1 items-center justify-center"
14+
class="mx-auto flex max-w-app flex-1 items-center justify-center"
1515
>
1616
<div class="mb-14 flex flex-col items-center justify-center">
1717
<h1 class="text-9xl font-bold text-accent">404</h1>

src/styles/global.css

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,14 @@ html[data-theme="dark"] {
5050
}
5151
section,
5252
footer {
53-
@apply mx-auto max-w-3xl px-4;
53+
@apply mx-auto max-w-app px-4;
5454
}
5555
}
5656

57+
@utility max-w-app {
58+
@apply max-w-3xl;
59+
}
60+
5761
.active-nav {
5862
@apply underline decoration-wavy decoration-2 underline-offset-4;
5963
}

0 commit comments

Comments
 (0)