Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
 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);
     }));
 }
Exemplo n.º 3
0
        public static ManifestItemType GetDocumentType(ManifestItem item)
        {
            var type = item.DocumentType;

            if (Enum.TryParse(type, out ManifestItemType actualType))
            {
                return(actualType);
            }

            return(ManifestItemType.Content);
        }
Exemplo n.º 4
0
        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);
        }
Exemplo n.º 5
0
 private bool IsType(ManifestItem item, ManifestItemType targetType)
 {
     return(ManifestUtility.GetDocumentType(item) == targetType);
 }
Exemplo n.º 6
0
 private IList <TocModel> LoadTocModels(string basePath, ManifestItem tocFile)
 {
     return(JsonUtility.Deserialize <IList <TocModel> >(Path.Combine(basePath, ManifestUtility.GetRelativePath(tocFile, OutputType.TocJson))));
 }