Skip to content

Commit f47ebfe

Browse files
committed
chore: add post details
1 parent 57312b4 commit f47ebfe

File tree

7 files changed

+40
-31
lines changed

7 files changed

+40
-31
lines changed

.changeset/funny-ghosts-allow.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"r.obin.ch": patch
3+
---
4+
5+
Add post details

src/components/Details.astro

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,19 @@
22
33
type Props = {
44
defaultOpen?: boolean;
5+
title?: string;
56
}
67
7-
const { defaultOpen = false } = Astro.props;
8+
const { defaultOpen = false, title } = Astro.props;
89
910
---
1011

11-
<details open={defaultOpen} data-default-open={defaultOpen}>
12-
<summary><slot name="title" /></summary>
12+
<details data-default-open={defaultOpen}>
13+
<summary>
14+
<slot name="title">
15+
{title}
16+
</slot>
17+
</summary>
1318
<div class="content">
1419
<slot />
1520
</div>
@@ -52,17 +57,19 @@ const { defaultOpen = false } = Astro.props;
5257
</style>
5358

5459
<script>
55-
const details = document.querySelectorAll('details') as NodeListOf<HTMLDetailsElement>;
5660
const matchQuery = window.matchMedia('(max-width: 1280px)');
5761

58-
matchQuery.addEventListener('change', () => {
62+
const handleBreakpoint = () => {
63+
const details = document.querySelectorAll('details') as NodeListOf<HTMLDetailsElement>;
5964
details.forEach(detail => {
6065
if (matchQuery.matches) {
6166
detail.removeAttribute('open');
6267
} else {
6368
detail.dataset.defaultOpen === 'true' && detail.setAttribute('open', '');
6469
}
6570
});
66-
});
71+
};
72+
document.addEventListener('astro:page-load', handleBreakpoint);
73+
matchQuery.addEventListener('change', handleBreakpoint);
6774

6875
</script>

src/components/TableOfContents.astro

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,7 @@ const t = useTranslations(locale);
9393
});
9494
</script>
9595

96-
<Details defaultOpen={true}>
97-
<span class="label" slot="title">{t("tableOfContentsLabel")}</span>
96+
<Details defaultOpen={true} title={t("tableOfContentsLabel")}>
9897
<nav class="table-of-contents">
9998
<ul>
10099
{

src/components/GitInfo.astro renamed to src/components/VersioningDetails.astro

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,8 @@ const t = useTranslations(locale);
1313
1414
---
1515

16-
<Details>
17-
<span class="label" slot="title">{t('gitInfoLabel')}</span>
16+
<Details title={t('versioningLabel')}>
1817
<dl>
19-
<slot name="before" />
2018
{gitInfo?.lastCommit && (
2119
<dt>{t('authorLabel')}</dt>
2220
<dd>{gitInfo.lastCommit.authorName}</dd>
@@ -29,6 +27,5 @@ const t = useTranslations(locale);
2927
<Button href={gitInfo.remoteEditUrl}>{t('editLabel')}</Button>
3028
</dd>
3129
)}
32-
<slot name="after" />
3330
</dl>
3431
</Details>

src/layouts/DefaultLayout.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ footer {
269269
padding-right: var(--padding-page);
270270
}
271271

272-
:is(#topbar, header, footer) a {
272+
body > :is(#topbar, header, footer) a {
273273
text-decoration: none;
274274
color: var(--color-white);
275275
}

src/pages/[...locale]/[blog]/[...slug].astro

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
---
22
import DefaultLayout from "../../../layouts/DefaultLayout.astro";
33
import TableOfContents from "../../../components/TableOfContents.astro";
4-
import GitInfo from "../../../components/GitInfo.astro";
54
import { getGitInfo } from "../../../remark/remark-git-info";
65
import { parseLocale, useTranslations } from "../../../utils/i18n";
76
import Comments from "../../../components/Comments.astro";
@@ -20,6 +19,8 @@ import {
2019
} from "../../../utils/paths";
2120
import ArticleWithAside from "../../../layouts/pages/ArticleWithAside.astro";
2221
import DateTime from "../../../components/DateTime.astro";
22+
import VersioningDetails from "../../../components/VersioningDetails.astro";
23+
import Details from "../../../components/Details.astro";
2324
2425
export const getStaticPaths = async () => {
2526
const routePattern = "[...locale]/[blog]/[...slug]";
@@ -61,22 +62,18 @@ const t = useTranslations(parseLocale(locale));
6162
<Comments />
6263
<Fragment slot="title">
6364
<h1>{title}</h1>
64-
{publishedAt && <DateTime date={publishedAt} />}
6565
</Fragment>
6666
<Fragment slot="aside">
6767
<TableOfContents headings={headings} />
68-
<GitInfo gitInfo={gitInfo}>
69-
<Fragment slot="after">
70-
<dt>{t("tagsLabel")}</dt>
71-
<dd>
72-
{
73-
tags.map((tag) => (
74-
<a href={resolvePath(blogPath, slug(tag))}>{tag}</a>
75-
))
76-
}
77-
</dd>
78-
</Fragment>
79-
</GitInfo>
68+
<Details defaultOpen title={t("detailsLabel")}>
69+
<dl>
70+
<dt>{t("createdAtLabel")}</dt>
71+
<dd><DateTime date={publishedAt} /></dd>
72+
<dt>{t("categorizedWithLabel")}</dt>
73+
<dd>{tags.map((tag) => <a href={resolvePath(blogPath, slug(tag))}>{tag}</a>)}</dd>
74+
</dl>
75+
</Details>
76+
<VersioningDetails gitInfo={gitInfo} />
8077
</Fragment>
8178
</ArticleWithAside>
8279
</DefaultLayout>

src/site.config.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,10 @@ export const C = {
3030
searchPlaceholder: "Tippe um zu suchen...",
3131
searchLoading: "Suche läuft...",
3232
tableOfContentsLabel: "Inhaltsverzeichnis",
33-
tagsLabel: "Kategorien",
34-
gitInfoLabel: "Zusatzinformationen",
33+
detailsLabel: "Details",
34+
categorizedWithLabel: "Kategorisiert mit",
35+
createdAtLabel: "Erstellt am",
36+
versioningLabel: "Versionierung",
3537
authorLabel: "Autor",
3638
lastUpdatedLabel: "Letzte Aktualisierung",
3739
linksLabel: "Links",
@@ -62,8 +64,10 @@ export const C = {
6264
searchPlaceholder: "Type to search...",
6365
searchLoading: "Searching...",
6466
tableOfContentsLabel: "Table of Contents",
65-
tagsLabel: "Tags",
66-
gitInfoLabel: "Meta information",
67+
detailsLabel: "Details",
68+
categorizedWithLabel: "Categorized with",
69+
createdAtLabel: "Created at",
70+
versioningLabel: "Versioning",
6771
authorLabel: "Author",
6872
lastUpdatedLabel: "Last updated",
6973
linksLabel: "Links",

0 commit comments

Comments
 (0)