Skip to content

Commit 013abbb

Browse files
Add Open Graph tags
1 parent 379316a commit 013abbb

3 files changed

Lines changed: 42 additions & 0 deletions

File tree

src/UndefinedLabs/Components/Pages/FileView.razor

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,20 @@
11
@using UndefinedLabs.Models
22
@inject ConvexService ConvexService
3+
@inject IConfiguration Configuration
34
@page "/f/{Slug}"
45

56
<PageTitle>File - @Slug</PageTitle>
67

8+
@if (_record is not null)
9+
{
10+
<HeadContent>
11+
<meta property="og:type" content="website" />
12+
<meta property="og:title" content="@_record.FileName" />
13+
<meta property="og:description" content="File - @FormatBytes(_record.FileSize) — @_record.ContentType" />
14+
<meta property="og:url" content="@_baseUrl/f/@Uri.EscapeDataString(Slug)" />
15+
</HeadContent>
16+
}
17+
718
@if (_notFound)
819
{
920
<NotFound />
@@ -51,11 +62,13 @@ else
5162

5263
private UploadRecord? _record;
5364
private bool _notFound;
65+
private string _baseUrl = string.Empty;
5466

5567
protected override async Task OnParametersSetAsync()
5668
{
5769
_record = null;
5870
_notFound = false;
71+
_baseUrl = (Configuration["PUBLIC_BASE_URL"] ?? "").TrimEnd('/');
5972

6073
_record = await ConvexService.QueryAsync<UploadRecord?>(
6174
"files:getBySlug",

src/UndefinedLabs/Components/Pages/ImageView.razor

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,23 @@
11
@using UndefinedLabs.Models
22
@inject ConvexService ConvexService
3+
@inject IConfiguration Configuration
34
@page "/i/{Slug}"
45

56
<PageTitle>Image - @Slug</PageTitle>
67

8+
@if (_record is not null)
9+
{
10+
<HeadContent>
11+
<meta property="og:type" content="website" />
12+
<meta property="og:title" content="@_record.FileName" />
13+
<meta property="og:description" content="@FormatBytes(_record.FileSize) - Uploaded @FormatDate(_record.CreationTime)" />
14+
<meta property="og:url" content="@_baseUrl/i/@Uri.EscapeDataString(Slug)" />
15+
<meta property="og:image" content="@_baseUrl/content/i/@Uri.EscapeDataString(Slug)" />
16+
<meta property="og:image:type" content="@_record.ContentType" />
17+
<meta name="twitter:card" content="summary_large_image" />
18+
</HeadContent>
19+
}
20+
721
@if (_notFound)
822
{
923
<NotFound />
@@ -52,11 +66,13 @@ else
5266

5367
private UploadRecord? _record;
5468
private bool _notFound;
69+
private string _baseUrl = string.Empty;
5570

5671
protected override async Task OnParametersSetAsync()
5772
{
5873
_record = null;
5974
_notFound = false;
75+
_baseUrl = (Configuration["PUBLIC_BASE_URL"] ?? "").TrimEnd('/');
6076

6177
_record = await ConvexService.QueryAsync<UploadRecord?>(
6278
"images:getBySlug",

src/UndefinedLabs/Components/Pages/TextView.razor

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,20 @@
11
@using UndefinedLabs.Models
22
@inject ConvexService ConvexService
3+
@inject IConfiguration Configuration
34
@page "/t/{Slug}"
45

56
<PageTitle>Text - @Slug</PageTitle>
67

8+
@if (_record is not null)
9+
{
10+
<HeadContent>
11+
<meta property="og:type" content="website" />
12+
<meta property="og:title" content="@_record.FileName" />
13+
<meta property="og:description" content="Text - @FormatBytes(_record.FileSize)" />
14+
<meta property="og:url" content="@_baseUrl/t/@Uri.EscapeDataString(Slug)" />
15+
</HeadContent>
16+
}
17+
718
@if (_notFound)
819
{
920
<NotFound />
@@ -37,12 +48,14 @@ else
3748
private UploadRecord? _record;
3849
private string _textContent = string.Empty;
3950
private bool _notFound;
51+
private string _baseUrl = string.Empty;
4052

4153
protected override async Task OnParametersSetAsync()
4254
{
4355
_record = null;
4456
_textContent = string.Empty;
4557
_notFound = false;
58+
_baseUrl = (Configuration["PUBLIC_BASE_URL"] ?? "").TrimEnd('/');
4659

4760
_record = await ConvexService.QueryAsync<UploadRecord?>(
4861
"texts:getBySlug",

0 commit comments

Comments
 (0)