diff --git a/OurUmbraco.Site/OurUmbraco.Site.csproj b/OurUmbraco.Site/OurUmbraco.Site.csproj
index dfa78ab7..8832f0d9 100644
--- a/OurUmbraco.Site/OurUmbraco.Site.csproj
+++ b/OurUmbraco.Site/OurUmbraco.Site.csproj
@@ -4330,6 +4330,7 @@
+
web.config
diff --git a/OurUmbraco.Site/Views/Lesson.cshtml b/OurUmbraco.Site/Views/Lesson.cshtml
new file mode 100644
index 00000000..45c70b7a
--- /dev/null
+++ b/OurUmbraco.Site/Views/Lesson.cshtml
@@ -0,0 +1,12 @@
+@using OurUmbraco.Documentation.Busineslogic
+@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
+@{
+ Layout = null;
+
+ var path = HttpContext.Current.Items[MarkdownLogic.MarkdownPathKey].ToString();
+ var ml = new MarkdownLogic(path) { PrefixLinks = false, AppendAltLessonLink = false };
+ var markdown = ml.DoTransformation();
+}
+
+
+@Html.Raw(markdown)
\ No newline at end of file
diff --git a/OurUmbraco/Documentation/Busineslogic/GithubSourcePull/ZipDownloader.cs b/OurUmbraco/Documentation/Busineslogic/GithubSourcePull/ZipDownloader.cs
index 1a99b169..2ffd7916 100644
--- a/OurUmbraco/Documentation/Busineslogic/GithubSourcePull/ZipDownloader.cs
+++ b/OurUmbraco/Documentation/Busineslogic/GithubSourcePull/ZipDownloader.cs
@@ -112,12 +112,11 @@ namespace OurUmbraco.Documentation.Busineslogic.GithubSourcePull
FireOnFinish(finishEventArgs);
}
- public dynamic DocumentationSiteMap(string folder = "")
+ public SiteMapItem DocumentationSiteMap(string folder = "")
{
var path = Path.Combine(RootFolder, folder, "sitemap.js");
var json = File.ReadAllText(path);
- dynamic documentationSiteMap = JsonConvert.DeserializeObject(json);
- return documentationSiteMap;
+ return JsonConvert.DeserializeObject(json);
}
public void Process(string url, string foldername)
@@ -143,13 +142,13 @@ namespace OurUmbraco.Documentation.Busineslogic.GithubSourcePull
public void BuildSitemap(string foldername)
{
var folder = new DirectoryInfo(Path.Combine(RootFolder, foldername));
- dynamic root = GetFolderStructure(folder, folder.FullName, 0);
+ var 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 class SiteMapItem
+ public class SiteMapItem
{
public string name { get; set; }
public string path { get; set; }
@@ -157,28 +156,28 @@ namespace OurUmbraco.Documentation.Busineslogic.GithubSourcePull
public int sort { get; set; }
public bool hasChildren { get; set; }
public List directories { get; set; }
+ public string url => $"https://our.umbraco.org/documentation{this.path}?altTemplate=Lesson";
}
private SiteMapItem GetFolderStructure(DirectoryInfo dir, string rootPath, int level)
{
+ var list = new List();
+
var siteMapItem = new SiteMapItem
{
name = dir.Name.Replace("-", " "),
path = dir.FullName.Substring(rootPath.Length).Replace('\\', '/'),
level = level,
- sort = GetSort(dir.Name, level) ?? 100
+ sort = GetSort(dir.Name, level) ?? 100,
+ directories = list,
+ hasChildren = dir.GetDirectories().Any()
};
-
- if (dir.GetDirectories().Any() == false)
- return siteMapItem;
-
- var list = new List();
+
foreach (var child in dir.GetDirectories().Where(x => x.Name != "images"))
{
list.Add(GetFolderStructure(child, rootPath, level + 1));
}
- siteMapItem.hasChildren = true;
siteMapItem.directories = list.OrderBy(x => x.sort).ToList();
return siteMapItem;
diff --git a/OurUmbraco/Documentation/Busineslogic/MarkdownLogic.cs b/OurUmbraco/Documentation/Busineslogic/MarkdownLogic.cs
index daab6610..67485cb5 100644
--- a/OurUmbraco/Documentation/Busineslogic/MarkdownLogic.cs
+++ b/OurUmbraco/Documentation/Busineslogic/MarkdownLogic.cs
@@ -11,6 +11,7 @@ namespace OurUmbraco.Documentation.Busineslogic
public MarkdownLogic(string filePath)
{
_filePath = filePath;
+ AppendAltLessonLink = false;
}
public const string VersionSession = "DocumentationVersion";
@@ -28,6 +29,8 @@ namespace OurUmbraco.Documentation.Busineslogic
public bool PrefixLinks { get; set; }
+ public bool AppendAltLessonLink { get; set; }
+
public string DoTransformation()
{
if (File.Exists(_filePath))
@@ -79,6 +82,10 @@ namespace OurUmbraco.Documentation.Busineslogic
else
mdUrlTag.TrimEnd('/');
+ if (AppendAltLessonLink)
+ {
+ return mdUrlTag.Replace(rawUrl, $"{rawUrl.EnsureNoDotsInUrl()}?altTemplate=Lesson");
+ }
return mdUrlTag.Replace(rawUrl, rawUrl.EnsureNoDotsInUrl());
}
diff --git a/OurUmbraco/Documentation/Controllers/LessonsController.cs b/OurUmbraco/Documentation/Controllers/LessonsController.cs
new file mode 100644
index 00000000..8d537282
--- /dev/null
+++ b/OurUmbraco/Documentation/Controllers/LessonsController.cs
@@ -0,0 +1,64 @@
+using System.Collections.Generic;
+using System.Linq;
+using System.Net;
+using System.Net.Http;
+using System.Web.Http;
+using OurUmbraco.Documentation.Busineslogic.GithubSourcePull;
+using OurUmbraco.Documentation.Models;
+using Umbraco.Core;
+using Umbraco.Web.Mvc;
+using Umbraco.Web.WebApi;
+
+namespace OurUmbraco.Documentation.Controllers
+{
+ [PluginController("Documentation")]
+ public class LessonsController : UmbracoApiController
+ {
+ ///
+ ///
+ ///
+ /// The path in the documentation folder structure that you wish to start from & list descendants
+ /// Future Use: Backoffice Usertype requesting lessons
+ /// Future Use: AllowedSections of BackOffice User
+ /// Future Use: Backoffice Users langunage
+ /// Umbraco CMS Version as a string
+ ///
+ /// A partial part of the documentation tree, that lists out folders
+ /// This is used in the new Starter Kit in conjuction with 'Lessons'
+ ///
+ public List GetDocsForPath(string path, string userType, string allowedSections, string lang, string version)
+ {
+ //Ensure path is not null & empty
+ if (string.IsNullOrEmpty(path))
+ {
+ var resp = new HttpResponseMessage(HttpStatusCode.BadRequest)
+ {
+ Content = new StringContent("Path varibale is null or empty"),
+ ReasonPhrase = "Documentation Path is invalid"
+ };
+
+ throw new HttpResponseException(resp);
+ }
+
+ //Get the documentation Sitemap JS file that lives on disk everytime we fetch & unpack the markdown docs from GitHub
+ var docs = new ZipDownloader();
+
+ //Note: For now the folder param is NOT the folder/subtree but where the JSON file is stored to build up this model
+ var allDocs = docs.DocumentationSiteMap();
+
+
+ //Split path and ensure we can find each part of the path
+ //In the array of nested objects
+ var pathArray = path.Split('/').Where(x => string.IsNullOrEmpty(x) == false).ToArray();
+ var currentDirectory = allDocs;
+
+ for (int i = 0; i < pathArray.Length; i++)
+ {
+ var pathPart = "/" + string.Join("/", pathArray.Take(i + 1));
+ currentDirectory = currentDirectory.directories.First(x => x.path == pathPart);
+ }
+
+ return currentDirectory.directories;
+ }
+ }
+}
diff --git a/OurUmbraco/OurUmbraco.csproj b/OurUmbraco/OurUmbraco.csproj
index 3250b40b..90461fef 100644
--- a/OurUmbraco/OurUmbraco.csproj
+++ b/OurUmbraco/OurUmbraco.csproj
@@ -401,6 +401,7 @@
+