fix page Path so it supports the specification of external Urls, querystrings, and anchors

This commit is contained in:
sbwalker
2024-02-28 13:10:14 -05:00
parent aa5df3c309
commit f439541844
3 changed files with 127 additions and 52 deletions

View File

@ -380,7 +380,7 @@
}
else
{
if (_path.Contains("/"))
if (_path.Contains("/") & !_path.Contains("://"))
{
_path = _path.Substring(_path.LastIndexOf("/") + 1);
}
@ -518,36 +518,56 @@
_page.Name = _name;
if (string.IsNullOrEmpty(_path))
// path can be a link to an external url
if (!_path.Contains("://"))
{
_path = _name;
}
if (_path.Contains("/"))
{
if (_path.EndsWith("/") && _path != "/")
if (string.IsNullOrEmpty(_path))
{
_path = _path.Substring(0, _path.Length - 1);
_path = _name;
}
_path = _path.Substring(_path.LastIndexOf("/") + 1);
var fragment = (_path.Contains("?")) ? _path.Substring(_path.IndexOf("?")) : "";
fragment = (_path.Contains("#")) ? _path.Substring(_path.IndexOf("#")) : "";
_path = (!string.IsNullOrEmpty(fragment)) ? _path.Replace(fragment, "") : _path;
if (_path.Contains("/"))
{
if (_path.EndsWith("/") && _path != "/")
{
_path = _path.Substring(0, _path.Length - 1);
}
_path = _path.Substring(_path.LastIndexOf("/") + 1);
}
if (_parentid == "-1")
{
_page.Path = Utilities.GetFriendlyUrl(_path);
}
else
{
Page parent = PageState.Pages.FirstOrDefault(item => item.PageId == _page.ParentId);
if (parent.Path == string.Empty)
{
_page.Path = Utilities.GetFriendlyUrl(parent.Name) + "/" + Utilities.GetFriendlyUrl(_path);
}
else
{
_page.Path = parent.Path + "/" + Utilities.GetFriendlyUrl(_path);
}
}
_page.Path += fragment;
}
else
{
_page.Path = _path;
}
if (_parentid == "-1")
{
_page.ParentId = null;
_page.Path = Utilities.GetFriendlyUrl(_path);
}
else
{
_page.ParentId = Int32.Parse(_parentid);
Page parent = PageState.Pages.FirstOrDefault(item => item.PageId == _page.ParentId);
if (parent.Path == string.Empty)
{
_page.Path = Utilities.GetFriendlyUrl(parent.Name) + "/" + Utilities.GetFriendlyUrl(_path);
}
else
{
_page.Path = parent.Path + "/" + Utilities.GetFriendlyUrl(_path);
}
}
var _pages = await PageService.GetPagesAsync(PageState.Site.SiteId);
@ -638,7 +658,14 @@
}
else
{
NavigationManager.NavigateTo(NavigateUrl(), true);
if (!_page.Path.Contains("://"))
{
NavigationManager.NavigateTo(NavigateUrl(), true); // redirect to page being edited
}
else
{
NavigationManager.NavigateTo(NavigateUrl("admin/pages"));
}
}
}
else