Skip to content

Commit ce65020

Browse files
committed
archive
1 parent 48ed632 commit ce65020

File tree

6 files changed

+59
-1
lines changed

6 files changed

+59
-1
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
@model Blog.Web.Actions.PostGet.PostIndexViewModel
2+
3+
@{
4+
ViewBag.Title = "All Posts";
5+
Layout = "~/Views/_Layout.cshtml";
6+
}
7+
8+
<h2>Archive</h2>
9+
10+
<section id="archive">
11+
<h4>@Model.Active.Count posts @(Model.Future.Any() ? Model.Future.Count + " future" : "")</h4>
12+
<ul>
13+
@foreach (var post in Model.Active)
14+
{
15+
<li>
16+
<small>@post.PublishedAtCst.ToString("yyyy.MMM.dd")</small>
17+
<a href="@Url.Action("Execute", "PostGet", new {slug = post.Slug})" title="@post.Title">
18+
<span>@post.Title</span>
19+
</a>
20+
</li>
21+
}
22+
</ul>
23+
</section>

src/Blog.Web/Actions/PostGet/PostGetController.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ public void Execute(IContainer container)
2323
result = new MarkdownContentStorage(root).Handle(message, result);
2424
return result;
2525
});
26+
27+
mediator.Subscribe<PostIndexRequest, PostIndexViewModel>(message => new FilteredPostVault().Handle(message));
2628
}
2729
}
2830

@@ -41,6 +43,12 @@ public ActionResult Execute(PostRequest request)
4143
if (model.Post == null) return HttpNotFound();
4244
return View(model);
4345
}
46+
47+
public ActionResult Index()
48+
{
49+
var model = _mediator.Send<PostIndexRequest, PostIndexViewModel>(new PostIndexRequest());
50+
return View(model);
51+
}
4452
}
4553

4654
public class PostRequest
@@ -60,4 +68,12 @@ public class PostGetViewModel
6068
public bool HasPrevious { get { return Previous != null; } }
6169
public bool HasNext { get { return Next != null; } }
6270
}
71+
72+
public class PostIndexRequest { }
73+
74+
public class PostIndexViewModel
75+
{
76+
public IReadOnlyCollection<Post> Active { get; set; }
77+
public IReadOnlyCollection<Post> Future { get; set; }
78+
}
6379
}

src/Blog.Web/Blog.Web.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,9 @@
274274
<ItemGroup>
275275
<Content Include="Actions\DisplayErrors\Http404.cshtml" />
276276
</ItemGroup>
277+
<ItemGroup>
278+
<Content Include="Actions\PostGet\Index.cshtml" />
279+
</ItemGroup>
277280
<PropertyGroup>
278281
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
279282
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>

src/Blog.Web/Content/css/site.css

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,6 @@ footer p {
8282
/* Large format tablet and desktop */
8383
@media only screen and (min-width: 768px) {
8484

85-
}
85+
}
86+
87+
#archive ul { list-style-type: none;margin: 0;}

src/Blog.Web/Infrastructure/FilteredPostVault.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,15 @@ public PostGetViewModel Handle(PostRequest message, PostGetViewModel result)
4444
return result;
4545
}
4646

47+
public PostIndexViewModel Handle(PostIndexRequest message)
48+
{
49+
var result = new PostIndexViewModel();
50+
result.Active = ActivePosts;
51+
result.Future = FuturePosts;
52+
53+
return result;
54+
}
55+
4756
public AtomGetViewModel Handle(AtomRequest message)
4857
{
4958
return new AtomGetViewModel {Posts = ActivePosts};

src/Blog.Web/Initialization/RouteConfig.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ public static void RegisterRoutes(RouteCollection routes)
99
{
1010
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
1111

12+
routes.MapRoute(
13+
null,
14+
"posts",
15+
new { controller = "PostGet", action = "Index" });
16+
1217
routes.MapRoute(
1318
null,
1419
"atom",

0 commit comments

Comments
 (0)