Skip to content

Commit 78f62bf

Browse files
Add asideNote type with icon
1 parent b9b92db commit 78f62bf

File tree

6 files changed

+126
-28
lines changed

6 files changed

+126
-28
lines changed

studio/schemas/post.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export default {
2828
{ type: 'code' },
2929
// TODO: update these type names:
3030
{ type: 'post_aside' },
31+
{ type: 'post_aside_note' },
3132
{ type: 'post_aside_with_code' }
3233
]
3334
},

studio/schemas/postAsideNote.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
export default {
2+
title: 'Post Aside Note',
3+
name: 'post_aside_note',
4+
type: 'document',
5+
fields: [
6+
{
7+
title: 'String Content',
8+
name: 'str_content',
9+
type: 'array',
10+
of: [
11+
{ type: 'text' },
12+
{
13+
type: 'block',
14+
of: [{
15+
type: 'inline_code'
16+
}]
17+
},
18+
]
19+
}
20+
]
21+
}

studio/schemas/postAsideWithCode.js

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,6 @@ export default {
1818
},
1919

2020
]
21-
},
22-
23-
// TODO: image:
24-
// {
25-
// title: '',
26-
// name: '',
27-
// type: '',
28-
// },
21+
}
2922
]
3023
}

studio/schemas/schema.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import comment from './comment'
88
import author from './author'
99
import tag from './tag'
1010
import postAside from './postAside'
11+
import postAsideNote from './postAsideNote'
1112
import postAsideWithCode from './postAsideWithCode'
1213
import inlineCode from './inlineCode'
1314

@@ -22,6 +23,7 @@ export default createSchema({
2223
author,
2324
tag,
2425
postAside,
26+
postAsideNote,
2527
postAsideWithCode,
2628
inlineCode
2729
])

web/pages/posts/[slug].js

Lines changed: 52 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@ const ArticleBlock = styled.div`
3232
`
3333
const AsideBlock = styled.div`
3434
margin-bottom: 1em;
35-
padding: 1em 2em;
35+
padding: 1em 1.5em;
3636
background-color: ${({ theme }) => theme.asideBackground};
3737
font-size: .9em;
3838
line-height: 1.5em;
3939
border: 1px solid rgba(114, 143, 203, .5);
40-
border-left: 2px solid rgba(114, 143, 203, .5);
40+
/* border-left: 5px solid rgba(114, 143, 203, .5); */
4141
`
4242
const Pre = styled.pre`
4343
font-family: 'Fira Mono', monospace;
@@ -67,18 +67,17 @@ const InlineCodeMain = styled.span`
6767
background-color: ${({ theme }) => theme.secondaryColor};
6868
padding: 1px 3px;
6969
`
70+
// TODO: why does this format inline code in asideWithCode all wonky when I remove the 0 padding
7071
const AsideCode = styled(InlineCodeMain)`
7172
padding: 0 5px;
72-
margin-bottom: 1em;
73-
font-family: 'Courier Prime', monospace;
7473
`
7574
const AsideCodeDescription = styled.p`
7675
margin-top: 1.1em;
7776
display: block;
7877
font-weight: 400;
7978
`
8079
const CodeNote = styled.p`
81-
margin-top: -.5em;
80+
/* margin-top: -.5em; */
8281
margin-bottom: 1.2em;
8382
font-style: italic;
8483
color: ${({ theme }) => theme.primaryColor};
@@ -99,6 +98,16 @@ const H3 = styled.h3`
9998
margin-top: 1.5em;
10099
font-family: 'Cuprum', sans-serif;
101100
`
101+
const UL = styled.ul`
102+
margin-bottom: 15px;
103+
`
104+
const InfoIcon = styled.img`
105+
float: left;
106+
margin: 0 15px 0 0;
107+
@media screen and (max-width: 600px) {
108+
margin: 0 5px 0 0;
109+
}
110+
`
102111
const ListItem = styled.li`
103112
/* &:before {
104113
content: ''
@@ -123,22 +132,18 @@ function Post(props) {
123132
}
124133

125134
function formatListItem(listItemParts) {
126-
// console.log('formatListItem ', listItemParts)
127135
const listItem = []
128136
for (let i = 0; i < listItemParts.length; i++) {
129137
if (listItemParts[i]._type === 'inline_code') {
130138
listItem.push(
131-
<InlineCodeMain key={listItemParts._key}>
139+
<InlineCodeMain key={listItemParts[i]._key}>
132140
{listItemParts[i].str_content_inline}
133141
</InlineCodeMain>
134142
)
135-
}
136-
else {
143+
} else {
137144
listItem.push(listItemParts[i].text)
138145
}
139-
140146
}
141-
// console.log('listItem: ', listItem)
142147
return listItem
143148
}
144149

@@ -193,13 +198,17 @@ function Post(props) {
193198
const renderedLines = []
194199
for (let i = 0; i < contentArray.length; i++) {
195200
renderedLines.push(
196-
<div key={i}>{contentArray[i]}</div>
201+
<p key={i}>{contentArray[i]}</p>
197202
)
198203
}
199-
return <AsideBlock key={_key}>{renderedLines}</AsideBlock>
204+
return (
205+
<AsideBlock key={_key}>
206+
{renderedLines}
207+
</AsideBlock>
208+
)
200209
}
201210

202-
function asideWithCode(content, _key) {
211+
function asideWithCode(content, _key, isAsideNote) {
203212
// console.log('asideWithCode: ', content)
204213
const renderedContent = []
205214
for (let i = 0; i < content.length; i++) {
@@ -227,6 +236,10 @@ function Post(props) {
227236
</CodeNote>
228237
)
229238
}
239+
// aside note with no special formatting
240+
else if (isAsideNote) {
241+
renderedContent.push(children[0].text)
242+
}
230243
else {
231244
renderedContent.push(
232245
<AsideCodeDescription key={children[0]._key}>
@@ -236,7 +249,23 @@ function Post(props) {
236249
}
237250
}
238251
// console.log('renderedContent: ', renderedContent)
239-
return <AsideBlock key={_key}>{renderedContent}</AsideBlock>
252+
return (
253+
<AsideBlock key={_key}>
254+
{isAsideNote && (
255+
<InfoIcon
256+
src="/info.svg"
257+
width="40"
258+
height="40"
259+
alt="info icon"
260+
/>
261+
)}
262+
{renderedContent}
263+
</AsideBlock>
264+
)
265+
}
266+
267+
function asideNote(content, _key) {
268+
return asideWithCode(content, _key, true)
240269
}
241270

242271
function prismafyCodeBlock(content, _key) {
@@ -272,14 +301,15 @@ function Post(props) {
272301

273302
let list = []
274303
props.body && props.body.forEach(section => {
304+
// console.log('section._type: ', section._type)
275305
if (section.listItem) {
276306
list.push(
277307
<ListItem>{formatListItem(section.children)}</ListItem>
278308
)
279309
} else {
280310
if (list.length > 0) {
281311
postContent.push(
282-
<ul>{list}</ul>
312+
<UL>{list}</UL>
283313
)
284314
list = []
285315
}
@@ -301,12 +331,14 @@ function Post(props) {
301331
)
302332
)
303333
break
334+
case 'post_aside_note':
335+
postContent.push(
336+
asideNote(section.str_content, section._key)
337+
)
338+
break
304339
case 'post_aside_with_code':
305-
// console.log('section.body: ', section.body)
306340
postContent.push(
307-
asideWithCode(
308-
section.body, section._key
309-
)
341+
asideWithCode(section.body, section._key)
310342
)
311343
break
312344
// default:

web/public/info.svg

Lines changed: 49 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)