diff --git a/OurUmbraco.Site/OurUmbraco.Site.csproj b/OurUmbraco.Site/OurUmbraco.Site.csproj index 330c34c1..b05b9f7e 100644 --- a/OurUmbraco.Site/OurUmbraco.Site.csproj +++ b/OurUmbraco.Site/OurUmbraco.Site.csproj @@ -4730,10 +4730,6 @@ {a625544f-660a-4c01-ba49-1b467d0322d9} our.umbraco.org - - {2040bdaf-a804-462f-8d5f-ca0df141bf89} - uDocumentation - {f356b339-296a-4594-81b6-cf69a802483e} uEvents diff --git a/uDocumentation/Busineslogic/ConventionExtensions.cs b/OurUmbraco/Documentation/Busineslogic/ConventionExtensions.cs similarity index 96% rename from uDocumentation/Busineslogic/ConventionExtensions.cs rename to OurUmbraco/Documentation/Busineslogic/ConventionExtensions.cs index 5ebcff5c..098dfc29 100644 --- a/uDocumentation/Busineslogic/ConventionExtensions.cs +++ b/OurUmbraco/Documentation/Busineslogic/ConventionExtensions.cs @@ -1,31 +1,31 @@ -namespace uDocumentation.Busineslogic -{ - public static class ConventionExtensions - { - public static string EnsureNoDotsInUrl(this string url) - { - return url.Replace(".", "_") - .Replace("__", "..") - .Replace("_md", "") - .Replace("_png", ".png") - .Replace("_jpg", ".jpg") - .Replace("_pdf", ".pdf") - .Replace("_gif", ".gif"); - } - - public static string UnderscoreToDot(this string str) - { - return str.Replace("_", "."); - } - - public static string RemoveDash(this string str) - { - return str.Replace("-", " "); - } - - public static string EnsureCorrectDocumentationText(this string str) - { - return str.Replace("documentation", "Documentation"); - } - } +namespace uDocumentation.Busineslogic +{ + public static class ConventionExtensions + { + public static string EnsureNoDotsInUrl(this string url) + { + return url.Replace(".", "_") + .Replace("__", "..") + .Replace("_md", "") + .Replace("_png", ".png") + .Replace("_jpg", ".jpg") + .Replace("_pdf", ".pdf") + .Replace("_gif", ".gif"); + } + + public static string UnderscoreToDot(this string str) + { + return str.Replace("_", "."); + } + + public static string RemoveDash(this string str) + { + return str.Replace("-", " "); + } + + public static string EnsureCorrectDocumentationText(this string str) + { + return str.Replace("documentation", "Documentation"); + } + } } \ No newline at end of file diff --git a/uDocumentation/Busineslogic/DefaultVersion.cs b/OurUmbraco/Documentation/Busineslogic/DefaultVersion.cs similarity index 95% rename from uDocumentation/Busineslogic/DefaultVersion.cs rename to OurUmbraco/Documentation/Busineslogic/DefaultVersion.cs index 5519ab22..578d3579 100644 --- a/uDocumentation/Busineslogic/DefaultVersion.cs +++ b/OurUmbraco/Documentation/Busineslogic/DefaultVersion.cs @@ -1,29 +1,29 @@ -namespace uDocumentation.Busineslogic -{ - public class DefaultVersion - { - private static DefaultVersion _instance; - - private DefaultVersion() { } - - public static DefaultVersion Instance - { - get - { - if (_instance == null) - { - _instance = new DefaultVersion(); - } - return _instance; - } - } - - public string Number - { - get - { - return "master";//Read default version from web.config - } - } - } +namespace uDocumentation.Busineslogic +{ + public class DefaultVersion + { + private static DefaultVersion _instance; + + private DefaultVersion() { } + + public static DefaultVersion Instance + { + get + { + if (_instance == null) + { + _instance = new DefaultVersion(); + } + return _instance; + } + } + + public string Number + { + get + { + return "master";//Read default version from web.config + } + } + } } \ No newline at end of file diff --git a/uDocumentation/Busineslogic/Events.cs b/OurUmbraco/Documentation/Busineslogic/Events.cs similarity index 100% rename from uDocumentation/Busineslogic/Events.cs rename to OurUmbraco/Documentation/Busineslogic/Events.cs diff --git a/uDocumentation/Busineslogic/GithubSourcePull/ZipDownloader.cs b/OurUmbraco/Documentation/Busineslogic/GithubSourcePull/ZipDownloader.cs similarity index 97% rename from uDocumentation/Busineslogic/GithubSourcePull/ZipDownloader.cs rename to OurUmbraco/Documentation/Busineslogic/GithubSourcePull/ZipDownloader.cs index ce1ac606..b0c3e97b 100644 --- a/uDocumentation/Busineslogic/GithubSourcePull/ZipDownloader.cs +++ b/OurUmbraco/Documentation/Busineslogic/GithubSourcePull/ZipDownloader.cs @@ -1,336 +1,336 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Web; -using System.Xml; -using System.IO; -using System.Net; -using ICSharpCode.SharpZipLib.Zip; -using System.Diagnostics; -using umbraco.BusinessLogic; -using System.Dynamic; -using Examine; -using Newtonsoft.Json; - -namespace uDocumentation.Busineslogic.GithubSourcePull -{ - public class ZipDownloader - { - private const string rootFolder = @"~\Documentation"; - private const string config = @"~\config\githubpull.config"; - private string rootFolderPath = HttpContext.Current.Server.MapPath(rootFolder); - private string configPath = HttpContext.Current.Server.MapPath(config); - - - public string RootFolder { get; set; } - public XmlDocument Configuration { get; set; } - public bool IsProjectDocumentation { get; set; } - - public ZipDownloader(string rootFolder, XmlDocument configuration) - { - Configuration = configuration; - RootFolder = rootFolder; - IsProjectDocumentation = false; - } - - public ZipDownloader() - { - XmlDocument xd = new XmlDocument(); - xd.Load(configPath); - - Configuration = xd; - RootFolder = rootFolderPath; - IsProjectDocumentation = false; - } - - public ZipDownloader(string rootFolder, string configurationPath) - { - XmlDocument xd = new XmlDocument(); - xd.Load(configurationPath); - - Configuration = xd; - RootFolder = rootFolder; - IsProjectDocumentation = false; - } - - public ZipDownloader(int projectId) - { - var project = new umbraco.NodeFactory.Node(projectId); - var githubRepo = project.GetProperty("documentationGitRepo"); - var xd = new XmlDocument(); - - xd.LoadXml(string.Format( - "", - githubRepo)); - - Configuration = xd; - RootFolder = HttpContext.Current.Server.MapPath(@"~" + project.Url.Replace("/",@"\") + @"\Documentation"); - IsProjectDocumentation = true; - } - - /// - /// This will ensure that the docs exist, this checks by the existence of the /Documentation/sitemap.js file - /// - public static void EnsureGitHubDocs(bool overwrite = false) - { - var rootFolderPath = HttpContext.Current.Server.MapPath(rootFolder); - var configPath = HttpContext.Current.Server.MapPath(config); - - //Check if it exists, if it does then exit - if (!overwrite && File.Exists(Path.Combine(rootFolderPath, "sitemap.js"))) return; - - if (!Directory.Exists(rootFolderPath)) - { - Directory.CreateDirectory(rootFolderPath); - } - - var unzip = new ZipDownloader(rootFolderPath, configPath) - { - IsProjectDocumentation = true - }; - unzip.Run(); - } - - public void Run() - { - Trace.WriteLine("Started git sync", "Gitsyncer"); - - foreach (XmlNode node in Configuration.SelectNodes("//add")) - { - var url = node.Attributes["url"].Value; - var folder = node.Attributes["folder"].Value; - var path = Path.Combine(RootFolder, folder); - - Trace.WriteLine("Loading: " + url + " to " + path, "Gitsyncer"); - - process(url, folder); - } - - +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; +using System.Xml; +using System.IO; +using System.Net; +using ICSharpCode.SharpZipLib.Zip; +using System.Diagnostics; +using umbraco.BusinessLogic; +using System.Dynamic; +using Examine; +using Newtonsoft.Json; + +namespace uDocumentation.Busineslogic.GithubSourcePull +{ + public class ZipDownloader + { + private const string rootFolder = @"~\Documentation"; + private const string config = @"~\config\githubpull.config"; + private string rootFolderPath = HttpContext.Current.Server.MapPath(rootFolder); + private string configPath = HttpContext.Current.Server.MapPath(config); + + + public string RootFolder { get; set; } + public XmlDocument Configuration { get; set; } + public bool IsProjectDocumentation { get; set; } + + public ZipDownloader(string rootFolder, XmlDocument configuration) + { + Configuration = configuration; + RootFolder = rootFolder; + IsProjectDocumentation = false; + } + + public ZipDownloader() + { + XmlDocument xd = new XmlDocument(); + xd.Load(configPath); + + Configuration = xd; + RootFolder = rootFolderPath; + IsProjectDocumentation = false; + } + + public ZipDownloader(string rootFolder, string configurationPath) + { + XmlDocument xd = new XmlDocument(); + xd.Load(configurationPath); + + Configuration = xd; + RootFolder = rootFolder; + IsProjectDocumentation = false; + } + + public ZipDownloader(int projectId) + { + var project = new umbraco.NodeFactory.Node(projectId); + var githubRepo = project.GetProperty("documentationGitRepo"); + var xd = new XmlDocument(); + + xd.LoadXml(string.Format( + "", + githubRepo)); + + Configuration = xd; + RootFolder = HttpContext.Current.Server.MapPath(@"~" + project.Url.Replace("/",@"\") + @"\Documentation"); + IsProjectDocumentation = true; + } + + /// + /// This will ensure that the docs exist, this checks by the existence of the /Documentation/sitemap.js file + /// + public static void EnsureGitHubDocs(bool overwrite = false) + { + var rootFolderPath = HttpContext.Current.Server.MapPath(rootFolder); + var configPath = HttpContext.Current.Server.MapPath(config); + + //Check if it exists, if it does then exit + if (!overwrite && File.Exists(Path.Combine(rootFolderPath, "sitemap.js"))) return; + + if (!Directory.Exists(rootFolderPath)) + { + Directory.CreateDirectory(rootFolderPath); + } + + var unzip = new ZipDownloader(rootFolderPath, configPath) + { + IsProjectDocumentation = true + }; + unzip.Run(); + } + + public void Run() + { + Trace.WriteLine("Started git sync", "Gitsyncer"); + + foreach (XmlNode node in Configuration.SelectNodes("//add")) + { + var url = node.Attributes["url"].Value; + var folder = node.Attributes["folder"].Value; + var path = Path.Combine(RootFolder, folder); + + Trace.WriteLine("Loading: " + url + " to " + path, "Gitsyncer"); + + process(url, folder); + } + + FinishEventArgs ev = new FinishEventArgs(); - FireOnFinish(ev); - } - - public dynamic DocumentationSiteMap(string folder = "") - { - var path = Path.Combine(RootFolder, folder, "sitemap.js"); - var json = File.ReadAllText(path); - dynamic d = JsonConvert.DeserializeObject(json); - return d; - } - - public void process(string url, string foldername) - { - var zip = Download(url, foldername); - unzip(zip, foldername, RootFolder); - BuildSitemap(foldername); - - //YUCK, this is horrible but unfortunately the way that the doc indexes are setup are not with - // a consistent integer id per document. I'm sure we can make that happen but I don't have time right now. - ExamineManager.Instance.IndexProviderCollection["documentationIndexer"].RebuildIndex(); - } - - private void BuildSitemap(string foldername) - { - var folder = new DirectoryInfo(Path.Combine(RootFolder, foldername)); - dynamic root = GetFolderStructure(folder, folder.FullName, 0); - - var serializedRoot = JsonConvert.SerializeObject(root, Newtonsoft.Json.Formatting.Indented); - File.WriteAllText(Path.Combine(folder.FullName, "sitemap.js"), serializedRoot); - } - - private dynamic GetFolderStructure(DirectoryInfo dir, string rootPath, int level) - { - dynamic d = new ExpandoObject(); - d.name = dir.Name; - d.path = dir.FullName.Substring(rootPath.Length).Replace('\\','/'); - d.level = level; - - if (dir.GetDirectories().Any()) - { - var list = new List(); - foreach (var child in dir.GetDirectories()) - list.Add(GetFolderStructure(child, rootPath, level+1)); - - - d.hasChildren = true; - d.directories = list; - } - - return d; - } - - private string Download(string url, string foldername) - { - var dir = new DirectoryInfo(Path.Combine(RootFolder, foldername)); - var dirsToCreate = new List(); - - while (!dir.Exists) - { - dirsToCreate.Add(dir); - dir = dir.Parent; - } - - if (dirsToCreate.Any()) - { - dirsToCreate.Reverse(); - foreach (var d in dirsToCreate) - d.Create(); - } - - var path = Path.Combine(RootFolder, foldername + "archive.zip"); - - if (File.Exists(path)) - File.Delete(path); - - WebClient Client = new WebClient(); - Client.DownloadFile(url, path); - - return path; - } - - - private void unzip(string path, string foldername, string rootFolder) - { - ZipInputStream s = new ZipInputStream(File.OpenRead(path)); - ZipEntry theEntry; - - var stopDir = "\\Documentation"; - string serverFolder = rootFolder + "\\" + foldername; - - List existingFiles = new List(); - - if (Directory.Exists(serverFolder)) - { - foreach (var folder in Directory.GetDirectories(serverFolder)) - Directory.Delete(folder, true); - - foreach (var mdfile in Directory.GetFiles(serverFolder, "*.md")) - File.Delete(mdfile); - -// var files = string.Join("|", Directory.GetFiles(serverFolder, "*.md", SearchOption.AllDirectories)).ToLower().Split('|'); -// existingFiles.AddRange(files); - } - else - Directory.CreateDirectory(serverFolder); - - try - { - bool stopDirSet = false; - - while ((theEntry = s.GetNextEntry()) != null) - { - if (IsProjectDocumentation && !stopDirSet) - { - stopDir = Path.GetDirectoryName(theEntry.Name); - stopDirSet = true; - } - - string directoryName = Path.GetDirectoryName(theEntry.Name); - string fileName = Path.GetFileName(theEntry.Name); - - HttpContext.Current.Trace.Write("git", theEntry.Name + " " + fileName + " - " + directoryName); - - if (directoryName.Contains(stopDir)) - { - var startIndex = directoryName.LastIndexOf(stopDir) + stopDir.Length; - directoryName = directoryName.Substring(startIndex); - - // create directory - Directory.CreateDirectory(serverFolder + directoryName); - - if (fileName != String.Empty) - { - bool update = false; - var filepath = serverFolder + directoryName + "\\" + fileName; - - - if (existingFiles.Contains(filepath.ToLower())) - { - update = true; - existingFiles.Remove(filepath.ToLower()); - } - - FileStream streamWriter = File.Create(filepath); - int size = 2048; - byte[] data = new byte[2048]; - while (true) - { - size = s.Read(data, 0, data.Length); - if (size > 0) - { - streamWriter.Write(data, 0, size); - } - else - { - break; - } - } - streamWriter.Close(); - - if (update) - { - UpdateEventArgs ev = new UpdateEventArgs(); - ev.FilePath = filepath; - FireOnUpdate(ev); - } - else - { - CreateEventArgs ev = new CreateEventArgs(); - ev.FilePath = filepath; - FireOnCreate(ev); - } - } - } - } - - s.Close(); - foreach (var file in Directory.GetFiles(rootFolder, "*.zip")) - { - //File.Delete(file); - } - - } - catch (Exception ex) - { - Log.Add(LogTypes.Error, -1, ex.ToString()); - } - } - - private Events _e = new Events(); - - public static event EventHandler OnUpdate; - protected virtual void FireOnUpdate(UpdateEventArgs e) - { - try - { - _e.FireCancelableEvent(OnUpdate, this, e); - } - catch (Exception ex) { } - } - - - public static event EventHandler OnCreate; - protected virtual void FireOnCreate(CreateEventArgs e) - { - try - { - _e.FireCancelableEvent(OnCreate, this, e); - } - catch (Exception ex) { } - } - - - public static event EventHandler OnDelete; - protected virtual void FireOnDelete(DeleteEventArgs e) - { - try - { - _e.FireCancelableEvent(OnDelete, this, e); - } - catch (Exception ex) { } - } - + FireOnFinish(ev); + } + + public dynamic DocumentationSiteMap(string folder = "") + { + var path = Path.Combine(RootFolder, folder, "sitemap.js"); + var json = File.ReadAllText(path); + dynamic d = JsonConvert.DeserializeObject(json); + return d; + } + + public void process(string url, string foldername) + { + var zip = Download(url, foldername); + unzip(zip, foldername, RootFolder); + BuildSitemap(foldername); + + //YUCK, this is horrible but unfortunately the way that the doc indexes are setup are not with + // a consistent integer id per document. I'm sure we can make that happen but I don't have time right now. + ExamineManager.Instance.IndexProviderCollection["documentationIndexer"].RebuildIndex(); + } + + private void BuildSitemap(string foldername) + { + var folder = new DirectoryInfo(Path.Combine(RootFolder, foldername)); + dynamic root = GetFolderStructure(folder, folder.FullName, 0); + + var serializedRoot = JsonConvert.SerializeObject(root, Newtonsoft.Json.Formatting.Indented); + File.WriteAllText(Path.Combine(folder.FullName, "sitemap.js"), serializedRoot); + } + + private dynamic GetFolderStructure(DirectoryInfo dir, string rootPath, int level) + { + dynamic d = new ExpandoObject(); + d.name = dir.Name; + d.path = dir.FullName.Substring(rootPath.Length).Replace('\\','/'); + d.level = level; + + if (dir.GetDirectories().Any()) + { + var list = new List(); + foreach (var child in dir.GetDirectories()) + list.Add(GetFolderStructure(child, rootPath, level+1)); + + + d.hasChildren = true; + d.directories = list; + } + + return d; + } + + private string Download(string url, string foldername) + { + var dir = new DirectoryInfo(Path.Combine(RootFolder, foldername)); + var dirsToCreate = new List(); + + while (!dir.Exists) + { + dirsToCreate.Add(dir); + dir = dir.Parent; + } + + if (dirsToCreate.Any()) + { + dirsToCreate.Reverse(); + foreach (var d in dirsToCreate) + d.Create(); + } + + var path = Path.Combine(RootFolder, foldername + "archive.zip"); + + if (File.Exists(path)) + File.Delete(path); + + WebClient Client = new WebClient(); + Client.DownloadFile(url, path); + + return path; + } + + + private void unzip(string path, string foldername, string rootFolder) + { + ZipInputStream s = new ZipInputStream(File.OpenRead(path)); + ZipEntry theEntry; + + var stopDir = "\\Documentation"; + string serverFolder = rootFolder + "\\" + foldername; + + List existingFiles = new List(); + + if (Directory.Exists(serverFolder)) + { + foreach (var folder in Directory.GetDirectories(serverFolder)) + Directory.Delete(folder, true); + + foreach (var mdfile in Directory.GetFiles(serverFolder, "*.md")) + File.Delete(mdfile); + +// var files = string.Join("|", Directory.GetFiles(serverFolder, "*.md", SearchOption.AllDirectories)).ToLower().Split('|'); +// existingFiles.AddRange(files); + } + else + Directory.CreateDirectory(serverFolder); + + try + { + bool stopDirSet = false; + + while ((theEntry = s.GetNextEntry()) != null) + { + if (IsProjectDocumentation && !stopDirSet) + { + stopDir = Path.GetDirectoryName(theEntry.Name); + stopDirSet = true; + } + + string directoryName = Path.GetDirectoryName(theEntry.Name); + string fileName = Path.GetFileName(theEntry.Name); + + HttpContext.Current.Trace.Write("git", theEntry.Name + " " + fileName + " - " + directoryName); + + if (directoryName.Contains(stopDir)) + { + var startIndex = directoryName.LastIndexOf(stopDir) + stopDir.Length; + directoryName = directoryName.Substring(startIndex); + + // create directory + Directory.CreateDirectory(serverFolder + directoryName); + + if (fileName != String.Empty) + { + bool update = false; + var filepath = serverFolder + directoryName + "\\" + fileName; + + + if (existingFiles.Contains(filepath.ToLower())) + { + update = true; + existingFiles.Remove(filepath.ToLower()); + } + + FileStream streamWriter = File.Create(filepath); + int size = 2048; + byte[] data = new byte[2048]; + while (true) + { + size = s.Read(data, 0, data.Length); + if (size > 0) + { + streamWriter.Write(data, 0, size); + } + else + { + break; + } + } + streamWriter.Close(); + + if (update) + { + UpdateEventArgs ev = new UpdateEventArgs(); + ev.FilePath = filepath; + FireOnUpdate(ev); + } + else + { + CreateEventArgs ev = new CreateEventArgs(); + ev.FilePath = filepath; + FireOnCreate(ev); + } + } + } + } + + s.Close(); + foreach (var file in Directory.GetFiles(rootFolder, "*.zip")) + { + //File.Delete(file); + } + + } + catch (Exception ex) + { + Log.Add(LogTypes.Error, -1, ex.ToString()); + } + } + + private Events _e = new Events(); + + public static event EventHandler OnUpdate; + protected virtual void FireOnUpdate(UpdateEventArgs e) + { + try + { + _e.FireCancelableEvent(OnUpdate, this, e); + } + catch (Exception ex) { } + } + + + public static event EventHandler OnCreate; + protected virtual void FireOnCreate(CreateEventArgs e) + { + try + { + _e.FireCancelableEvent(OnCreate, this, e); + } + catch (Exception ex) { } + } + + + public static event EventHandler OnDelete; + protected virtual void FireOnDelete(DeleteEventArgs e) + { + try + { + _e.FireCancelableEvent(OnDelete, this, e); + } + catch (Exception ex) { } + } + public static event EventHandler OnFinish; protected virtual void FireOnFinish(FinishEventArgs e) { @@ -339,7 +339,7 @@ namespace uDocumentation.Busineslogic.GithubSourcePull _e.FireCancelableEvent(OnFinish, this, e); } catch (Exception ex) { } - } - + } + } } \ No newline at end of file diff --git a/uDocumentation/Busineslogic/MarkdownLogic.cs b/OurUmbraco/Documentation/Busineslogic/MarkdownLogic.cs similarity index 97% rename from uDocumentation/Busineslogic/MarkdownLogic.cs rename to OurUmbraco/Documentation/Busineslogic/MarkdownLogic.cs index 8d3d4ba7..d42f6124 100644 --- a/uDocumentation/Busineslogic/MarkdownLogic.cs +++ b/OurUmbraco/Documentation/Busineslogic/MarkdownLogic.cs @@ -1,86 +1,86 @@ -using System.IO; -using System.Text.RegularExpressions; -using MarkdownDeep; - -namespace uDocumentation.Busineslogic -{ - public class MarkdownLogic - { - private readonly string _filePath; - - public MarkdownLogic(string filePath) - { - _filePath = filePath; - } - - public const string VersionSession = "DocumentationVersion"; - public const string BaseUrl = "documentation"; - public const string AlternativeTemplate = "DocumentationSubpage"; - public const string DocumentTypeAlias = "Wiki"; - public const string MarkdownBasePath = "Documentation"; - public const string MarkdownPathKey = "MarkdownPath"; - public const string RegEx = @"\[([^\]]+)\]\(([^)]+)\)"; - - public string GetMarkdownBasePathWithVersion - { - get { return string.Concat(MarkdownBasePath, "\\"); } - } - - public bool PrefixLinks { get; set; } - - public string DoTransformation() - { - if (File.Exists(_filePath)) - { - string text = File.ReadAllText(_filePath); - - var clean = Regex.Replace(text, MarkdownLogic.RegEx, new MatchEvaluator(match => LinkEvaluator(match, PrefixLinks)), - RegexOptions.Singleline | RegexOptions.IgnorePatternWhitespace); - - Markdown md = new Markdown(); - string transform = md.Transform(clean); - return transform; - } - - return "

Not Found

"; - } - - private string LinkEvaluator(Match match, bool prefixLinks) - { - string mdUrlTag = match.Groups[0].Value; - string rawUrl = match.Groups[2].Value; - - //Escpae external URLs - if (rawUrl.StartsWith("http") || rawUrl.StartsWith("https") || rawUrl.StartsWith("ftp")) - return mdUrlTag; - - //Escape anchor links - if (rawUrl.StartsWith("#")) - return mdUrlTag; - - //Correct internal image links - if (rawUrl.StartsWith("../images/")) - return mdUrlTag.Replace("../images/", "images/"); - - //Used for main page to correct relative links - if (prefixLinks) - { - var p = "/documentation/"; - - if (umbraco.NodeFactory.Node.GetCurrent().Parent.NodeTypeAlias == "Project") - p = "documentation/"; - - string temp = string.Concat(p, rawUrl); - mdUrlTag = mdUrlTag.Replace(rawUrl, temp); - } - - if (rawUrl.EndsWith("index.md")) - mdUrlTag = mdUrlTag.Replace("/index.md", "/"); - else - mdUrlTag.TrimEnd('/'); - - - return mdUrlTag.Replace(rawUrl, rawUrl.EnsureNoDotsInUrl()); - } - } +using System.IO; +using System.Text.RegularExpressions; +using MarkdownDeep; + +namespace uDocumentation.Busineslogic +{ + public class MarkdownLogic + { + private readonly string _filePath; + + public MarkdownLogic(string filePath) + { + _filePath = filePath; + } + + public const string VersionSession = "DocumentationVersion"; + public const string BaseUrl = "documentation"; + public const string AlternativeTemplate = "DocumentationSubpage"; + public const string DocumentTypeAlias = "Wiki"; + public const string MarkdownBasePath = "Documentation"; + public const string MarkdownPathKey = "MarkdownPath"; + public const string RegEx = @"\[([^\]]+)\]\(([^)]+)\)"; + + public string GetMarkdownBasePathWithVersion + { + get { return string.Concat(MarkdownBasePath, "\\"); } + } + + public bool PrefixLinks { get; set; } + + public string DoTransformation() + { + if (File.Exists(_filePath)) + { + string text = File.ReadAllText(_filePath); + + var clean = Regex.Replace(text, MarkdownLogic.RegEx, new MatchEvaluator(match => LinkEvaluator(match, PrefixLinks)), + RegexOptions.Singleline | RegexOptions.IgnorePatternWhitespace); + + Markdown md = new Markdown(); + string transform = md.Transform(clean); + return transform; + } + + return "

Not Found

"; + } + + private string LinkEvaluator(Match match, bool prefixLinks) + { + string mdUrlTag = match.Groups[0].Value; + string rawUrl = match.Groups[2].Value; + + //Escpae external URLs + if (rawUrl.StartsWith("http") || rawUrl.StartsWith("https") || rawUrl.StartsWith("ftp")) + return mdUrlTag; + + //Escape anchor links + if (rawUrl.StartsWith("#")) + return mdUrlTag; + + //Correct internal image links + if (rawUrl.StartsWith("../images/")) + return mdUrlTag.Replace("../images/", "images/"); + + //Used for main page to correct relative links + if (prefixLinks) + { + var p = "/documentation/"; + + if (umbraco.NodeFactory.Node.GetCurrent().Parent.NodeTypeAlias == "Project") + p = "documentation/"; + + string temp = string.Concat(p, rawUrl); + mdUrlTag = mdUrlTag.Replace(rawUrl, temp); + } + + if (rawUrl.EndsWith("index.md")) + mdUrlTag = mdUrlTag.Replace("/index.md", "/"); + else + mdUrlTag.TrimEnd('/'); + + + return mdUrlTag.Replace(rawUrl, rawUrl.EnsureNoDotsInUrl()); + } + } } \ No newline at end of file diff --git a/uDocumentation/DocumentationContentFinder.cs b/OurUmbraco/Documentation/DocumentationContentFinder.cs similarity index 100% rename from uDocumentation/DocumentationContentFinder.cs rename to OurUmbraco/Documentation/DocumentationContentFinder.cs diff --git a/OurUmbraco/OurUmbraco.csproj b/OurUmbraco/OurUmbraco.csproj index 187943ae..559ad96c 100644 --- a/OurUmbraco/OurUmbraco.csproj +++ b/OurUmbraco/OurUmbraco.csproj @@ -94,6 +94,10 @@ ..\packages\Lucene.Net.2.9.4.1\lib\net40\Lucene.Net.dll True + + ..\packages\MarkdownDeep.NET.1.5\lib\.NetFramework 3.5\MarkdownDeep.dll + True + ..\packages\UmbracoCms.Core.7.2.8-build103\lib\Microsoft.ApplicationBlocks.Data.dll True @@ -221,6 +225,12 @@ + + + + + + diff --git a/OurUmbraco/packages.config b/OurUmbraco/packages.config index 3b4470d2..9b06ae06 100644 --- a/OurUmbraco/packages.config +++ b/OurUmbraco/packages.config @@ -8,6 +8,7 @@ + diff --git a/our.umbraco.org.sln b/our.umbraco.org.sln index 02cd92dd..c043259f 100644 --- a/our.umbraco.org.sln +++ b/our.umbraco.org.sln @@ -23,8 +23,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Notification", "Notificatio EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NotificationsWeb", "NotificationsWeb\NotificationsWeb.csproj", "{6CF53D68-BD81-47BB-8F56-350A1B04F114}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "uDocumentation", "uDocumentation\uDocumentation.csproj", "{2040BDAF-A804-462F-8D5F-CA0DF141BF89}" -EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{F3A30EFB-C5EA-460A-A591-8FBD7176B131}" ProjectSection(SolutionItems) = preProject .nuget\NuGet.Config = .nuget\NuGet.Config @@ -118,16 +116,6 @@ Global {6CF53D68-BD81-47BB-8F56-350A1B04F114}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU {6CF53D68-BD81-47BB-8F56-350A1B04F114}.Release|Mixed Platforms.Build.0 = Release|Any CPU {6CF53D68-BD81-47BB-8F56-350A1B04F114}.Release|x86.ActiveCfg = Release|Any CPU - {2040BDAF-A804-462F-8D5F-CA0DF141BF89}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {2040BDAF-A804-462F-8D5F-CA0DF141BF89}.Debug|Any CPU.Build.0 = Debug|Any CPU - {2040BDAF-A804-462F-8D5F-CA0DF141BF89}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU - {2040BDAF-A804-462F-8D5F-CA0DF141BF89}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU - {2040BDAF-A804-462F-8D5F-CA0DF141BF89}.Debug|x86.ActiveCfg = Debug|Any CPU - {2040BDAF-A804-462F-8D5F-CA0DF141BF89}.Release|Any CPU.ActiveCfg = Release|Any CPU - {2040BDAF-A804-462F-8D5F-CA0DF141BF89}.Release|Any CPU.Build.0 = Release|Any CPU - {2040BDAF-A804-462F-8D5F-CA0DF141BF89}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU - {2040BDAF-A804-462F-8D5F-CA0DF141BF89}.Release|Mixed Platforms.Build.0 = Release|Any CPU - {2040BDAF-A804-462F-8D5F-CA0DF141BF89}.Release|x86.ActiveCfg = Release|Any CPU {C5B74E6A-ABCE-4A9A-896D-89C33FDAFCD8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {C5B74E6A-ABCE-4A9A-896D-89C33FDAFCD8}.Debug|Any CPU.Build.0 = Debug|Any CPU {C5B74E6A-ABCE-4A9A-896D-89C33FDAFCD8}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU diff --git a/our.umbraco.org/our.umbraco.org.csproj b/our.umbraco.org/our.umbraco.org.csproj index 19f0b955..92f2ef8e 100644 --- a/our.umbraco.org/our.umbraco.org.csproj +++ b/our.umbraco.org/our.umbraco.org.csproj @@ -422,10 +422,6 @@ {a8e5c936-ecab-45b3-bfda-d12f680eb2a6} OurUmbraco
- - {2040BDAF-A804-462F-8D5F-CA0DF141BF89} - uDocumentation - {F356B339-296A-4594-81B6-CF69A802483E} uEvents diff --git a/uDocumentation/uDocumentation.csproj b/uDocumentation/uDocumentation.csproj index 475bfe99..238424c5 100644 --- a/uDocumentation/uDocumentation.csproj +++ b/uDocumentation/uDocumentation.csproj @@ -244,12 +244,6 @@ - - - - - -