public async Task OnGet() { Versions = (await _documentAppService.GetVersions(ProjectName, DocumentName)) .Select(v => new VersionInfo(v, v)) .ToList(); var latestVersion = Versions.First(); if (string.Equals(Version, "latest", StringComparison.OrdinalIgnoreCase) || !Versions.Exists(v => v.Version == Version)) { Version = latestVersion.Version; } latestVersion.DisplayText = $"latest {latestVersion.Version}"; latestVersion.Version = "latest"; Document = await _documentAppService.GetByNameAsync(ProjectName, DocumentName, Version); var documentFormatting = _documentFormattingFactory.Create(Document.Format ?? "md"); Document.Content = documentFormatting.Format(Document.Content); NavigationDocument = await _documentAppService.GetNavigationDocumentAsync(ProjectName, Version); var navigationDocumentFormatting = _documentFormattingFactory.Create(NavigationDocument.Format); NavigationDocument.Content = navigationDocumentFormatting.Format(NavigationDocument.Content); }
protected virtual async Task <DocumentWithDetailsDto> GetDocumentWithDetailsDto( Project project, string documentName, string version) { var cacheKey = $"Document@{project.ShortName}#{documentName}#{version}"; Document document; async Task <Document> GetDocumentAsync() { Logger.Info($"在缓存中找不到。仓储请求请求 {documentName}..."); var store = _documentStoreFactory.Create(project.DocumentStoreType); //判断为Github,或者Filesystem,调用不同的实现 document = await store.GetDocumentAsync(project, documentName, version); Logger.Info($"文档检索: {documentName}"); return(document); } //如果是Debug模式,不进入缓存 if (Debugger.IsAttached) { //需要检查 document = await GetDocumentAsync(); } var documentCache = _cacheManager.GetCache(cacheKey).AsTyped <string, Document>(); document = await documentCache.GetOrDefaultAsync(cacheKey); if (document == null) { var cacheDocument = await GetDocumentAsync(); _cacheManager.GetCache(cacheKey).Set(cacheKey, cacheDocument, null, TimeSpan.FromHours(30)); } //实际进行的是类型转换 var documentDto = new DocumentWithDetailsDto(); ObjectMapper.Map(document, documentDto); return(documentDto); }
public virtual string Convert(ProjectDto project, DocumentWithDetailsDto document, string version) { if (document.Content.IsNullOrEmpty()) { return(document.Content); } var content = NormalizeLinks( document.Content, project.ShortName, version, document.LocalDirectory ); return(CommonMarkConverter.Convert(Encoding.UTF8.GetString(Encoding.Default.GetBytes(content)))); }
public virtual string Convert(ProjectDto project, DocumentWithDetailsDto document, string version) { if (document.Content.IsNullOrEmpty()) { return(document.Content); } var content = NormalizeLinks( document.Content, project.ShortName, version, document.LocalDirectory ); return(_markdownConverter.ConvertToHtml(content)); }
public virtual string Convert(ProjectDto project, DocumentWithDetailsDto document, string version, string languageCode) { if (document.Content.IsNullOrEmpty()) { return(document.Content); } var content = NormalizeLinks( document.Content, project.ShortName, version, document.LocalDirectory, languageCode ); var html = _markdownConverter.ConvertToHtml(content); return(html); // return HtmlNormalizer.WrapImagesWithinAnchors(html); }
public NavigationTreePostProcessorContext(DocumentWithDetailsDto document, NavigationNode rootNode) { Document = document; RootNode = rootNode; }