Skip to content

Commit

Permalink
Use relative links
Browse files Browse the repository at this point in the history
  • Loading branch information
lauraneto committed Aug 27, 2023
1 parent e6ccb4a commit 7f796ce
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 29 deletions.
22 changes: 19 additions & 3 deletions src/UmbracoDemo.Client/Helpers/UmbracoApiExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Collections.Concurrent;
using System.Reflection;
using UmbracoDemo.Client.Models;
using UmbracoDemo.Client.Models.Pages.Abstractions;

namespace UmbracoDemo.Client.Helpers;
Expand All @@ -19,10 +20,25 @@ public static T ToContent<T>(this IApiContentResponseModel source, bool preview)
page.Id = source.Id;
page.ContentType = source.ContentType;
page.Name = source.Name;
page.StartItem = source.Route.StartItem.Id;
page.Culture = source.Cultures.FirstOrDefault(c => c.Value.Path == source.Route.Path).Key;
page.Cultures = source.Cultures.ToDictionary(c => c.Key, c => c.Value.Path);
page.Path = source.Route.Path;
page.Cultures = source.Cultures.ToDictionary(c => c.Key, c => new Route
{
Path = c.Value.Path,
StartItem = new StartItem
{
Id = c.Value.StartItem.Id,
Path = c.Value.StartItem.Path
}
});
page.Route = new Route
{
Path = source.Route.Path,
StartItem = new StartItem
{
Id = source.Route.StartItem.Id,
Path = source.Route.StartItem.Path
}
};
page.Preview = preview;
}

Expand Down
17 changes: 4 additions & 13 deletions src/UmbracoDemo.Client/Models/DataTypes/Link.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,9 @@ public class Link
public Route? Route { get; set; }

public string LinkType { get; set; }

Check warning on line 17 in src/UmbracoDemo.Client/Models/DataTypes/Link.cs

View workflow job for this annotation

GitHub Actions / deploy-to-github-pages

Non-nullable property 'LinkType' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.
}

public class Route
{
public required string Path { get; set; }

public required StartItem StartItem { get; set; }
}

public class StartItem
{
public required string Id { get; set; }

public required string Path { get; set; }
public string GetUrl()
{
return Url ?? Route?.GetUrl() ?? "#";
}
}
6 changes: 2 additions & 4 deletions src/UmbracoDemo.Client/Models/Pages/Abstractions/BasePage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ public abstract class BasePage

public bool Preview { get; set; }

public Dictionary<string, string> Cultures { get; set; } = new();
public Dictionary<string, Route> Cultures { get; set; } = new();

public Guid StartItem { get; set; }

public string Path { get; set; }
public Route Route { get; set; }

Check warning on line 17 in src/UmbracoDemo.Client/Models/Pages/Abstractions/BasePage.cs

View workflow job for this annotation

GitHub Actions / deploy-to-github-pages

Non-nullable property 'Route' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.
}
13 changes: 13 additions & 0 deletions src/UmbracoDemo.Client/Models/Route.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace UmbracoDemo.Client.Models;

public class Route
{
public required string Path { get; set; }

public required StartItem StartItem { get; set; }

public string GetUrl()
{
return Path.Trim('/');
}
}
8 changes: 8 additions & 0 deletions src/UmbracoDemo.Client/Models/StartItem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace UmbracoDemo.Client.Models;

public class StartItem
{
public required Guid Id { get; set; }

public required string Path { get; set; }
}
4 changes: 2 additions & 2 deletions src/UmbracoDemo.Client/Pages/BlogOverview.razor
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<MudText Typo="Typo.body2">@((MarkupString)(child.Intro?.Markup ?? ""))</MudText>
</MudCardContent>
<MudCardActions>
<MudButton Href="@child.Path" Variant="Variant.Text" Color="Color.Transparent" EndIcon="@Icons.Material.Filled.ArrowRight">Read more</MudButton>
<MudButton Href="@child.Route.GetUrl()" Variant="Variant.Text" Color="Color.Transparent" EndIcon="@Icons.Material.Filled.ArrowRight">Read more</MudButton>
</MudCardActions>
</MudCard>
</MudItem>
Expand Down Expand Up @@ -86,7 +86,7 @@
return;
}

Children = (await UmbracoClient.GetChildrenByPath(Page.Path, sort: _currentSort != null ? new[] { $"{_currentSort.SortName}:{_currentSort.SortOrder}" } : null)).OfType<UmbracoDemo.Client.Models.Pages.BlogDetail>().ToList();
Children = (await UmbracoClient.GetChildrenByPath(Page.Route.Path, sort: _currentSort != null ? new[] { $"{_currentSort.SortName}:{_currentSort.SortOrder}" } : null)).OfType<UmbracoDemo.Client.Models.Pages.BlogDetail>().ToList();
}

public class SortItem
Expand Down
2 changes: 1 addition & 1 deletion src/UmbracoDemo.Client/Pages/Index.razor
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
_loaded = false;

var slug = $"/{Slug}";
if (slug != _page?.Path || forceUpdate)
if (slug != _page?.Route.Path || forceUpdate)
{
_page = await UmbracoClient.GetContentByPath($"/{Slug}");
}
Expand Down
2 changes: 1 addition & 1 deletion src/UmbracoDemo.Client/Pages/SearchPage.razor
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<MudText Typo="Typo.body2" Class="line-clamp-3">@((MarkupString)(basePage?.Intro?.Markup ?? ""))</MudText>
</MudCardContent>
<MudCardActions>
<MudButton Href="@result.Path" Variant="Variant.Text" Color="Color.Transparent" EndIcon="@Icons.Material.Filled.ArrowRight">Read more</MudButton>
<MudButton Href="@result.Route.GetUrl()" Variant="Variant.Text" Color="Color.Transparent" EndIcon="@Icons.Material.Filled.ArrowRight" HtmlTag="a">Read more</MudButton>
</MudCardActions>
</MudCard>
</MudItem>
Expand Down
2 changes: 1 addition & 1 deletion src/UmbracoDemo.Client/Shared/LanguagePicker.razor
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<MudMenu EndIcon="@Icons.Material.Filled.KeyboardArrowDown" Label="@GetFriendlyName(Page?.Culture ?? "en-US")" Color="Color.Transparent" Variant="Variant.Text">
@foreach (var culture in Page!.Cultures)
{
<MudMenuItem Href="@culture.Value">@GetFriendlyName(culture.Key)</MudMenuItem>
<MudMenuItem Href="@culture.Value.GetUrl()">@GetFriendlyName(culture.Key)</MudMenuItem>
}
</MudMenu>
}
Expand Down
8 changes: 4 additions & 4 deletions src/UmbracoDemo.Client/Shared/NavMenu.razor
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@
@using UmbracoDemo.Client.Models.Pages
@using UmbracoDemo.Client.Models.Pages.Abstractions
@using UmbracoDemo.Client.Services
<MudIconButton Icon="@Icons.Material.Outlined.Home" Color="Color.Inherit" Link="@((Settings?.HomeLink?.FirstOrDefault() is {} link ? (link.Url ?? link.Route?.Path) : null) ?? "/")" />
<MudIconButton Icon="@Icons.Material.Outlined.Home" Color="Color.Inherit" Href="@(Settings?.HomeLink?.FirstOrDefault()?.GetUrl())" HtmlTag="a" />
<MudSpacer />
<MudHidden Breakpoint="Breakpoint.SmAndUp" Invert="true">
@foreach (var link in Settings?.HeaderLinks ?? Enumerable.Empty<Link>())
{
<MudLink Color="Color.Inherit" Href="@(link.Url ?? link.Route?.Path)" Match="NavLinkMatch.Prefix" Class="mx-8">@link.Title</MudLink>
<MudLink Color="Color.Inherit" Href="@link.GetUrl()" Match="NavLinkMatch.Prefix" Class="mx-8">@link.Title</MudLink>
}
</MudHidden>
<MudSpacer />
<PreviewToggle OnPreviewToggled="OnPreviewToggled" />
<MudIconButton Icon="@Icons.Material.Outlined.Search" Color="Color.Inherit" Link="@((Settings?.SearchLink?.FirstOrDefault() is {} searchLink ? (searchLink.Url ?? searchLink.Route?.Path) : null) ?? "/")" />
<MudIconButton Icon="@Icons.Material.Outlined.Search" Color="Color.Inherit" Link="@(Settings?.SearchLink?.FirstOrDefault()?.GetUrl())" />
<LanguagePicker Page="Page" />
<MudHidden Breakpoint="Breakpoint.SmAndUp" Invert="false">
<MudMenu Label="Open Menu" Icon="@Icons.Material.Outlined.Menu" Color="Color.Inherit">
@foreach (var link in Settings?.HeaderLinks ?? Enumerable.Empty<Link>())
{
<MudMenuItem Color="Color.Inherit" Href="@(link.Url ?? link.Route?.Path)" Match="NavLinkMatch.All">@link.Title</MudMenuItem>
<MudMenuItem Color="Color.Inherit" Href="@link.GetUrl()" Match="NavLinkMatch.All">@link.Title</MudMenuItem>
}
</MudMenu>
</MudHidden>
Expand Down

0 comments on commit 7f796ce

Please sign in to comment.