Skip to content

Commit 5f7cff5

Browse files
Style for docs
1 parent cc8e14a commit 5f7cff5

8 files changed

Lines changed: 160 additions & 39 deletions

File tree

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import Link from 'next/link'
2+
import { readDocuments } from '@/db/api/documents'
3+
import classes from './page.module.css'
4+
5+
const NewsLayout = async ({ children }: { children: React.ReactNode }) => {
6+
const documents = await readDocuments()
7+
8+
return (
9+
<div className={classes.layout}>
10+
<div className={classes.container}>{children}</div>
11+
<div className={classes.sidebar}>
12+
<ul className={classes.list}>
13+
{documents.map((document) => (
14+
<li key={document.id} className={classes.item}>
15+
<Link
16+
title={document.title}
17+
className={classes.link}
18+
href={`/news/${document.id}`}
19+
>
20+
{`${document.title.slice(0, 80)}...`}
21+
</Link>
22+
</li>
23+
))}
24+
</ul>
25+
</div>
26+
</div>
27+
)
28+
}
29+
30+
export default NewsLayout
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
.layout {
2+
display: flex;
3+
flex-direction: row;
4+
gap: 1rem;
5+
margin: 0 auto;
6+
padding: 0 2rem;
7+
}
8+
9+
.container {
10+
flex: 1;
11+
}
12+
13+
.sidebar {
14+
flex: 0 0 200px;
15+
}
16+
17+
.list {
18+
list-style: none;
19+
padding: 0;
20+
margin: 0;
21+
}
22+
23+
.item {
24+
margin-bottom: 1rem;
25+
}
26+
27+
.link {
28+
text-decoration: none;
29+
}
30+
31+
.link:hover {
32+
text-decoration: underline;
33+
}

src/app/(sections)/news/[slug]/page.tsx

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,26 @@
11
import { readDocumentWithBlocks } from '@/db/api/documents'
22
import { Document } from '@/components'
3+
import { Metadata } from 'next'
4+
5+
export const generateMetadata = async ({
6+
params,
7+
}: {
8+
params: Promise<{ slug: string }>
9+
}): Promise<Metadata> => {
10+
const { slug } = await params
11+
const document = await readDocumentWithBlocks(slug)
12+
return {
13+
title: document.title,
14+
description: document.description,
15+
}
16+
}
317

418
const NewsPage = async ({ params }: { params: Promise<{ slug: string }> }) => {
519
const { slug } = await params
620
const document = await readDocumentWithBlocks(slug)
721

822
return (
9-
<article style={{ flexGrow: 1 }}>
23+
<article className="NewsPage" style={{ flexGrow: 1 }}>
1024
<Document document={document} />
1125
</article>
1226
)
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
.component {
2+
font-family: sans-serif;
3+
}
4+
5+
.list {
6+
list-style: none;
7+
padding: 0;
8+
margin: 0;
9+
}
10+
11+
.item {
12+
margin-bottom: 1rem;
13+
display: flex;
14+
flex-direction: column;
15+
gap: 0.5rem;
16+
}
17+
18+
.link {
19+
text-decoration: none;
20+
}
21+
22+
.link:hover {
23+
text-decoration: underline;
24+
}
25+
26+
.date {
27+
font-size: 0.8rem;
28+
color: #666;
29+
}

src/app/(sections)/news/page.tsx

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,35 @@
11
import { readDocuments } from '@/db/api/documents'
22
import Link from 'next/link'
3+
import classes from './page.module.css'
4+
5+
export const metadata = {
6+
title: 'Новости',
7+
description: 'Новости о болезни Рандю-Ослера',
8+
keywords: 'новости, болезнь Рандю-Ослера',
9+
}
310

411
const NewsPage = async () => {
512
const documents = await readDocuments()
613

714
return (
8-
<div>
15+
<div className={classes.component}>
916
<h1>Новости</h1>
10-
<ul>
17+
<ul className={classes.list}>
1118
{documents.map((document) => (
12-
<li key={document.id}>
13-
<Link href={`/news/${document.id}`}>{document.title}</Link>
19+
<li key={document.id} className={classes.item}>
20+
<time
21+
dateTime={document.created_at.toISOString()}
22+
className={classes.date}
23+
>
24+
{new Date(document.created_at).toLocaleDateString('ru-RU', {
25+
day: '2-digit',
26+
month: '2-digit',
27+
year: 'numeric',
28+
})}
29+
</time>
30+
<Link className={classes.link} href={`/news/${document.id}`}>
31+
{document.title}
32+
</Link>
1433
</li>
1534
))}
1635
</ul>

src/app/global.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
body {
1818
background-color: var(--background-color);
1919
color: var(--text-color);
20+
font-family: sans-serif;
2021
}
2122

2223
a {

src/components/Document/Document.tsx

Lines changed: 27 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -20,39 +20,34 @@ type BlockData = {
2020

2121
const Document = ({ document }: { document: DocumentWithBlocks }) => {
2222
return (
23-
<div className={classes.document}>
23+
<div className={classes.component}>
2424
<h1>{document.title}</h1>
25-
<p>{document.description}</p>
26-
<ul>
27-
{document.blocks.map((block) => {
28-
switch (block.type) {
29-
case 'paragraph':
30-
return (
31-
<DocumentParagraph key={block.id} content={block.content} />
32-
)
33-
case 'heading2':
34-
return <DocumentHeading2 key={block.id} content={block.content} />
35-
case 'heading3':
36-
return <DocumentHeading3 key={block.id} content={block.content} />
37-
case 'list':
38-
return <DocumentList key={block.id} content={block.content} />
39-
case 'youtube':
40-
return <DocumentYoutube key={block.id} url={block.url} />
41-
case 'image':
42-
return <DocumentImage key={block.id} url={block.url} />
43-
case 'quote':
44-
return (
45-
<DocumentQuote
46-
key={block.id}
47-
content={block.content}
48-
url={block.url}
49-
/>
50-
)
51-
default:
52-
return <p>Unknown block type: {block.type}</p>
53-
}
54-
})}
55-
</ul>
25+
{document.blocks.map((block) => {
26+
switch (block.type) {
27+
case 'paragraph':
28+
return <DocumentParagraph key={block.id} content={block.content} />
29+
case 'heading2':
30+
return <DocumentHeading2 key={block.id} content={block.content} />
31+
case 'heading3':
32+
return <DocumentHeading3 key={block.id} content={block.content} />
33+
case 'list':
34+
return <DocumentList key={block.id} content={block.content} />
35+
case 'youtube':
36+
return <DocumentYoutube key={block.id} url={block.url} />
37+
case 'image':
38+
return <DocumentImage key={block.id} url={block.url} />
39+
case 'quote':
40+
return (
41+
<DocumentQuote
42+
key={block.id}
43+
content={block.content}
44+
url={block.url}
45+
/>
46+
)
47+
default:
48+
return <p>Unknown block type: {block.type}</p>
49+
}
50+
})}
5651
</div>
5752
)
5853
}

src/components/Document/document.module.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,9 +206,9 @@
206206
width: 100%;
207207
}
208208

209-
.document {
210-
max-width: 800px;
209+
.component {
211210
margin: 0 auto;
211+
font-family: sans-serif;
212212

213213
/** Paragraphs */
214214
p {

0 commit comments

Comments
 (0)