Ejemplo n.º 1
0
        /// <summary>
        /// Root toc should always from working folder
        /// Parent toc is the first nearest toc
        /// </summary>
        /// <param name="context">The document build context</param>
        /// <param name="item">The manifest item</param>
        /// <returns>A class containing root toc path and parent toc path</returns>
        private static TocInfo GetTocInfo(IDocumentBuildContext context, ManifestItem item)
        {
            string       key           = GetFileKey(item.Key);
            RelativePath rootTocPath   = null;
            RelativePath parentTocPath = null;
            var          rootToc       = context.GetTocFileKeySet(RelativePath.WorkingFolder)?.FirstOrDefault();
            var          parentToc     = context.GetTocFileKeySet(key)?.FirstOrDefault();

            if (parentToc == null)
            {
                // fall back to get the toc file from the same directory
                var directory = ((RelativePath)key).GetDirectoryPath();
                parentToc = context.GetTocFileKeySet(directory)?.FirstOrDefault();
            }

            if (rootToc != null)
            {
                rootTocPath = GetFinalFilePath(rootToc, context);
            }

            if (parentToc != null)
            {
                parentTocPath = GetFinalFilePath(parentToc, context);
            }

            return(new TocInfo(rootTocPath, parentTocPath));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Root toc should always from working folder
        /// Parent toc is the first nearest toc
        /// </summary>
        /// <param name="context">The document build context</param>
        /// <param name="item">The manifest item</param>
        /// <returns>A class containing root toc path and parent toc path</returns>
        private static TocInfo GetTocInfo(IDocumentBuildContext context, ManifestItem item)
        {
            string relativePath = item.OriginalFile;
            string key = GetFileKey(relativePath);
            RelativePath rootTocPath = null;
            RelativePath parentTocPath = null;
            var rootToc = context.GetTocFileKeySet(RelativePath.WorkingFolder)?.FirstOrDefault();
            var parentToc = context.GetTocFileKeySet(key)?.FirstOrDefault();
            if (parentToc == null)
            {
                // fall back to get the toc file from the same directory
                var directory = ((RelativePath)key).GetDirectoryPath();
                parentToc = context.GetTocFileKeySet(directory)?.FirstOrDefault();
            }

            if (rootToc != null)
            {
                rootTocPath = GetFinalFilePath(rootToc, context);
            }

            if (parentToc != null)
            {
                parentTocPath = GetFinalFilePath(parentToc, context);
            }

            return new TocInfo(rootTocPath, parentTocPath);
        }
Ejemplo n.º 3
0
        public SystemMetadata Generate(ManifestItem item)
        {
            var attrs = new SystemMetadata
            {
                Language = Constants.DefaultLanguage,
            };

            string key  = GetFileKey(item.Key);
            var    file = (RelativePath)item.ModelFile;

            attrs.RelativePathToRoot = (RelativePath.Empty).MakeRelativeTo(file);
            attrs.PathFromRoot       = file.RemoveWorkingFolder();

            // 1. Root Toc is always in the top directory of output folder
            var rootToc = _toc.FirstOrDefault();

            if (rootToc != null)
            {
                var rootTocPath = rootToc.RemoveWorkingFolder();
                if (rootTocPath.SubdirectoryCount == 0)
                {
                    attrs.RootTocPath         = rootTocPath;
                    attrs.RootTocRelativePath = attrs.RootTocPath == null ? null : rootTocPath.MakeRelativeTo(file);
                    Logger.LogVerbose($"Root TOC file {rootTocPath} is found.");
                }
                else
                {
                    Logger.LogVerbose($"Root TOC file from output folder is not found, the toppest TOC file is {rootTocPath}");
                }
            }

            // 2. The algorithm of toc current article belongs to:
            //    a. If toc can be found in TocMap, return that toc
            //    b. Elsewise, get the nearest toc, **nearest** means nearest toc in **OUTPUT** folder
            var parentTocFiles = _context.GetTocFileKeySet(key)?.Select(s => _context.GetFilePath(s));
            var parentToc      = GetNearestToc(parentTocFiles);

            if (parentToc == null)
            {
                parentToc = GetDefaultToc(key);
            }

            if (parentToc != null)
            {
                var parentTocPath = parentToc.RemoveWorkingFolder();
                attrs.TocPath         = parentTocPath;
                attrs.TocRelativePath = attrs.TocPath == null ? null : parentTocPath.MakeRelativeTo(file);
                Logger.LogVerbose($"TOC file {parentTocPath} is found for {item.LocalPathFromRepoRoot}.");
            }
            else
            {
                Logger.LogVerbose($"TOC file for {item.LocalPathFromRepoRoot} is not found.");
            }

            return(attrs);
        }