Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:03,000 --> 00:00:04,611
Thanks to some styling,
2
00:00:04,611 --> 00:00:07,696
our website is starting to look a bit nicer.
3
00:00:07,696 --> 00:00:09,796
But it's still quite plain.
4
00:00:09,796 --> 00:00:12,248
What we could do is add some images,
5
00:00:12,248 --> 00:00:14,824
maybe one for each game we review.
6
00:00:14,824 --> 00:00:18,301
We'll also want to style these links by the way,
7
00:00:18,301 --> 00:00:20,742
but let's start from a review page.
8
00:00:20,742 --> 00:00:22,836
We could show an image here,
9
00:00:22,836 --> 00:00:24,556
representing this game.
10
00:00:24,631 --> 00:00:28,036
But where should we put the images in our project?
11
00:00:28,036 --> 00:00:30,562
We can create a folder, at the top level,
12
00:00:30,562 --> 00:00:31,965
called "public".
13
00:00:32,402 --> 00:00:35,060
Any files we put inside that folder
14
00:00:35,060 --> 00:00:37,718
will be treated as "static assets".
15
00:00:37,794 --> 00:00:39,994
Just to show you how it works,
16
00:00:39,994 --> 00:00:43,299
let's create a file named "test.txt",
17
00:00:43,299 --> 00:00:46,456
and write some text, like "Hello world!"
18
00:00:46,456 --> 00:00:48,629
That file will now be served
19
00:00:48,629 --> 00:00:50,337
by the Next.js server,
20
00:00:50,415 --> 00:00:54,496
and we can access it as "/test.txt".
21
00:00:54,496 --> 00:00:57,213
So, any file in the "public" folder
22
00:00:57,213 --> 00:00:59,852
will be returned exactly as it is.
23
00:00:59,930 --> 00:01:02,923
That's how we can serve images as well.
24
00:01:02,923 --> 00:01:06,102
If you look under the Resources for this lecture,
25
00:01:06,102 --> 00:01:09,370
you'll find a file called "images.zip",
26
00:01:09,370 --> 00:01:13,174
that contains a few pictures for our game reviews.
27
00:01:13,174 --> 00:01:16,682
So you can download this package to your machine.
28
00:01:16,682 --> 00:01:19,015
And you can save it directly inside
29
00:01:19,015 --> 00:01:20,814
the "next-reviews" project,
30
00:01:20,881 --> 00:01:22,522
in the "public" folder.
31
00:01:23,841 --> 00:01:26,167
So this will download it there.
32
00:01:26,167 --> 00:01:28,569
And I'll open it in Finder, that's
33
00:01:28,569 --> 00:01:30,193
the macOS File Manager.
34
00:01:30,264 --> 00:01:32,459
We can unzip this file directly
35
00:01:32,459 --> 00:01:34,371
inside the "public" folder,
36
00:01:34,441 --> 00:01:37,639
and it will create its own "images" folder.
37
00:01:37,639 --> 00:01:40,990
We can also delete these other two files now.
38
00:01:41,279 --> 00:01:45,023
Ok. We have some images to use in our project.
39
00:01:45,023 --> 00:01:47,014
Let's go back to our application.
40
00:01:48,383 --> 00:01:50,780
And I'll reload the Home page.
41
00:01:51,363 --> 00:01:54,370
"test.txt" doesn't exist any more.
42
00:01:54,370 --> 00:01:56,416
But inside "public" there's
43
00:01:56,416 --> 00:01:58,159
now an "images" folder,
44
00:01:58,235 --> 00:02:01,173
that contains three jpeg files.
45
00:02:01,173 --> 00:02:04,128
"stardew-valley.jpg" is a screenshot
46
00:02:04,128 --> 00:02:06,508
from the Stardew Valley game.
47
00:02:06,590 --> 00:02:08,907
Then there's one for "hollow-knight".
48
00:02:08,907 --> 00:02:11,564
And the third one is "hellblade".
49
00:02:11,564 --> 00:02:14,171
We don't have a page for this game yet,
50
00:02:14,171 --> 00:02:16,033
but we'll add one later on.
51
00:02:16,033 --> 00:02:18,240
Anyway, we have some images.
52
00:02:18,240 --> 00:02:20,976
Since they're inside the "public" folder,
53
00:02:20,976 --> 00:02:26,147
we can access them directly as "/images/hellblade.jpg"
54
00:02:26,147 --> 00:02:27,296
for example,
55
00:02:27,392 --> 00:02:29,252
and the browser will display it,
56
00:02:29,252 --> 00:02:32,249
because the Next.js server returns
57
00:02:32,249 --> 00:02:34,276
the jpeg file as it is.
58
00:02:34,364 --> 00:02:38,103
Ok, so let's use those images in our pages.
59
00:02:38,103 --> 00:02:40,985
Let's start from the Hollow Knight review,
60
00:02:40,985 --> 00:02:43,775
that I'll open in the browser as well.
61
00:02:43,775 --> 00:02:46,764
Here we can add an image after the Heading,
62
00:02:46,764 --> 00:02:49,256
and we'll use the standard HTML
63
00:02:49,256 --> 00:02:51,024
"img" element for now.
64
00:02:51,105 --> 00:02:55,749
The path will be "/images/hollow-knight.jpg".
65
00:02:56,025 --> 00:02:58,726
Then we should set the "alt" attribute,
66
00:02:58,726 --> 00:02:59,973
for accessibility.
67
00:03:00,043 --> 00:03:01,628
But we can leave it empty,
68
00:03:01,628 --> 00:03:05,022
because this will be a purely decorative image.
69
00:03:05,022 --> 00:03:08,287
The heading already contains the game title.
70
00:03:08,287 --> 00:03:10,637
And we can see the image on the page.
71
00:03:10,637 --> 00:03:12,807
Now, it's good practice to also
72
00:03:12,807 --> 00:03:14,418
specify the dimensions,
73
00:03:14,488 --> 00:03:17,142
so that the browser can reserve the right
74
00:03:17,142 --> 00:03:19,732
amount of space when rendering the page.
75
00:03:19,797 --> 00:03:23,415
Let's set the "width" to 640 pixels,
76
00:03:23,415 --> 00:03:26,112
and the "height" to 360.
77
00:03:26,955 --> 00:03:30,960
The original size is 1280x720,
78
00:03:30,960 --> 00:03:33,717
so this will preserve the aspect ratio,
79
00:03:33,717 --> 00:03:35,458
but we don't want the image
80
00:03:35,458 --> 00:03:37,135
to take up the whole page.
81
00:03:37,199 --> 00:03:40,020
We want to be able to see the text as well.
82
00:03:40,020 --> 00:03:41,895
If we're on a smaller screen,
83
00:03:41,895 --> 00:03:43,770
it will automatically shrink.
84
00:03:43,835 --> 00:03:45,978
Now, let's add some styles.
85
00:03:45,978 --> 00:03:49,422
We'll use Tailwind CSS classes as usual.
86
00:03:49,422 --> 00:03:51,092
Let's make it "rounded",
87
00:03:51,092 --> 00:03:54,515
just because rounded corners look nicer.
88
00:03:54,515 --> 00:03:57,389
We could also add some margin at the bottom,
89
00:03:57,389 --> 00:04:00,822
to leave some space before the text below.
90
00:04:00,822 --> 00:04:03,774
And I think that's good enough for this example.
91
00:04:03,774 --> 00:04:05,453
Let's copy this code
92
00:04:05,453 --> 00:04:08,849
and do exactly the same in the other review page,
93
00:04:08,849 --> 00:04:11,087
that is for Stardew Valley.
94
00:04:11,087 --> 00:04:12,910
Let me show the right page.
95
00:04:12,910 --> 00:04:15,735
So, we can paste the image code here,
96
00:04:15,810 --> 00:04:19,999
but we need to change it to "stardew-valley.jpg".
97
00:04:19,999 --> 00:04:22,492
And if we save, we see the right image.
98
00:04:22,492 --> 00:04:25,891
Ok. It's much better with a screenshot.
99
00:04:25,891 --> 00:04:28,766
So, to recap: we just need to put our
100
00:04:28,766 --> 00:04:31,330
images inside the "public" folder
101
00:04:31,408 --> 00:04:33,986
and the Next.js server will return
102
00:04:33,986 --> 00:04:35,958
them directly as they are.
103
00:04:36,034 --> 00:04:38,113
You can use the same approach
104
00:04:38,113 --> 00:04:40,048
for any other static asset,
105
00:04:40,119 --> 00:04:43,494
like videos, audio files, PDF documents,
106
00:04:43,494 --> 00:04:44,338
and so on.
7744
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.