Skip to content

Instantly share code, notes, and snippets.

@AThraen
Created May 11, 2020 07:45
Show Gist options
  • Select an option

  • Save AThraen/f6c83e89e64efb6461e1091af9ca8cef to your computer and use it in GitHub Desktop.

Select an option

Save AThraen/f6c83e89e64efb6461e1091af9ca8cef to your computer and use it in GitHub Desktop.
Using Wyam to build a blog website from an RssFeed
<html>
<head>
<title>@ViewBag.Title</title>
</head>
<body>
@RenderBody()
</body>
</html>
@{
Layout = "_Layout.cshtml";
}
// This directive installs packages from NuGet and is what you would normally use
#n Wyam.Razor
// This directive loads modules directly from the local build and is used for testing
// NOTE: If running the example against modules built from source, call wyam.exe from the Wyam.Examples.Tests/bin/Debug folder
#a **/*
// Normalize the culture for the examples so they produce the same output regardless of system culture
System.Globalization.CultureInfo.DefaultThreadCurrentCulture
= System.Globalization.CultureInfo.CreateSpecificCulture("en-US");
Pipelines.Add("Posts",
Download("https://www.codeart.dk/blog/rss/"),
Xml("//item"),
Merge(ReadFiles("post/post.cshtml")),
Razor(),
Index(),
Title(@doc["title"]),
Meta("PostFile",string.Format(@"posts\{0}.html", @doc["Index"])),
WriteFiles((string)@doc["PostFile"])
);
Pipelines.Add("Home",
ReadFiles("home.cshtml"),
Razor(),
WriteFiles(".html")
);
@{ViewBag.Title="Blog posts";}
<h1>Blog posts from CodeArt</h1>
@foreach(var doc in Documents["Posts"].OrderBy(x => x["Title"]))
{
<ul>
<li><a href="@doc["PostFile"]">@doc["Title"]</a> - @doc["pubDate"]</li>
</ul>
}
@{
ViewBag.Title=Metadata["Title"];
}
<h1 style="color:red">@Metadata["Title"]</h1>
<h2>@Metadata["pubDate"]</h2>
<hr />
<p>@Metadata["description"]</p>
<a href="@Metadata["link"]">Read more...</a>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment