Skip to content

Instantly share code, notes, and snippets.

@davepermen
Last active September 30, 2023 11:21
Show Gist options
  • Save davepermen/12133a13aee3d6b8e4a69722b597fae4 to your computer and use it in GitHub Desktop.
Save davepermen/12133a13aee3d6b8e4a69722b597fae4 to your computer and use it in GitHub Desktop.
Generate Navigation Filename
using System;
var monthnames = new [] { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
var years = new [] { 2007, 2008, 2009, 2010 };
var months = Enumerable.Range(1, 12);
Directory.CreateDirectory("navigation-segments");
foreach(var year in years)
{
foreach (var month in months)
{
var shortyear = $"{(year - 2000):00}";
var shortmonth = $"{month:00}";
var filename = $"{shortyear}{shortmonth}-nav.html";
Console.WriteLine($"{year}/{month}: {filename}");
CreateNavigationFor(year, month, filename);
Console.WriteLine();
Console.WriteLine();
Console.WriteLine();
Console.WriteLine();
}
}
void CreateNavigationFor(int currentyear, int currentmonth, string filename)
{
/// <nav style="grid-area: nav">
/// <h2>2008 2009 2010 2011</h2>
/// <h3>jan feb <a href="2008-mar.html">mar</a> ....</h3>
/// </nav>
using var file = File.Create("navigation-segments/" + filename);
using var writer = new StreamWriter(file);
writer.WriteLine("<nav style=\"grid-area: nav\">");
writer.WriteLine(" <h2>");
foreach (var year in years)
{
var shortyear = $"{(year - 2000):00}";
var shortmonth = $"{currentmonth:00}";
var link = $"{shortyear}{shortmonth}.html";
if(year == currentyear)
{
writer.WriteLine($" <a href='{link}' class='current'>{year}</a>");
}
else
{
writer.WriteLine($" <a href='{link}'>{year}</a>");
}
}
writer.WriteLine(" </h2>");
writer.WriteLine(" <h3>");
foreach (var month in months)
{
var shortyear = $"{(currentyear - 2000):00}";
var shortmonth = $"{month:00}";
var link = $"{shortyear}{shortmonth}.html";
if (month == currentmonth)
{
writer.WriteLine($" <a href='{link}' class='current'>{monthnames[month - 1]}</a>");
}
else
{
writer.WriteLine($" <a href='{link}'>{monthnames[month - 1]}</a>");
}
}
writer.WriteLine(" </h3>");
writer.WriteLine("</nav>");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment