Example #1
0
        public DocumentationPage Compile(FileInfo file, FolderItem page, string documentationVersion, List <DocumentationMapping> mappings)
        {
            try
            {
                var key      = ExtractKey(file, page, documentationVersion);
                var category = CategoryHelper.ExtractCategoryFromPath(key);
                var images   = new HashSet <DocumentationImage>();

                _parser.PrepareImage = (tag, b) => PrepareImage(images, file.DirectoryName, _options.ImagesUrl, documentationVersion, tag);

                var content = File.ReadAllText(file.FullName);
                content = TransformLegacyBlocks(file, content);
                content = _parser.Transform(content);
                content = TransformBlocks(content, documentationVersion);

                var htmlDocument = HtmlHelper.ParseHtml(content);

                var title       = ExtractTitle(htmlDocument);
                var textContent = ExtractTextContent(htmlDocument);

                var caseSensitiveFileName = PathHelper.GetProperFilePathCapitalization(file.FullName);

                var fullName = caseSensitiveFileName ?? file.FullName;

                var repoRelativePath = _repoAnalyzer.MakeRelativePathInRepository(fullName);

                var relativeUrl = repoRelativePath.Replace(@"\", @"/");

                var lastCommit = _repoAnalyzer.GetLastCommitThatAffectedFile(repoRelativePath);

                return(new DocumentationPage
                {
                    Key = key,
                    Title = title,
                    Version = documentationVersion,
                    HtmlContent = content,
                    TextContent = textContent,
                    Language = page.Language,
                    Category = category,
                    Images = images,
                    LastCommitSha = lastCommit,
                    RelativePath = relativeUrl,
                    Mappings = mappings.OrderBy(x => x.Version).ToList()
                });
            }
            catch (Exception e)
            {
                throw new InvalidOperationException(string.Format("Could not compile '{0}'.", file.FullName), e);
            }
        }