public static IsSupportedRelativeHref ( HrefType hrefType ) : bool | ||
hrefType | HrefType | |
return | bool |
private string ResolveHref(string pathToFile, string originalPathToFile, FileModel model, IDocumentBuildContext context) { if (!Utility.IsSupportedRelativeHref(pathToFile)) { return(pathToFile); } var index = pathToFile.IndexOf('#'); if (index == 0) { throw new DocumentException($"Invalid toc link: {originalPathToFile}."); } string href = index == -1 ? context.GetFilePath(pathToFile) : context.GetFilePath(pathToFile.Remove(index)); if (href == null) { Logger.LogWarning($"Unable to find file \"{originalPathToFile}\" referenced by TOC file \"{model.LocalPathFromRepoRoot}\""); return(originalPathToFile); } var relativePath = GetRelativePath(href, model.File); var path = ((RelativePath)relativePath).UrlEncode().ToString(); if (index >= 0) { path += pathToFile.Substring(index); } return(path); }
private string ResolveHref(string pathToFile, string originalPathToFile, FileModel model, IDocumentBuildContext context, string propertyName) { if (!Utility.IsSupportedRelativeHref(pathToFile)) { return(pathToFile); } var index = pathToFile.IndexOfAny(QueryStringOrAnchor); if (index == 0) { throw new DocumentException($"Invalid toc link for {propertyName}: {originalPathToFile}."); } var path = UriUtility.GetPath(pathToFile); var segments = UriUtility.GetQueryStringAndFragment(pathToFile); var fli = FileLinkInfo.Create(model.LocalPathFromRoot, model.File, path, context); var result = context.HrefGenerator?.GenerateHref(fli); if (fli.ToFileInDest == null && result == null) { // original path to file can be null for files generated by docfx in PreBuild var displayFilePath = string.IsNullOrEmpty(originalPathToFile) ? pathToFile : originalPathToFile; Logger.LogInfo($"Unable to find file \"{displayFilePath}\" for {propertyName} referenced by TOC file \"{model.LocalPathFromRoot}\""); return(originalPathToFile); } return((result ?? fli.Href) + segments); }
private string ResolveHref(string pathToFile, string originalPathToFile, FileModel model, IDocumentBuildContext context, string propertyName) { if (!Utility.IsSupportedRelativeHref(pathToFile)) { return(pathToFile); } var index = pathToFile.IndexOfAny(QueryStringOrAnchor); if (index == 0) { throw new DocumentException($"Invalid toc link for {propertyName}: {originalPathToFile}."); } var path = UriUtility.GetPath(pathToFile); var segments = UriUtility.GetQueryStringAndFragment(pathToFile); string href = context.GetFilePath(HttpUtility.UrlDecode(path)); // original path to file can be null for files generated by docfx in PreBuild var displayFilePath = string.IsNullOrEmpty(originalPathToFile) ? pathToFile : originalPathToFile; if (href == null) { Logger.LogInfo($"Unable to find file \"{displayFilePath}\" for {propertyName} referenced by TOC file \"{model.LocalPathFromRoot}\""); return(originalPathToFile); } var relativePath = GetRelativePath(href, model.File); var resolvedHref = ((RelativePath)relativePath).UrlEncode().ToString() + segments; return(resolvedHref); }
private string ResolveHref(string pathToFile, string originalPathToFile, FileModel model, IDocumentBuildContext context, string propertyName) { if (!Utility.IsSupportedRelativeHref(pathToFile)) { return(pathToFile); } var index = pathToFile.IndexOfAny(QueryStringOrAnchor); if (index == 0) { var message = $"Invalid toc link for {propertyName}: {originalPathToFile}."; Logger.LogError(message, code: ErrorCodes.Toc.InvalidTocLink); throw new DocumentException(message); } var path = UriUtility.GetPath(pathToFile); var segments = UriUtility.GetQueryStringAndFragment(pathToFile); var fli = FileLinkInfo.Create(model.LocalPathFromRoot, model.File, path, context); var href = context.HrefGenerator?.GenerateHref(fli); if (fli.ToFileInDest == null && href == null) { // original path to file can be null for files generated by docfx in PreBuild var displayFilePath = string.IsNullOrEmpty(originalPathToFile) ? pathToFile : originalPathToFile; Logger.LogInfo($"Unable to find file \"{displayFilePath}\" for {propertyName} referenced by TOC file \"{model.LocalPathFromRoot}\""); return(originalPathToFile); } // fragment and query in original href takes precedence over the one from hrefGenerator return(href == null ? fli.Href + segments : UriUtility.MergeHref(href, segments)); }
private string ResolveHref(string pathToFile, string originalPathToFile, FileModel model, IDocumentBuildContext context, string propertyName) { if (!Utility.IsSupportedRelativeHref(pathToFile)) { return(pathToFile); } var index = pathToFile.IndexOfAny(QueryStringOrAnchor); if (index == 0) { throw new DocumentException($"Invalid toc link for {propertyName}: {originalPathToFile}."); } string href = index == -1 ? context.GetFilePath(pathToFile) : context.GetFilePath(pathToFile.Remove(index)); if (href == null) { Logger.LogInfo($"Unable to find file \"{originalPathToFile}\" for {propertyName} referenced by TOC file \"{model.LocalPathFromRoot}\""); return(originalPathToFile); } var relativePath = GetRelativePath(href, model.File); var path = ((TypeForwardedToRelativePath)relativePath).UrlEncode().ToString(); if (index >= 0) { path += pathToFile.Substring(index); } return(path); }
private string NormalizeHref(string href, RelativePath relativeToFile) { if (!Utility.IsSupportedRelativeHref(href)) { return(href); } return((relativeToFile + (RelativePath)href).GetPathFromWorkingFolder()); }
private void BuildCore(TocItemViewModel item, FileModel model, IHostService hostService, string includedFrom = null) { if (item == null) { return; } var linkToUids = new HashSet <string>(); var linkToFiles = new HashSet <string>(); var uidLinkSources = new Dictionary <string, ImmutableList <LinkSourceInfo> >(); var fileLinkSources = new Dictionary <string, ImmutableList <LinkSourceInfo> >(); if (Utility.IsSupportedRelativeHref(item.Href)) { UpdateDependencies(linkToFiles, fileLinkSources, item.Href); } if (Utility.IsSupportedRelativeHref(item.Homepage)) { UpdateDependencies(linkToFiles, fileLinkSources, item.Homepage); } if (!string.IsNullOrEmpty(item.TopicUid)) { UpdateDependencies(linkToUids, uidLinkSources, item.TopicUid); } model.LinkToUids = model.LinkToUids.Union(linkToUids); model.LinkToFiles = model.LinkToFiles.Union(linkToFiles); model.UidLinkSources = model.UidLinkSources.Merge(uidLinkSources); model.FileLinkSources = model.FileLinkSources.Merge(fileLinkSources); includedFrom = item.IncludedFrom ?? includedFrom; if (item.Items != null) { foreach (var i in item.Items) { BuildCore(i, model, hostService, includedFrom); } } void UpdateDependencies(HashSet <string> linkTos, Dictionary <string, ImmutableList <LinkSourceInfo> > linkSources, string link) { var path = UriUtility.GetPath(link); var anchor = UriUtility.GetFragment(link); linkTos.Add(path); AddOrUpdate(linkSources, path, GetLinkSourceInfo(path, anchor, model.File, includedFrom)); } }
private string ResolveHref(string originalPathToFile, FileModel model, IDocumentBuildContext context) { if (!Utility.IsSupportedRelativeHref(originalPathToFile)) { return(originalPathToFile); } string href = context.GetFilePath(originalPathToFile); if (href == null) { Logger.LogWarning($"Unable to find file \"{originalPathToFile}\" referenced by TOC file \"{model.LocalPathFromRepoRoot}\""); return(originalPathToFile); } var relativePath = GetRelativePath(href, model.File); return(((RelativePath)relativePath).UrlEncode()); }
private string NormalizeHref(string href, RelativePath relativeToFile) { if (!Utility.IsSupportedRelativeHref(href)) { return(href); } RelativePath relativeToTargetFile; try { relativeToTargetFile = RelativePath.Parse(href); } catch (Exception ex) { Logger.LogWarning(ex.Message, code: WarningCodes.Build.InvalidFileLink); return(href); } return((relativeToFile + relativeToTargetFile).GetPathFromWorkingFolder()); }
private void BuildCore(TocItemViewModel item, FileModel model, IHostService hostService) { if (item == null) { return; } var linkToUids = new HashSet <string>(); var linkToFiles = new HashSet <string>(); if (Utility.IsSupportedRelativeHref(item.Href)) { linkToFiles.Add(item.Href.Split('#')[0]); } if (Utility.IsSupportedRelativeHref(item.Homepage)) { linkToFiles.Add(item.Homepage.Split('#')[0]); } if (!string.IsNullOrEmpty(item.Uid)) { linkToUids.Add(item.Uid); } if (!string.IsNullOrEmpty(item.HomepageUid)) { linkToUids.Add(item.HomepageUid); } ((HashSet <string>)model.Properties.LinkToUids).UnionWith(linkToUids); ((HashSet <string>)model.Properties.LinkToFiles).UnionWith(linkToFiles); if (item.Items != null) { foreach (var i in item.Items) { BuildCore(i, model, hostService); } } }
private void RegisterTocMap(TocItemViewModel item, string key, IDocumentBuildContext context) { // If tocHref is set, href is originally RelativeFolder type, and href is set to the homepage of TocHref, // So in this case, TocHref should be used to in TocMap // TODO: what if user wants to set TocHref? var tocHref = item.TocHref; var tocHrefType = Utility.GetHrefType(tocHref); if (tocHrefType == HrefType.MarkdownTocFile || tocHrefType == HrefType.YamlTocFile) { context.RegisterToc(key, tocHref); } else { var href = item.Href; // Should be original href from working folder starting with ~ if (Utility.IsSupportedRelativeHref(href)) { context.RegisterToc(key, href); } } }
private void UpdateNearestToc(IHostService host, TocItemViewModel item, FileModel toc, ConcurrentDictionary <string, RelativeInfo> nearest) { var tocHref = item.TocHref; var type = Utility.GetHrefType(tocHref); if (type == HrefType.MarkdownTocFile || type == HrefType.YamlTocFile) { UpdateNearestTocCore(host, UriUtility.GetPath(tocHref), toc, nearest); } else if (item.TopicUid == null && Utility.IsSupportedRelativeHref(item.Href)) { UpdateNearestTocCore(host, UriUtility.GetPath(item.Href), toc, nearest); } if (item.Items != null && item.Items.Count > 0) { foreach (var i in item.Items) { UpdateNearestToc(host, i, toc, nearest); } } }
protected override void RegisterTocMapToContext(TocItemViewModel item, FileModel model, IDocumentBuildContext context) { var key = model.Key; // If tocHref is set, href is originally RelativeFolder type, and href is set to the homepage of TocHref, // So in this case, TocHref should be used to in TocMap // TODO: what if user wants to set TocHref? var tocHref = item.TocHref; var tocHrefType = Utility.GetHrefType(tocHref); if (tocHrefType == HrefType.MarkdownTocFile || tocHrefType == HrefType.YamlTocFile) { context.RegisterToc(key, HttpUtility.UrlDecode(UriUtility.GetPath(tocHref))); } else { var href = item.Href; // Should be original href from working folder starting with ~ if (Utility.IsSupportedRelativeHref(href)) { context.RegisterToc(key, HttpUtility.UrlDecode(UriUtility.GetPath(href))); } } }
private void BuildCore(TocItemViewModel item, FileModel model, IHostService hostService) { if (item == null) { return; } var linkToUids = new HashSet <string>(); var linkToFiles = new HashSet <string>(); if (Utility.IsSupportedRelativeHref(item.Href)) { linkToFiles.Add(ParseFile(item.Href)); } if (Utility.IsSupportedRelativeHref(item.Homepage)) { linkToFiles.Add(ParseFile(item.Homepage)); } if (!string.IsNullOrEmpty(item.TopicUid)) { linkToUids.Add(item.TopicUid); } model.LinkToUids = model.LinkToUids.Union(linkToUids); model.LinkToFiles = model.LinkToFiles.Union(linkToFiles); if (item.Items != null) { foreach (var i in item.Items) { BuildCore(i, model, hostService); } } }