Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:02,050 --> 00:00:04,850
Now, that we learned about this head element
2
00:00:04,850 --> 00:00:08,290
we, of course, don't just want to set our own title
3
00:00:08,290 --> 00:00:10,720
and description for the starting page,
4
00:00:10,720 --> 00:00:12,580
but also for the other pages.
5
00:00:12,580 --> 00:00:14,780
And feel free to do this on your own, of course,
6
00:00:14,780 --> 00:00:18,660
with your titles and descriptions of your choice.
7
00:00:18,660 --> 00:00:22,110
I will start here with events index.js, and then here
8
00:00:22,110 --> 00:00:26,170
in the fragment, maybe here, at this head component.
9
00:00:26,170 --> 00:00:28,480
And of course, therefore, also imported.
10
00:00:28,480 --> 00:00:33,480
So import Head from next/head, like this.
11
00:00:36,040 --> 00:00:38,020
And then here, since this lists all events,
12
00:00:38,020 --> 00:00:40,900
I will give it a title of All Events
13
00:00:40,900 --> 00:00:43,270
and I'll keep this description text.
14
00:00:43,270 --> 00:00:46,540
Of course, we could use a different one but I'll keep that.
15
00:00:46,540 --> 00:00:51,430
Copy this again, go to the event ID page for a single event.
16
00:00:51,430 --> 00:00:55,270
And here, I'll then also add this in my fragment
17
00:00:55,270 --> 00:01:00,270
and add the import, import Head from next/head, like this.
18
00:01:02,550 --> 00:01:05,110
And, with that again, fine tune this.
19
00:01:05,110 --> 00:01:07,320
And here, the title should actually
20
00:01:07,320 --> 00:01:09,603
be the title of the selected event.
21
00:01:10,740 --> 00:01:13,530
Now, the great thing is since we used that
22
00:01:13,530 --> 00:01:17,520
in our regular page component JSX code,
23
00:01:17,520 --> 00:01:22,090
we can, of course, also inject dynamic content here.
24
00:01:22,090 --> 00:01:24,470
So, instead of hard coding the title
25
00:01:24,470 --> 00:01:26,870
we can use event.title here
26
00:01:26,870 --> 00:01:29,740
to use the title of the selected event.
27
00:01:29,740 --> 00:01:31,750
This is, of course, very important
28
00:01:31,750 --> 00:01:34,300
because this ensures that we don't have
29
00:01:34,300 --> 00:01:37,870
to hard code all that head data in advance,
30
00:01:37,870 --> 00:01:42,820
but that since we added to the regular component JSX code
31
00:01:42,820 --> 00:01:47,750
that we can, of course, also use a lot of dynamic values
32
00:01:47,750 --> 00:01:50,250
for the content, so for the description here,
33
00:01:50,250 --> 00:01:53,983
we could therefore, for example, also use event.description.
34
00:01:55,220 --> 00:01:57,653
So, that is very, very useful.
35
00:01:58,640 --> 00:02:01,190
And with that, if I go to the slug here
36
00:02:01,190 --> 00:02:06,190
I also want to add this, add it down there.
37
00:02:07,540 --> 00:02:10,520
And therefore also import this from next.
38
00:02:10,520 --> 00:02:15,520
So, import Head from next/head, like this.
39
00:02:16,910 --> 00:02:21,410
And also, set a title, and a description here.
40
00:02:21,410 --> 00:02:24,840
So, here I'll say filtered Events.
41
00:02:24,840 --> 00:02:26,880
And then here we could, of course,
42
00:02:26,880 --> 00:02:29,800
again use a dynamic value for the description
43
00:02:29,800 --> 00:02:32,960
and kind of construct a dynamic text
44
00:02:32,960 --> 00:02:36,770
where we say All events for,
45
00:02:36,770 --> 00:02:38,800
and then I want to use the actual month,
46
00:02:38,800 --> 00:02:41,070
and year that was selected.
47
00:02:41,070 --> 00:02:46,070
So, I'll just output for numMonth/numYear.
48
00:02:49,680 --> 00:02:51,920
And, of course, you can fine tune this text
49
00:02:51,920 --> 00:02:55,070
and format this date however you want.
50
00:02:55,070 --> 00:02:58,760
But, with that, if we save all those different page files,
51
00:02:58,760 --> 00:03:00,830
if I go to all events, for example,
52
00:03:00,830 --> 00:03:03,620
and I search for events in May,
53
00:03:03,620 --> 00:03:07,320
we see that if I inspect the rendered page
54
00:03:07,320 --> 00:03:10,480
in the head section we have that title
55
00:03:10,480 --> 00:03:14,234
and we have that description with that content
56
00:03:14,234 --> 00:03:16,513
that contains the month and year.
57
00:03:17,700 --> 00:03:20,370
Now, it's also worth noting that we don't just see
58
00:03:20,370 --> 00:03:23,520
this head content in the actual rendered page,
59
00:03:23,520 --> 00:03:25,580
which we see here when we inspect it,
60
00:03:25,580 --> 00:03:28,260
but also in the response from the server.
61
00:03:28,260 --> 00:03:30,650
If we go back to the starting page,
62
00:03:30,650 --> 00:03:34,740
if we reload this page and we then view the page source,
63
00:03:34,740 --> 00:03:38,580
so that we now fetched a brand new page from the server,
64
00:03:38,580 --> 00:03:40,990
we also find the title in here
65
00:03:40,990 --> 00:03:43,620
and we also find the description in here.
66
00:03:43,620 --> 00:03:47,430
So, that is really part of the response, which is important
67
00:03:47,430 --> 00:03:50,433
because that means that search engines will see it.
68
00:03:51,650 --> 00:03:55,140
Now you might notice, though, that if you filter for events,
69
00:03:55,140 --> 00:03:58,460
if we set a filter here and we find our events,
70
00:03:58,460 --> 00:04:02,250
here, if we reload this page in the page source
71
00:04:02,250 --> 00:04:05,970
we don't see the title and the description
72
00:04:05,970 --> 00:04:09,350
and that's not a (indistinct) but it has a simple reason.
73
00:04:09,350 --> 00:04:14,070
In our slug page, here, we do add a head,
74
00:04:14,070 --> 00:04:18,110
but we only add it here in the main content,
75
00:04:18,110 --> 00:04:21,079
which we return if we make it past all these
76
00:04:21,079 --> 00:04:23,360
if checks we have in front of it.
77
00:04:23,360 --> 00:04:26,260
Now, if we make it into one of those if checks
78
00:04:26,260 --> 00:04:30,090
to show the loading text, or to show this error,
79
00:04:30,090 --> 00:04:35,090
or to show another error, then we didn't add head here.
80
00:04:35,340 --> 00:04:37,720
And, of course, we can add head here.
81
00:04:37,720 --> 00:04:40,650
And we probably would want to add head here
82
00:04:40,650 --> 00:04:45,180
to set specific different titles for these cases.
83
00:04:45,180 --> 00:04:47,330
But you also might want to set up
84
00:04:47,330 --> 00:04:52,330
some general head content, which is part of every page.
85
00:04:52,580 --> 00:04:53,970
And, of course, you can do that
86
00:04:53,970 --> 00:04:56,050
by including it in every page,
87
00:04:56,050 --> 00:04:59,310
but that involves a lot of copy and pasting.
88
00:04:59,310 --> 00:05:02,520
And therefore, let's now have a look at the different ways
89
00:05:02,520 --> 00:05:07,430
and tools Next.js gives us for reusing logic,
90
00:05:07,430 --> 00:05:11,900
or reusing configuration, like certain head elements
91
00:05:11,900 --> 00:05:15,883
across all pages without having to copy them around.
7487
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.