Beispiel #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());
        }
Beispiel #2
0
        private async Task <string> RenderContentAsync(string markdown, DocumentMetaData metaData, HashSet <string> mediaFiles, int slot)
        {
            var body = await _markdownParser.ParseAsync(markdown);

            // Hack: Replace all links to .md files with links to .html files,
            // as we're changing the extension of the files during local generation.
            body = body.Replace(".md)", ".html)")
                   .Replace(".md\"", ".html\"")
                   .Replace(".md#", ".html#");

            var sb = new StringBuilder();

            sb.AppendLine($"<div class=\"example-content-preview example-content-preview-slot-{slot}\">");
            sb.AppendLine(GetPreviewVideo(mediaFiles));
            sb.AppendLine("</div>");
            sb.AppendLine("<div class=\"example-content-body\">");
            sb.AppendLine(body);
            sb.AppendLine("</div>");
            return(sb.ToString());
        }
Beispiel #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);
        }