Skip to content

Commit 3533372

Browse files
committed
handle vertical margins in Post
1 parent 2b21b51 commit 3533372

File tree

10 files changed

+96
-44
lines changed

10 files changed

+96
-44
lines changed

docs/working-notes/todo3.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,5 +414,8 @@ fix content width
414414
migrate scroll to top and toast to react
415415
fix footer
416416
fix share, just small gray icons
417+
use vertical margins and margin collapsing for all vertical spacings, no paddings, when in same parent
418+
remove tag-lg, fix button size on mobile
419+
alert component style
417420
```
418421

src/components/Giscus.astro

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,31 @@
11
---
2+
import { cn } from '@/utils/styles';
23
4+
import type { HTMLAttributes } from 'astro/types';
5+
6+
export interface Props extends HTMLAttributes<'div'> {}
7+
8+
const { class: className } = Astro.props;
39
---
410

5-
<giscus-widget
6-
id="giscus-comments"
7-
repo="nemanjam/nemanjam.github.io"
8-
repoid="R_kgDOKc-LeA"
9-
category="General"
10-
categoryid="DIC_kwDOKc-LeM4CZ7UL"
11-
mapping="pathname"
12-
term="Comments are welcome"
13-
strict="0"
14-
reactionsenabled="1"
15-
emitmetadata="0"
16-
inputposition="bottom"
17-
theme="light"
18-
lang="en"
19-
crossorigin="anonymous"
20-
loading="lazy"></giscus-widget>
11+
<div class={cn('giscus', className)}>
12+
<giscus-widget
13+
id="giscus-comments"
14+
repo="nemanjam/nemanjam.github.io"
15+
repoid="R_kgDOKc-LeA"
16+
category="General"
17+
categoryid="DIC_kwDOKc-LeM4CZ7UL"
18+
mapping="pathname"
19+
term="Comments are welcome"
20+
strict="0"
21+
reactionsenabled="1"
22+
emitmetadata="0"
23+
inputposition="bottom"
24+
theme="light"
25+
lang="en"
26+
crossorigin="anonymous"
27+
loading="lazy"></giscus-widget>
28+
</div>
2129

2230
<script>
2331
import 'giscus';

src/components/PostListMore.astro

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
---
2-
import PostCardMore from './PostCardMore.astro';
2+
import PostCardMore from '@/components/PostCardMore.astro';
3+
import { cn } from '@/utils/styles';
34
45
import type { Post } from '@/types/post';
6+
import type { HTMLAttributes } from 'astro/types';
57
6-
export interface Props {
8+
export interface Props extends HTMLAttributes<'div'> {
79
morePosts: Post[];
810
}
911
10-
const { morePosts } = Astro.props;
12+
const { morePosts, class: className } = Astro.props;
1113
---
1214

13-
<div>
14-
<h2 class="b-h2">More posts</h2>
15+
<div class={cn(className)}>
16+
<h2 class="b-h2 mt-0">More posts</h2>
1517
<ul class="grid grid-cols-1 gap-6 sm:grid-cols-2 md:grid-cols-3">
1618
{
1719
morePosts.map((post) => (

src/components/PostMeta.astro

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@ import { ROUTES } from '@/constants/routes';
66
import { formatDate, formatDateIso } from '@/utils/datetime';
77
import { cn } from '@/utils/styles';
88
import { getCategoryProps } from '@/modules/post/category';
9+
import type { HTMLAttributes } from 'astro/types';
910
10-
interface Props {
11+
12+
13+
export interface Props extends HTMLAttributes<'p'> {
1114
publishDate: Date;
1215
category?: string;
1316
readingTime?: number;
1417
updatedDate?: Date;
15-
class?: string
1618
}
1719
1820
const { category, publishDate, updatedDate, readingTime, class: className } = Astro.props;

src/components/TableOfContents.astro

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,25 @@
11
---
22
import Link from '@/components/Link.astro';
3+
import { cn } from '@/utils/styles';
4+
5+
import type { HTMLAttributes } from 'astro/types';
36
47
export interface Heading {
58
text: string;
69
slug: string;
710
headings: Heading[];
811
}
912
10-
export interface Props {
13+
export interface Props extends HTMLAttributes<'aside'> {
1114
headings: Heading[];
1215
}
1316
14-
const { headings } = Astro.props as Props;
17+
const { headings, class: className } = Astro.props as Props;
1518
1619
const getHref = (slug: string) => `#${slug}`;
1720
---
1821

19-
<aside class="md:max-w-lg rounded-box border border-base-300 p-4 my-5 md:my-6 mx-auto">
22+
<aside class={cn('toc md:max-w-lg rounded-box border border-base-300 p-4 mx-auto', className)}>
2023
<h2 class="b-h2 mt-4">Table of contents</h2>
2124

2225
<ol class="ol-nested-decimal my-0">

src/layouts/Centered.astro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const props = Astro.props;
99
---
1010

1111
{/* flex here to take full height for pagination, flex-row align-stretch */}
12-
{/* h-full doent work without all parents h-full */}
12+
{/* h-full dosent work without all parents h-full */}
1313

1414
<Base {...props}>
1515
<main id="main" class="flex-grow flex flex-col centered-px max-w-4xl py-4 lg:py-8">

src/layouts/Post.astro

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,20 @@ const props = Astro.props;
1313
<figure class="centered max-w-4xl">
1414
<slot name="hero-image" />
1515
</figure>
16-
{/* hero custom without prose */}
17-
<section class="my-prose centered-px max-w-3xl pt-8 md:pt-12">
16+
17+
<section class="centered-px max-w-3xl b-h2-my">
1818
<slot name="hero-text" />
1919
</section>
20-
<section class="my-prose centered-px max-w-3xl">
20+
21+
<section class="my-prose centered-px max-w-3xl b-h2-my">
2122
<slot name="content" />
2223
</section>
23-
<section class="centered-px max-w-5xl">
24+
25+
<section class="centered-px max-w-3xl">
26+
<slot name="after-content" />
27+
</section>
28+
29+
<section class="centered-px max-w-5xl b-h2-mt">
2430
<slot name="more-posts" />
2531
</section>
2632
</article>

src/pages/blog/[slug].astro

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -88,34 +88,33 @@ const metadata: Metadata = { title, description, image };
8888
</Fragment>
8989

9090
<Fragment slot="hero-text">
91-
{/* title */}
92-
<h1>
91+
<h1 class="b-h1">
9392
{title}
9493
{draft && <sup class="text-red-500 ml-1">{draftText}</sup>}
9594
</h1>
9695

97-
{/* description */}
98-
{description && <h2 class="font-normal text-xl lg:text-2xl tracking-tight">{description}</h2>}
96+
{
97+
description && (
98+
<p class="font-normal text-captions text-xl md:text-2xl mb-6 md:mb-8">{description}</p>
99+
)
100+
}
99101

100-
{/* meta */}
101-
<PostMeta {...postMetaProps} class="not-prose" />
102+
<PostMeta {...postMetaProps} />
102103
</Fragment>
103104

104-
{/* section content */}
105105
<Fragment slot="content">
106-
{/* table of contents */}
107106
{toc && <TableOfContents headings={headings} />}
108107

109108
<Content />
109+
</Fragment>
110110

111-
<div
112-
class="flex justify-between items-start gap-4 flex-col md:flex-row mt-6 md:mt-8 mb-12 md:mb-16"
113-
>
111+
<Fragment slot="after-content">
112+
<div class="flex justify-between items-start gap-6 flex-col md:flex-row b-h2-mb">
114113
<TagList tags={tags} size="md" />
115114
<Share {title} {description} url={`${ROUTES.BLOG}${slug}`} />
116115
</div>
117116

118-
<Giscus />
117+
<Giscus class="b-h2-mt" />
119118
</Fragment>
120119

121120
<Fragment slot="more-posts">

src/styles/base/my-prose.css

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@
1919
/* image */
2020
@apply prose-img:rounded-button;
2121

22-
/* @apply outline outline-pink-500; */
22+
/* my custom components bellow */
23+
24+
/* vertical margins */
25+
.toc,
26+
.expressive-code,
27+
.alert {
28+
@apply b-p-my;
29+
}
2330
}
2431
}

src/styles/base/tags.css

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,26 @@
4242
@apply text-content;
4343
@apply text-base sm:text-lg;
4444
}
45+
46+
/* vertical margins (my-) */
47+
48+
/* like p */
49+
.b-p-my {
50+
@apply my-5 md:my-6;
51+
}
52+
53+
/* my- like h2 */
54+
.b-h2-my {
55+
@apply mt-12 md:mt-14 mb-6 md:mb-8;
56+
}
57+
58+
/* mt- first and last child */
59+
.b-h2-mt {
60+
@apply mt-12 md:mt-14;
61+
}
62+
63+
/* mb- */
64+
.b-h2-mb {
65+
@apply mb-6 md:mb-8;
66+
}
4567
}

0 commit comments

Comments
 (0)