@ -22,7 +22,7 @@ namespace Volo.Docs.Pages.Documents.Project
[BindProperty(SupportsGet = true)]
public string DocumentName { get ; set ; }
public string ProjectFormat { get ; set ; }
public string ProjectFormat { get ; private set ; }
public string DocumentNameWithExtension { get ; private set ; }
@ -30,15 +30,12 @@ namespace Volo.Docs.Pages.Documents.Project
public List < VersionInfo > Versions { get ; private set ; }
public List < SelectListItem > VersionSelectItems = > Versions . Select ( v = > new SelectListItem
{
Text = v . DisplayText ,
Value = "/documents/" + ProjectName + "/" + v . Version + "/" + DocumentName ,
Selected = v . IsSelected
} ) . ToList ( ) ;
public List < SelectListItem > VersionSelectItems { get ; private set ; }
public NavigationWithDetailsDto Navigation { get ; private set ; }
public VersionInfo LatestVersionInfo { get ; private set ; }
private readonly IDocumentAppService _d ocumentAppService ;
private readonly IDocumentConverterFactory _d ocumentConverterFactory ;
private readonly IProjectAppService _ projectAppService ;
@ -50,37 +47,53 @@ namespace Volo.Docs.Pages.Documents.Project
_ projectAppService = projectAppService ;
}
public VersionInfo LatestVersionInfo
public async Task OnGet ( )
{
get
{
var latestVersion = Versions . First ( ) ;
var project = await _ projectAppService . FindByShortNameAsync ( ProjectName ) ;
latestVersion . DisplayText = $"{latestVersion.Version} - " + DocsAppConsts . LatestVersion ;
latestVersion . Version = latestVersion . Version ;
SetPageParams ( project ) ;
return latestVersion ;
}
await SetVersionAsync ( project ) ;
await SetDocumentAsync ( ) ;
await SetNavigationAsync ( ) ;
}
public async Task OnGet ( )
private async Task SetNavigationAsync ( )
{
var projectDto = await _ projectAppService . FindByShortNameAsync ( ProjectName ) ;
Navigation = await _d ocumentAppService . GetNavigationDocumentAsync ( ProjectName , Version , false ) ;
Navigation . ConvertItems ( ) ;
}
ProjectFormat = projectDto . Format ;
private void SetPageParams ( ProjectDto project )
{
ProjectFormat = project . Format ;
if ( DocumentName . IsNullOrWhiteSpace ( ) )
{
DocumentName = projectDto . DefaultDocumentName ;
DocumentName = project . DefaultDocumentName ;
}
DocumentNameWithExtension = DocumentName + "." + projectDto . Format ;
DocumentNameWithExtension = DocumentName + "." + project . Format ;
}
var versions = await _d ocumentAppService . GetVersions ( projectDto . ShortName , projectDto . DefaultDocumentName ,
projectDto . ExtraProperties , projectDto . DocumentStoreType , DocumentNameWithExtension ) ;
private async Task SetVersionAsync ( ProjectDto project )
{
var versions = await _d ocumentAppService . GetVersions ( project . ShortName , project . DefaultDocumentName ,
project . ExtraProperties , project . DocumentStoreType , DocumentNameWithExtension ) ;
VersionSelectItems = Versions . Select ( v = > new SelectListItem
{
Text = v . DisplayText ,
Value = "/documents/" + ProjectName + "/" + v . Version + "/" + DocumentName ,
Selected = v . IsSelected
} ) . ToList ( ) ;
Versions = versions . Select ( v = > new VersionInfo ( v , v ) ) . ToList ( ) ;
LatestVersionInfo = GetLatestVersion ( ) ;
if ( string . Equals ( Version , DocsAppConsts . LatestVersion , StringComparison . OrdinalIgnoreCase ) )
{
LatestVersionInfo . IsSelected = true ;
@ -100,20 +113,28 @@ namespace Volo.Docs.Pages.Documents.Project
Version = Versions . First ( ) . Version ;
}
}
}
private VersionInfo GetLatestVersion ( )
{
var latestVersion = Versions . First ( ) ;
latestVersion . DisplayText = $"{latestVersion.Version} - " + DocsAppConsts . LatestVersion ;
latestVersion . Version = latestVersion . Version ;
return latestVersion ;
}
private async Task SetDocumentAsync ( )
{
Document = await _d ocumentAppService . GetByNameAsync ( ProjectName , DocumentNameWithExtension , Version , true ) ;
var converter = _d ocumentConverterFactory . Create ( Document . Format ? ? projectDto . Format ) ;
var converter = _d ocumentConverterFactory . Create ( Document . Format ? ? Project Format) ;
var content = converter . NormalizeLinks ( Document . Content , Document . Project . ShortName , Document . Version , Document . LocalDirectory ) ;
content = converter . Convert ( content ) ;
content = HtmlNormalizer . ReplaceImageSources ( content , Document . RawRootUrl , Document . LocalDirectory ) ;
content = HtmlNormalizer . ReplaceCodeBlocksLanguage ( content , "language-C#" , "language-csharp" ) ; //todo find a way to make it on client in prismJS configuration (eg: map C# => csharp)
Document . Content = content ;
Navigation = await _d ocumentAppService . GetNavigationDocumentAsync ( ProjectName , Version , false ) ;
Navigation . ConvertItems ( ) ;
}
}
}