Init API Controller to Query partial part of the MD Docs tree & WIP for the markdown alt template
This commit is contained in:
@@ -4330,6 +4330,7 @@
|
||||
<Content Include="Views\Partials\Grid\Bootstrap3-Fluid.cshtml" />
|
||||
<Content Include="Views\Partials\Grid\Bootstrap2.cshtml" />
|
||||
<Content Include="Views\Partials\Grid\Bootstrap2-Fluid.cshtml" />
|
||||
<Content Include="Views\Lesson.cshtml" />
|
||||
<None Include="web.Debug.config">
|
||||
<DependentUpon>web.config</DependentUpon>
|
||||
</None>
|
||||
|
||||
@@ -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)
|
||||
@@ -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<dynamic>(json);
|
||||
return documentationSiteMap;
|
||||
return JsonConvert.DeserializeObject<SiteMapItem>(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<SiteMapItem> 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<SiteMapItem>();
|
||||
|
||||
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<SiteMapItem>();
|
||||
|
||||
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;
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
@@ -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
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="path">The path in the documentation folder structure that you wish to start from & list descendants</param>
|
||||
/// <param name="userType">Future Use: Backoffice Usertype requesting lessons</param>
|
||||
/// <param name="allowedSections">Future Use: AllowedSections of BackOffice User</param>
|
||||
/// <param name="lang">Future Use: Backoffice Users langunage</param>
|
||||
/// <param name="version">Umbraco CMS Version as a string</param>
|
||||
/// <returns>
|
||||
/// A partial part of the documentation tree, that lists out folders
|
||||
/// This is used in the new Starter Kit in conjuction with 'Lessons'
|
||||
/// </returns>
|
||||
public List<ZipDownloader.SiteMapItem> 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -401,6 +401,7 @@
|
||||
<Compile Include="Documentation\Busineslogic\GithubSourcePull\ZipDownloader.cs" />
|
||||
<Compile Include="Documentation\Busineslogic\MarkdownLogic.cs" />
|
||||
<Compile Include="Documentation\Controllers\AppVeyorAuthorizeFilterAttribute.cs" />
|
||||
<Compile Include="Documentation\Controllers\LessonsController.cs" />
|
||||
<Compile Include="Documentation\Models\Artifact.cs" />
|
||||
<Compile Include="Documentation\Models\Compilationmessage.cs" />
|
||||
<Compile Include="Documentation\Models\DocFxUpdateModel.cs" />
|
||||
|
||||
Reference in New Issue
Block a user