Created
June 3, 2016 16:38
-
-
Save hyrmn/28e1cb635ad409826e433cbf7029c5e1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#n Wyam.Markdown -p | |
#n Wyam.Razor -p | |
#n Wyam.Yaml -p | |
#n Wyam.Minification -p | |
#n AngleSharp | |
#an "System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" | |
#an "System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" | |
Settings.Host = "hyr.mn"; | |
//Process each post as /post-sluggified-name/index.html so we get what looks like extensionless pages on gh-pages | |
Pipelines.Add("Posts", | |
ReadFiles("posts/*.md"), // Read all markdown files in the "posts" directory | |
FrontMatter(Yaml()), // Load any frontmatter and parse it as YAML markup | |
Markdown(), // Render the markdown content | |
Meta("Post", @doc.Content), // Move the markdown content to metadata | |
Merge( | |
ReadFiles("posts/post.cshtml") // Load the Razor post page template | |
), | |
Razor(), // Compile and render the page template | |
Meta("PostFile", string.Format(@"{0}\index.html", ((string)@doc["Title"]).ToLower().Replace(' ', '-'))), // Use the post title as the filename and save it in metadata so we can use it in links later | |
Meta("PostLink", string.Format(@"{0}/", ((string)@doc["Title"]).ToLower().Replace(' ', '-'))), // Friendly link for post | |
WriteFiles((string)@doc["PostFile"]) // Write the post file | |
); | |
//I want the most recent post to be the home index as well. | |
Pipelines.Add("MostRecentAsIndex", | |
ReadFiles("posts/*.md"), // Read all markdown files in the "posts" directory | |
OrderBy(@doc.Get<DateTime>("Published")), | |
Take(1), | |
FrontMatter(Yaml()), // Load any frontmatter and parse it as YAML markup | |
Markdown(), // Render the markdown content | |
Meta("Post", @doc.Content), // Move the markdown content to metadata | |
Razor(), // Compile and render the page template | |
Meta("PostFile", string.Format(@"{0}\index.html", ((string)@doc["Title"]).ToLower().Replace(' ', '-'))), // Use the post title as the filename and save it in metadata so we can use it in links later | |
Meta("PostLink", string.Format(@"{0}/", ((string)@doc["Title"]).ToLower().Replace(' ', '-'))), // Friendly link for post | |
WriteFiles((doc, ctx) => "index.html") | |
); | |
//Process the rest of the top-level pages | |
Pipelines.Add("TopLevel", | |
ReadFiles("{!_,!index}*.cshtml"), | |
FrontMatter(Yaml()), | |
Razor(), | |
WriteFiles(".html") | |
); | |
//Combine and minify the css assets | |
Pipelines.Add("css", | |
ReadFiles("css/*.css"), | |
MinifyCss(), | |
Combine(), | |
WriteFiles((doc, ctx) => "css/style.css") | |
); | |
//Copy over the other layout assets (images, font) | |
Pipelines.Add("Assets", | |
CopyFiles("css/*{!.css,}") | |
); |
The other ones like OrderBy didn't click for me though.
You've got the call right. I would expect the first try of yours to work:
OrderBy(@doc.Get<DateTime>("Published")).Descending(),
Take(1),
I'm assuming this is in relation to the "MostRecentAsIndex" pipeline above:
Pipelines.Add("MostRecentAsIndex",
ReadFiles("posts/*.md"), // Read all markdown files in the "posts" directory
OrderBy(@doc.Get<DateTime>("Published")),
Take(1),
FrontMatter(Yaml()), // Load any frontmatter and parse it as YAML markup
Markdown(), // Render the markdown content
// ...
The problem is that at the point where you're calling OrderBy
the front matter hasn't been processed yet, so there isn't a "Published" metadata key in the documents to order by. In that case the delegate that gets the metadata value for OrderBy
is returning a default value, which is the same for every document. Change the pipeline to this and it should work:
Pipelines.Add("MostRecentAsIndex",
ReadFiles("posts/*.md"), // Read all markdown files in the "posts" directory
FrontMatter(Yaml()), // Load any frontmatter and parse it as YAML markup
OrderBy(@doc.Get<DateTime>("Published")),
Take(1),
Markdown(), // Render the markdown content
// ...
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The lambda is fine. I just wanted to make sure I'm not missing something super-obvious. I think use cases like what I have are uncommon enough that the 'pain' is not a big deal. I think a 1->1 mapping is more common and you've already got @doc or the frontmatter to handle a naming redirect.