Skip to content

Instantly share code, notes, and snippets.

@guardrex
Created May 23, 2017 00:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save guardrex/6e91f66d4084022f0c8ca1e482bddf2e to your computer and use it in GitHub Desktop.
Save guardrex/6e91f66d4084022f0c8ca1e482bddf2e to your computer and use it in GitHub Desktop.
Title fixes
using System;
using System.Collections.Generic;
using System.IO;
using static System.IO.SearchOption;
namespace RemoveBlankLines
{
class Program
{
static void Main()
{
string path = @"C:\Users\XXXXXXXX\Documents\GitHub\docs-1\docs\";
var files = Directory.EnumerateFiles(path, "*.md", AllDirectories);
foreach (var file in files)
{
var changed = false;
var inputLines = File.ReadAllLines(file);
var outputLines = new List<string>();
foreach (var line in inputLines)
{
var trimmedLine = line.Trim();
if (trimmedLine.StartsWith("title:"))
{
var noQuotesLine = trimmedLine.Replace("\"", string.Empty);
if (!noQuotesLine.EndsWith("Microsoft Docs"))
{
outputLines.Add($"{noQuotesLine} | Microsoft Docs");
changed = true;
}
else
{
outputLines.Add(noQuotesLine);
}
}
else
{
outputLines.Add(line);
}
}
if (changed)
{
Console.WriteLine(file.Substring(path.Length));
File.WriteAllLines(file, outputLines);
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment