public static string GetAssetId(ManifestItem manifestItem) { Guard.ArgumentNotNull(manifestItem, nameof(manifestItem)); var documentType = GetDocumentType(manifestItem); string assetId; switch (documentType) { case ManifestItemType.Content: assetId = GetRelativePath(manifestItem, OutputType.Html) ?? GetRelativePath(manifestItem, OutputType.RawPageJson); break; case ManifestItemType.Resource: assetId = GetRelativePath(manifestItem, OutputType.Resource); break; case ManifestItemType.Toc: assetId = GetRelativePath(manifestItem, OutputType.TocJson); break; default: throw new NotSupportedException($"{nameof(ManifestItemType)} {documentType} is not supported."); } if (assetId == null) { throw new ArgumentException($"Invalid manifest item: {manifestItem}", nameof(manifestItem)); } return(assetId); }
private ManifestItem FindSiblingCoverPageInManifest(Manifest manifest, ManifestItem tocFile) { return(manifest.Files.SingleOrDefault(f => { return FilePathComparer.OSPlatformSensitiveRelativePathComparer.Equals(Path.GetDirectoryName(f.SourceRelativePath), Path.GetDirectoryName(tocFile.SourceRelativePath)) && string.Equals("cover.md", Path.GetFileName(f.SourceRelativePath), StringComparison.OrdinalIgnoreCase); })); }
public static ManifestItemType GetDocumentType(ManifestItem item) { var type = item.DocumentType; if (Enum.TryParse(type, out ManifestItemType actualType)) { return(actualType); } return(ManifestItemType.Content); }
public static string GetRelativePath(ManifestItem item, OutputType type) { if (item?.OutputFiles == null) { return(null); } switch (type) { case OutputType.Html: if (item.OutputFiles.TryGetValue(BuildToolConstants.OutputFileExtensions.ContentHtmlExtension, out OutputFileInfo content)) { return(content.RelativePath); } break; case OutputType.TocJson: if (item.OutputFiles.TryGetValue(BuildToolConstants.OutputFileExtensions.TocFileExtension, out content)) { return(content.RelativePath); } break; case OutputType.RawPageJson: if (item.OutputFiles.TryGetValue(BuildToolConstants.OutputFileExtensions.ContentRawPageExtension, out content)) { return(content.RelativePath); } break; case OutputType.Resource: if (item.OutputFiles.TryGetValue(ManifestConstants.BuildManifestItem.OutputResource, out content)) { return(content.RelativePath); } break; default: break; } return(null); }
private bool IsType(ManifestItem item, ManifestItemType targetType) { return(ManifestUtility.GetDocumentType(item) == targetType); }
private IList <TocModel> LoadTocModels(string basePath, ManifestItem tocFile) { return(JsonUtility.Deserialize <IList <TocModel> >(Path.Combine(basePath, ManifestUtility.GetRelativePath(tocFile, OutputType.TocJson)))); }