Пример #1
0
 private static List <HomepageInfo> GetHomepages(DocumentBuildContext context)
 {
     return(context.GetTocInfo()
            .Where(s => !string.IsNullOrEmpty(s.Homepage))
            .Select(s => new HomepageInfo
     {
         Homepage = TypeForwardedToRelativePath.GetPathWithoutWorkingFolderChar(s.Homepage),
         TocPath = TypeForwardedToRelativePath.GetPathWithoutWorkingFolderChar(context.GetFilePath(s.TocFileKey))
     }).ToList());
 }
Пример #2
0
        public static FileLinkInfo Create(string fromFileInSource, string fromFileInDest, string href, IDocumentBuildContext context)
        {
            if (fromFileInSource == null)
            {
                throw new ArgumentNullException(nameof(fromFileInSource));
            }
            if (fromFileInDest == null)
            {
                throw new ArgumentNullException(nameof(fromFileInDest));
            }
            if (href == null)
            {
                throw new ArgumentNullException(nameof(href));
            }
            if (UriUtility.HasFragment(href) || UriUtility.HasQueryString(href))
            {
                throw new ArgumentException("fragment and query string is not supported", nameof(href));
            }
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            var path = RelativePath.TryParse(href)?.UrlDecode();

            if (path == null)
            {
                throw new ArgumentException("only relative path is supported", nameof(href));
            }

            var fli = new FileLinkInfo
            {
                FromFileInSource = fromFileInSource,
                FromFileInDest   = fromFileInDest,
                GroupInfo        = context.GroupInfo,
            };

            if (path.IsFromWorkingFolder())
            {
                var targetInSource = path;
                fli.ToFileInSource   = targetInSource.RemoveWorkingFolder();
                fli.ToFileInDest     = RelativePath.GetPathWithoutWorkingFolderChar(context.GetFilePath(targetInSource));
                fli.FileLinkInSource = targetInSource - (RelativePath)fromFileInSource;
                if (fli.ToFileInDest != null)
                {
                    var resolved = (RelativePath)fli.ToFileInDest - (RelativePath)fromFileInDest;
                    fli.FileLinkInDest = resolved;
                    fli.Href           = resolved.UrlEncode();
                }
                else
                {
                    fli.Href = (targetInSource.RemoveWorkingFolder() - ((RelativePath)fromFileInSource).RemoveWorkingFolder()).UrlEncode();
                }
            }
            else
            {
                fli.FileLinkInSource = path;
                fli.ToFileInSource   = ((RelativePath)fromFileInSource + path).RemoveWorkingFolder();
                fli.FileLinkInDest   = fli.FileLinkInSource;
                fli.Href             = href;
            }

            return(fli);
        }