Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:02,090 --> 00:00:03,790
So let's continue with that
2
00:00:03,790 --> 00:00:07,280
post detail page now with this slug page
3
00:00:07,280 --> 00:00:09,560
which we load for a given slug.
4
00:00:09,560 --> 00:00:13,280
On this page, I in the end wanna output the content
5
00:00:13,280 --> 00:00:14,930
of a selected post.
6
00:00:14,930 --> 00:00:18,590
So that includes a header with the title
7
00:00:18,590 --> 00:00:21,570
and maybe the image again, but then below that
8
00:00:21,570 --> 00:00:25,030
the actual text that makes up a post.
9
00:00:25,030 --> 00:00:27,180
Of course we don't have any text yet,
10
00:00:27,180 --> 00:00:29,050
we only have those excerpts
11
00:00:29,050 --> 00:00:30,750
but in the actual post data
12
00:00:30,750 --> 00:00:32,860
which we'll add in the next lectures
13
00:00:32,860 --> 00:00:36,910
we will also have a rich content for every post
14
00:00:36,910 --> 00:00:40,890
with headings and images and maybe code snippets
15
00:00:40,890 --> 00:00:44,300
and of course a lot of just plain text.
16
00:00:44,300 --> 00:00:49,000
Hence in this Slug.js file in this component
17
00:00:49,000 --> 00:00:51,930
I again wanna return another component
18
00:00:51,930 --> 00:00:54,250
which will actually take care about
19
00:00:54,250 --> 00:00:57,590
outputting that post content.
20
00:00:57,590 --> 00:00:59,970
And I'll do that here in the posts folder,
21
00:00:59,970 --> 00:01:02,790
in the components folder I'll add a sub folder
22
00:01:02,790 --> 00:01:05,200
named post-detail to make it clear
23
00:01:05,200 --> 00:01:10,200
that in there we have the components for a single post.
24
00:01:10,290 --> 00:01:15,290
And in there I'll add a post-content.js file.
25
00:01:15,690 --> 00:01:19,450
I will also already add a post-header.js file
26
00:01:19,450 --> 00:01:21,540
which will be responsible for outputting
27
00:01:21,540 --> 00:01:25,760
the main header data like the main title entity image
28
00:01:25,760 --> 00:01:27,860
of that selected post.
29
00:01:27,860 --> 00:01:31,060
Now for that we'll also need some styles
30
00:01:31,060 --> 00:01:33,826
and as always you find those attached
31
00:01:33,826 --> 00:01:37,970
attached, you do find a post-content.module.css
32
00:01:37,970 --> 00:01:40,760
and a post-header.module.css file
33
00:01:40,760 --> 00:01:43,390
and you can just download them and add them
34
00:01:43,390 --> 00:01:45,773
in your post detail folder.
35
00:01:46,760 --> 00:01:50,900
Now let's start with the post-content.js file.
36
00:01:50,900 --> 00:01:54,870
This will become a quite complex file over time
37
00:01:54,870 --> 00:01:57,030
but we will start simple.
38
00:01:57,030 --> 00:02:00,970
We'll again, start by creating our component function
39
00:02:00,970 --> 00:02:05,370
and exporting that as a default as we always do.
40
00:02:05,370 --> 00:02:10,370
And then in here we wanna return some markup
41
00:02:10,573 --> 00:02:14,460
some JSX code that renders a post.
42
00:02:14,460 --> 00:02:17,860
Now later, we will actually get the post content
43
00:02:17,860 --> 00:02:19,750
as marked Markdown,
44
00:02:19,750 --> 00:02:23,600
which is text with extra annotations.
45
00:02:23,600 --> 00:02:26,260
You'll see it in a couple of minutes
46
00:02:26,260 --> 00:02:28,897
and we'll then translate that Markdown
47
00:02:28,897 --> 00:02:32,490
to React JSX elements.
48
00:02:32,490 --> 00:02:34,190
That is something we'll do later
49
00:02:34,190 --> 00:02:37,760
for the moment I'll start by adding
50
00:02:37,760 --> 00:02:42,177
an article element here, a standard article element,
51
00:02:42,177 --> 00:02:47,177
and then rendering a PostHeader here as a first element.
52
00:02:47,610 --> 00:02:51,173
And then below that the actual content.
53
00:02:52,910 --> 00:02:55,220
And that is what will then later translate
54
00:02:55,220 --> 00:02:58,643
from Markdown to actual JSX code.
55
00:02:59,520 --> 00:03:02,760
Now let's start with the PostHeader though
56
00:03:02,760 --> 00:03:05,040
with that PostHeader component,
57
00:03:05,040 --> 00:03:08,460
for which we have this separate post-header.js file
58
00:03:09,620 --> 00:03:12,660
in there again, we create our component function
59
00:03:12,660 --> 00:03:17,230
as we always did, and we export post-header here
60
00:03:18,160 --> 00:03:21,670
and then here we can return a header element.
61
00:03:21,670 --> 00:03:26,670
Let's say with the H1 element with the title of the post.
62
00:03:26,750 --> 00:03:31,540
And I do expect that I get data like the title from props.
63
00:03:31,540 --> 00:03:35,570
So here I do expect that I can pull data out of my props
64
00:03:35,570 --> 00:03:38,620
and that I get the title here
65
00:03:38,620 --> 00:03:41,140
and actually also the image.
66
00:03:41,140 --> 00:03:46,140
So then here, I just output the title like that.
67
00:03:47,520 --> 00:03:48,510
And then below that,
68
00:03:48,510 --> 00:03:50,070
I wanna render the image.
69
00:03:50,070 --> 00:03:53,070
And I'll again do that with the image component
70
00:03:53,070 --> 00:03:56,760
which we therefore import from next image.
71
00:03:56,760 --> 00:04:01,040
So we import that component and render it just like that
72
00:04:01,040 --> 00:04:02,663
below the H1 tag.
73
00:04:03,580 --> 00:04:05,610
Actually because of the styling,
74
00:04:05,610 --> 00:04:06,680
which we'll add soon,
75
00:04:06,680 --> 00:04:10,320
it will be rendered next to the h1 tag.
76
00:04:10,320 --> 00:04:11,650
So now we got that.
77
00:04:11,650 --> 00:04:14,430
Now the source of the image element here
78
00:04:14,430 --> 00:04:17,790
should be the image we're getting as an argument
79
00:04:17,790 --> 00:04:21,540
and here I will expect that image is the full path
80
00:04:21,540 --> 00:04:23,040
to the image already.
81
00:04:23,040 --> 00:04:25,890
So I'll just set src equal to image,
82
00:04:25,890 --> 00:04:29,050
set alt equal to the title.
83
00:04:29,050 --> 00:04:32,390
And then we need values for width and height
84
00:04:32,390 --> 00:04:37,210
and here a width of 200 and a height of 150
85
00:04:37,210 --> 00:04:38,963
should work quite well.
86
00:04:40,160 --> 00:04:41,740
Now we will need some styles.
87
00:04:41,740 --> 00:04:46,740
So import classes from ./post-header.module.css
88
00:04:48,160 --> 00:04:51,170
this css file which I provided to you.
89
00:04:51,170 --> 00:04:52,730
And with that on the header,
90
00:04:52,730 --> 00:04:56,963
we can add a class name of header like that.
91
00:04:58,710 --> 00:05:02,140
Now that is the post-header component,
92
00:05:02,140 --> 00:05:04,640
which we use in post content.
93
00:05:04,640 --> 00:05:07,973
Hence we need to set the title and the image here.
94
00:05:09,160 --> 00:05:11,570
Now speaking of that our post content
95
00:05:11,570 --> 00:05:14,130
will need some content to work.
96
00:05:14,130 --> 00:05:18,340
And we'll soon get that content from a real data source.
97
00:05:18,340 --> 00:05:20,700
Since we don't have that data source yet
98
00:05:20,700 --> 00:05:23,580
I'll create a dummy post here.
99
00:05:23,580 --> 00:05:27,100
And we will just assume that we loaded that post
100
00:05:27,100 --> 00:05:28,640
so I'll create a dummy post here,
101
00:05:28,640 --> 00:05:30,990
which is a JavaScript object
102
00:05:30,990 --> 00:05:33,030
which will contain some dummy data,
103
00:05:33,030 --> 00:05:34,870
like for example a slug.
104
00:05:34,870 --> 00:05:38,650
And here I wanna use one of the slugs I used before.
105
00:05:38,650 --> 00:05:43,070
Actually I'll grab one of my dummy posts here.
106
00:05:43,070 --> 00:05:46,330
So a single dummy post I'll grab that post
107
00:05:46,330 --> 00:05:51,330
and use that now as a dummy post in post-content.
108
00:05:53,330 --> 00:05:55,730
Here like this,
109
00:05:55,730 --> 00:05:57,450
I will get rid of the excerpt though.
110
00:05:57,450 --> 00:05:59,030
We don't need that here,
111
00:05:59,030 --> 00:06:01,890
but instead I will add a content field
112
00:06:01,890 --> 00:06:05,050
which will contain the actual post content.
113
00:06:05,050 --> 00:06:08,403
And in here I will write Markdown code.
114
00:06:09,310 --> 00:06:11,780
Now, in case you're not familiar with Markdown,
115
00:06:11,780 --> 00:06:13,810
you can of course Google it, look it up.
116
00:06:13,810 --> 00:06:17,576
And you'll see that there also a cheatsheet Markdown
117
00:06:17,576 --> 00:06:20,560
in there in this plain text with extra annotations.
118
00:06:20,560 --> 00:06:22,370
Markdown looks like this.
119
00:06:22,370 --> 00:06:24,660
You write text and you can for example,
120
00:06:24,660 --> 00:06:26,480
add a hash symbol in front of it,
121
00:06:26,480 --> 00:06:28,570
to turn it into a title.
122
00:06:28,570 --> 00:06:33,570
You can also create lists with dashes or with numbers
123
00:06:33,810 --> 00:06:35,430
to have ordered lists.
124
00:06:35,430 --> 00:06:38,670
You can add links by putting text in square brackets
125
00:06:38,670 --> 00:06:42,780
and adding the link destination in parentheses thereafter,
126
00:06:42,780 --> 00:06:44,200
things like that.
127
00:06:44,200 --> 00:06:46,100
If you ever worked with GitHub
128
00:06:46,100 --> 00:06:49,010
and you added a read me for a GitHub repository,
129
00:06:49,010 --> 00:06:51,740
you wrote that in Markdown.
130
00:06:51,740 --> 00:06:55,400
And we use Markdown here because it's less code
131
00:06:55,400 --> 00:06:59,700
than if we would use HTML and it can be translated
132
00:06:59,700 --> 00:07:04,500
into HTML or into JSX, even with third-party packages,
133
00:07:04,500 --> 00:07:06,130
which we'll add.
134
00:07:06,130 --> 00:07:08,570
So here I'll add a simple Markdown text
135
00:07:08,570 --> 00:07:12,870
of this is a first post.
136
00:07:12,870 --> 00:07:15,410
And the interesting thing is that this is plain text
137
00:07:15,410 --> 00:07:17,640
with this extra hash notation
138
00:07:17,640 --> 00:07:21,500
turning this into a title in Markdown's world.
139
00:07:21,500 --> 00:07:25,280
And the goal is now to translate this string
140
00:07:25,280 --> 00:07:29,850
from Markdown into JSX which we'll do in the next lecture.
141
00:07:29,850 --> 00:07:33,073
Before we do that, let's set the tittle and image
142
00:07:33,073 --> 00:07:35,087
of the PostHeader though.
143
00:07:35,087 --> 00:07:37,670
For this here in post content
144
00:07:37,670 --> 00:07:40,074
I will create a ImagePath here
145
00:07:40,074 --> 00:07:43,770
and again, set up a template literal
146
00:07:43,770 --> 00:07:48,770
where we dive into /images/posts then use the slug.
147
00:07:48,950 --> 00:07:53,950
So dummy-post.slug and then use the actual image name.
148
00:07:55,350 --> 00:07:59,160
So inject dummy post.image,
149
00:07:59,160 --> 00:08:02,270
and it's this ImagePath which I set as a value
150
00:08:02,270 --> 00:08:05,773
for the image prop on my PostHeader like this.
151
00:08:06,820 --> 00:08:10,000
And for the title we can also set this dynamically
152
00:08:10,000 --> 00:08:12,053
to dummy post.title.
153
00:08:13,440 --> 00:08:14,670
Now for the content,
154
00:08:14,670 --> 00:08:18,000
we don't wanna do dummy post.content
155
00:08:18,000 --> 00:08:19,750
because if we would,
156
00:08:19,750 --> 00:08:21,480
we would see that content
157
00:08:21,480 --> 00:08:24,450
but we would just output it as plain text,
158
00:08:24,450 --> 00:08:27,630
not translate it from Markdown to JSX
159
00:08:27,630 --> 00:08:30,130
and therefore that's not what we want.
160
00:08:30,130 --> 00:08:31,350
Still to get started,
161
00:08:31,350 --> 00:08:34,190
let's start with this and let's then go
162
00:08:34,190 --> 00:08:38,820
to the slug.js file in the page's post folder
163
00:08:38,820 --> 00:08:42,400
and output Post content here
164
00:08:42,400 --> 00:08:43,232
and later
165
00:08:43,232 --> 00:08:45,570
we'll pass in the data for the post content
166
00:08:45,570 --> 00:08:48,220
from inside this page for the moment
167
00:08:48,220 --> 00:08:49,770
I'll just render it like this
168
00:08:49,770 --> 00:08:53,200
and I'll import post content from the proper path
169
00:08:53,200 --> 00:08:56,912
therefore, and if we do all that
170
00:08:56,912 --> 00:08:58,900
If you reload a single post
171
00:08:58,900 --> 00:09:01,500
you see PostHeader is not defined
172
00:09:01,500 --> 00:09:04,470
because in post content I'm using PostHeader
173
00:09:04,470 --> 00:09:06,320
but I'm not importing it.
174
00:09:06,320 --> 00:09:08,320
That's something we should change.
175
00:09:08,320 --> 00:09:11,941
I'll import PostHeader from ./post-header
176
00:09:11,941 --> 00:09:15,940
add that import in the post content file.
177
00:09:15,940 --> 00:09:17,760
And now we see this.
178
00:09:17,760 --> 00:09:20,032
This is not the final look I want though
179
00:09:20,032 --> 00:09:23,220
I want some extra styling and for that,
180
00:09:23,220 --> 00:09:27,170
I did add that post-content module.css file.
181
00:09:27,170 --> 00:09:30,560
So I will also import classes from there
182
00:09:30,560 --> 00:09:35,560
and import classes from post-content.module.css
183
00:09:37,590 --> 00:09:40,290
and then on this article here
184
00:09:40,290 --> 00:09:44,090
set a class name of classes.content.
185
00:09:47,160 --> 00:09:49,800
If we save that now that looks better
186
00:09:50,720 --> 00:09:54,950
but here we see that we have this untransformed raw text
187
00:09:54,950 --> 00:09:58,880
and therefore let's now become a bit more advanced
188
00:09:58,880 --> 00:10:02,070
by adding functionality to translate
189
00:10:02,070 --> 00:10:04,110
playing the Markdown text,
190
00:10:04,110 --> 00:10:07,423
into renderable JSX code.
14685
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.