Ejemplo n.º 1
0
        private string RenderNavigation(DocumentMetaData metaData, CodeExportResult code)
        {
            var sb = new StringBuilder();

            sb.AppendLine("<p class=\"example-back-link\">");
            sb.AppendLine("&lt; <a href=\"../index.html\">Go back</a>");
            sb.AppendLine("</p>");

            if (code.HasCode)
            {
                sb.AppendLine("<p class=\"example-download-link\">");
                sb.AppendLine($"<a href=\"../{code.BundlePath}\" class=\"btn btn-primary btn-block\">Download example</a>");
                sb.AppendLine("</p>");
            }

            if (metaData.Tags?.Count > 0)
            {
                var tags = new List <string>();
                foreach (var tag in metaData.Tags)
                {
                    var filename = GetTagFilename(tag);
                    tags.Add($"<a href=\"../{filename}\">{EscapeHtml(tag)}</a>");
                }

                sb.AppendLine("<h6>Tags</h6>");
                sb.AppendLine("<p class=\"example-tags\">");
                sb.AppendLine(string.Join(", ", tags));
                sb.AppendLine("</p>");
            }

            sb.AppendLine(RenderConcepts(metaData.UxConcepts, _uxConcepts, "UX Concepts"));
            sb.AppendLine(RenderConcepts(metaData.JsConcepts, _jsConcepts, "JS Concepts"));

            return(sb.ToString());
        }
Ejemplo n.º 2
0
 public PreparedDocumentExport(string documentName,
                               string documentRoot,
                               CodeExportResult code,
                               DocumentMetaData metaData)
 {
     DocumentName = documentName;
     DocumentRoot = documentRoot;
     Code         = code;
     MetaData     = metaData;
 }
Ejemplo n.º 3
0
        public async Task <DocumentExportResult> ExportAsync(string exampleName, string directoryName, DocumentMetaData metaData, CodeExportResult code, int slot)
        {
            var exampleFile = Path.Combine(directoryName, "example.md");

            if (!File.Exists(exampleFile))
            {
                throw new ArgumentException($"No example file found at {exampleFile}");
            }

            var mediaFiles = await WriteMediaAsync(exampleName, directoryName);

            if (metaData.PublishedAt.HasValue)
            {
                var content = await RenderContentAsync(File.ReadAllText(exampleFile), metaData, mediaFiles, slot);

                var sidebar = RenderNavigation(metaData, code);
                var html    = _layout.Apply(content, sidebar, metaData.Title);
                await _outputDir.WriteAsync(Path.Combine(exampleName, "index.html"), Encoding.UTF8.GetBytes(html));

                return(new DocumentExportResult(isExternal: false,
                                                slot: slot,
                                                id: exampleName,
                                                title: metaData.Title,
                                                synopsis: metaData.Synopsis,
                                                previewImage: GetPreviewImage(mediaFiles, $"{exampleName}/"),
                                                detailedPreviewImage: null,
                                                uri: $"{exampleName}/index.html",
                                                publishedAt: metaData.PublishedAt.Value,
                                                tags: metaData.Tags ?? new List <string>()));
            }

            return(null);
        }