Kiwi is targeting one thing:
To enable you to easily bring your GitHub Wiki content, with its GitHub flavored markdown syntax, to your own site.
As of now, Kiwi only contains one module/component, “Kiwi.Markdown”.
It enables you to point to a directory with Markdown files and then turns them into HTML, with support for GitHub flavored markdown like CSharp code blocks.
Kiwi.Markdown relies on other open source components to handle most of the markdown transformations and syntax highlighting:
For latest version or more info, look at the Kiwi-projects Wiki.
Setup a Controller
For this example I will use a live one. The GitHub Wiki for SisoDb which also has the wiki at http://sisodb.com/wiki
My controller is really simple. One Action and a cache profile, nothing more.
WikiController
[HandleError]
public class WikiController : Controller
{
[OutputCache(CacheProfile = "WikiCache")]
public ActionResult Doc(string docId)
{
return View(MvcApplication.MarkdownService.GetDocument(docId));
}
}
Web.config
<caching>
<outputCacheSettings>
<outputCacheProfiles>
<add name="WikiCache" duration="3600" varyByParam="docId"/>
</outputCacheProfiles>
</outputCacheSettings>
</caching>
Fix a route
My route is going to match http://sisodb.com/wiki and http://sisodb.com/wiki/{docid} where docId matches the name of the Markdown file except the file suffix.
Global.asax
routes.MapRoute(
"Wiki", // Route name
"wiki/{docId}", // URL with parameters
new { controller = "wiki", action = "doc", docId = "home" } // Parameter defaults
);
Setup a MarkdownService
A bit temporary, but as for now I’ve just put a static member in Global.Asax.
MarkdownService = new MarkdownService(new FileContentProvider(Server.MapPath("~/App_Data/MarkdownFiles"));
You can also see that I have decided to reside my Markdow files under “~/App_Data/MarkdownFiles”. There’s nothing stopping you from using MarkdownService outside a webbapplication, it has no dependencies on any web stack.
Get the Markdown files
Go to the Wiki at your GitHub project and check under Git Access example. Bring down the files using git clone
Take the files and put them in the ASP.Net MVC application’s folder containing Markdown files (App_Data/Markdownfiles).
Tip
When moving the files to a server, you can use the strengths and features of Git.
# Clone and Get the Wiki locally git clone git://github.com/danielwertheim/Kiwi.wiki.git # Create a Zip which you can upload git archive master --format=zip -o Kiwi-Package.zip
Setup the view
Wiki/Doc.cshtml
@using Kiwi.Markdown
@model Document
@{
ViewBag.Title = @Model.Title;
}
<div class="post">
<h1 class="title">@Model.Title</h1>
<div class="entry">@Html.Raw(Model.Content)</div>
</div>
That’s it. Nothing more. There will be other Kiwi components coming that will assist you with the publishing etc of new Markdown files.
Coming feature
I’m working on a small MVC area that will let you complement the flow above with something like:
# Upload the Zip using Curl curl --upload-file package=@Kiwi-New.zip http://sisodb.com/kiwi/package/put
Of course, the example above misses out setting headers for security, info but I guess you get the point.