Skip to content

Commit 8f6bb2a

Browse files
reading redesign ish
1 parent d5079e9 commit 8f6bb2a

2 files changed

Lines changed: 59 additions & 28 deletions

File tree

components/reading.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import Link from 'next/link';
2+
import dayjs from 'dayjs';
3+
4+
import styles from '../styles/blog.module.scss';
5+
6+
export default function Reading({ reading }) {
7+
function createNameList(names) {
8+
let name = "";
9+
10+
if (names.length == 1) {
11+
return `${names[0].firstName} ${names[0].lastName}`
12+
}
13+
14+
for (let i = 0; i < names.length; i++) {
15+
if (i == names.length - 1) {
16+
name += `and ${names[i].firstName} ${names[i].lastName}`
17+
18+
return name;
19+
}
20+
name += `${names[i].firstName} ${names[i].lastName}, `
21+
}
22+
23+
return name;
24+
}
25+
26+
function createTagsList(tags) {
27+
let tag = "";
28+
29+
for (let i = 0; i < tags.length; i++) {
30+
tag += `#${tags[i].tag} `
31+
}
32+
33+
return tag;
34+
}
35+
36+
return (
37+
<>
38+
<div className={styles.post}>
39+
<hr />
40+
<Link href={reading.link} passHref>
41+
<h2>{reading.title}</h2>
42+
</Link>
43+
44+
<p className={styles.info}>By {createNameList(reading.author)}</p>
45+
<h4 className={styles.info}>Published: {reading.date}</h4>
46+
<p>Tags: {createTagsList(reading.tags)} </p>
47+
<p>Date Added: {dayjs(reading.dateAdded).format('MMMM D, YYYY')}</p>
48+
</div>
49+
</>
50+
)
51+
52+
}

pages/ai.js

Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
import Link from 'next/link';
22
import dayjs from 'dayjs';
33
import Head from 'next/head';
4+
import React from 'react';
45

56
import { NextSeo } from 'next-seo';
67

8+
import Reading from '../components/reading.js';
9+
710
import styles from '../styles/blog.module.scss';
811

912

@@ -25,24 +28,7 @@ export default function AI({ readings }) {
2528
everything listed below. I will read anything and everything, and this is
2629
just a list. Please send me more things to read! :)`;
2730

28-
function createNameList(names) {
29-
let name = "";
30-
31-
if (names.length == 1) {
32-
return `${names[0].firstName} ${names[0].lastName}`
33-
}
34-
35-
for (let i = 0; i < names.length; i++) {
36-
if (i == names.length - 1) {
37-
name += `and ${names[i].firstName} ${names[i].lastName}`
38-
39-
return name;
40-
}
41-
name += `${names[i].firstName} ${names[i].lastName}, `
42-
}
43-
44-
return name;
45-
}
31+
let sortedreadings = readings.sort((reading1, reading2) => (dayjs(reading1.dateAdded).isAfter(reading2.dateAdded) ? -1 : 1))
4632

4733
return (
4834
<>
@@ -61,16 +47,9 @@ export default function AI({ readings }) {
6147
</div>
6248
<div className={styles.blog}>
6349
{readings.map((reading, index) => (
64-
<div key={index} className={styles.post}>
65-
<hr/>
66-
67-
<Link href={reading.link} passHref>
68-
<h2>{reading.title}</h2>
69-
</Link>
70-
71-
<p className={styles.info}> {createNameList(reading.author)}</p>
72-
<h4 className={styles.info}>{reading.date}</h4>
73-
</div>
50+
<React.Fragment key={index}>
51+
<Reading reading={reading} />
52+
</React.Fragment>
7453
))}
7554
</div>
7655
</>

0 commit comments

Comments
 (0)