Skip to content

Commit

Permalink
Made permalinks consistent. Fixes #197 & fixes #196
Browse files Browse the repository at this point in the history
  • Loading branch information
tidyui committed Mar 1, 2018
1 parent a548165 commit fd00f6d
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 6 deletions.
4 changes: 2 additions & 2 deletions core/Piranha/App.cs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ private void Initialize(IApi api) {
.ForMember(f => f.Items, o => o.Ignore());
cfg.CreateMap<Data.Page, Models.PageBase>()
.ForMember(p => p.TypeId, o => o.MapFrom(m => m.PageTypeId))
.ForMember(p => p.Permalink, o => o.MapFrom(m => m.Slug));
.ForMember(p => p.Permalink, o => o.MapFrom(m => "/" + m.Slug));
cfg.CreateMap<Models.PageBase, Data.Page>()
.ForMember(p => p.PageTypeId, o => o.MapFrom(m => m.TypeId))
.ForMember(p => p.Fields, o => o.Ignore())
Expand All @@ -226,7 +226,7 @@ private void Initialize(IApi api) {
.ForMember(p => p.Created, o => o.Ignore());
cfg.CreateMap<Data.Post, Models.PostBase>()
.ForMember(p => p.TypeId, o => o.MapFrom(m => m.PostTypeId))
.ForMember(p => p.Permalink, o => o.MapFrom(m => m.Blog.Slug + "/" + m.Slug));
.ForMember(p => p.Permalink, o => o.MapFrom(m => "/" + m.Blog.Slug + "/" + m.Slug));
cfg.CreateMap<Models.PostBase, Data.Post>()
.ForMember(p => p.PostTypeId, o => o.MapFrom(m => m.TypeId))
.ForMember(p => p.CategoryId, o => o.MapFrom(m => m.Category.Id))
Expand Down
2 changes: 1 addition & 1 deletion examples/CoreWeb/Views/Cms/Archive.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
@foreach (var post in Model.Archive.Posts) {
<article>
<header>
<h2><a href="~/@post.Permalink">@post.Title</a></h2>
<h2><a href="@post.Permalink">@post.Title</a></h2>
</header>
<p class="small">Published: @post.Published.Value.ToString("yyyy-MM-dd") in @post.Category.Title</p>
<p>
Expand Down
11 changes: 11 additions & 0 deletions test/Piranha.Tests/Repositories/Pages.cs
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,17 @@ public void GetDynamicBySlug() {
}
}

[Fact]
public void CheckPermlinkSyntax() {
using (var api = new Api(GetDb(), storage, cache)) {
var model = api.Pages.GetById(PAGE_1_ID);

Assert.NotNull(model);
Assert.NotNull(model.Permalink);
Assert.StartsWith("/", model.Permalink);
}
}

[Fact]
public void GetCollectionPage() {
using (var api = new Api(GetDb(), storage, cache)) {
Expand Down
17 changes: 14 additions & 3 deletions test/Piranha.Tests/Repositories/Posts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ public void GetGenericById() {

Assert.NotNull(model);
Assert.Equal("my-first-post", model.Slug);
Assert.Equal("blog/my-first-post", model.Permalink);
Assert.Equal("/blog/my-first-post", model.Permalink);
Assert.Equal("My first body", model.Body.Value);
}
}
Expand All @@ -301,7 +301,7 @@ public void GetGenericBySlug() {

Assert.NotNull(model);
Assert.Equal("my-first-post", model.Slug);
Assert.Equal("blog/my-first-post", model.Permalink);
Assert.Equal("/blog/my-first-post", model.Permalink);
Assert.Equal("My first body", model.Body.Value);
}
}
Expand All @@ -313,7 +313,7 @@ public void GetDynamicById() {

Assert.NotNull(model);
Assert.Equal("my-first-post", model.Slug);
Assert.Equal("blog/my-first-post", model.Permalink);
Assert.Equal("/blog/my-first-post", model.Permalink);
Assert.Equal("My first body", model.Regions.Body.Value);
}
}
Expand All @@ -329,6 +329,17 @@ public void GetDynamicBySlug() {
}
}

[Fact]
public void CheckPermlinkSyntax() {
using (var api = new Api(GetDb(), storage, cache)) {
var model = api.Posts.GetById(POST_1_ID);

Assert.NotNull(model);
Assert.NotNull(model.Permalink);
Assert.StartsWith("/", model.Permalink);
}
}

[Fact]
public void GetCollectionPost() {
using (var api = new Api(GetDb(), storage, cache)) {
Expand Down
12 changes: 12 additions & 0 deletions test/Piranha.Tests/Repositories/Sites.cs
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,18 @@ public void GetSitemapById() {
}
}

[Fact]
public void CheckPermlinkSyntax() {
using (var api = new Api(GetDb(), storage, cache)) {
var sitemap = api.Sites.GetSitemap();

foreach (var item in sitemap) {
Assert.NotNull(item.Permalink);
Assert.StartsWith("/", item.Permalink);
}
}
}

[Fact]
public void GetUnpublishedSitemap() {
using (var api = new Api(GetDb(), storage, cache)) {
Expand Down

0 comments on commit fd00f6d

Please sign in to comment.