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); }
public async Task <CodeExportResult> ExportForAsync(string exampleName, string directoryName) { var codeDirectory = Path.Combine(directoryName, "code"); if (!Directory.Exists(codeDirectory)) { _logger.LogDebug($"No code directory exists for example directory {directoryName}, skipping"); return(new CodeExportResult(false, null)); } var files = Directory.EnumerateFiles(codeDirectory, "*.*", SearchOption.AllDirectories) .ToList(); foreach (var file in files) { var relativePath = file.Substring(codeDirectory.Length + 1); var destination = Path.Combine("bundles", exampleName, relativePath); var buffer = _stripper.RemoveSnippets(file, File.ReadAllBytes(file)); await _outputDir.WriteAsync(destination, buffer); } return(new CodeExportResult(true, $"bundles/{exampleName}.zip")); }