public async Task <string> GetContentItemIdFromRouteAsync(PathString url)
        {
            if (!url.HasValue)
            {
                url = "/";
            }

            string contentItemId;

            if (url == "/")
            {
                // get contentItemId from homeroute
                var siteSettings = await _siteService.GetSiteSettingsAsync();

                contentItemId = siteSettings.HomeRoute["contentItemId"]?.ToString();
            }
            else
            {
                // try to get from autorouteEntries
                _autorouteEntries.TryGetContentItemId(url, out contentItemId);
            }

            if (string.IsNullOrEmpty(contentItemId))
            {
                return(null);
            }

            return(contentItemId);
        }
Esempio n. 2
0
        public Task RouteAsync(RouteContext context)
        {
            var requestPath = context.HttpContext.Request.Path.ToString();

            if (!requestPath.StartsWith(_prefix, StringComparison.OrdinalIgnoreCase))
            {
                return(Task.CompletedTask);
            }

            var path = requestPath.ToString().Substring(_prefix.Length);

            int contentItemId;

            if (_entries.TryGetContentItemId(path, out contentItemId))
            {
                context.RouteData.Values["area"]       = "Orchard.Contents";
                context.RouteData.Values["controller"] = "Item";
                context.RouteData.Values["action"]     = "Display";
                context.RouteData.Values["id"]         = contentItemId;

                context.RouteData.Routers.Add(_target);
                return(_target.RouteAsync(context));
            }

            return(Task.CompletedTask);
        }
Esempio n. 3
0
        public async Task RouteAsync(RouteContext context)
        {
            var requestPath = context.HttpContext.Request.Path.Value;

            if (_entries.TryGetContentItemId(requestPath, out var contentItemId))
            {
                await EnsureRouteData(context, contentItemId);

                await _target.RouteAsync(context);
            }
        }
Esempio n. 4
0
        public override ValueTask <RouteValueDictionary> TransformAsync(HttpContext httpContext, RouteValueDictionary values)
        {
            if (_entries.TryGetContentItemId(httpContext.Request.Path.Value.TrimEnd('/'), out var contentItemId))
            {
                var routeValues = new RouteValueDictionary(_options.GlobalRouteValues);
                routeValues[_options.ContentItemIdKey] = contentItemId;
                return(new ValueTask <RouteValueDictionary>(routeValues));
            }

            return(new ValueTask <RouteValueDictionary>((RouteValueDictionary)null));
        }
Esempio n. 5
0
        public Task <string> GetContentItemIdAsync(string alias)
        {
            string contentItemId;

            if (alias.StartsWith("slug:"))
            {
                alias = alias.Substring(5);

                if (_autorouteEntries.TryGetContentItemId(alias, out contentItemId))
                {
                    return(Task.FromResult(contentItemId));
                }
            }

            return(Task.FromResult <string>(null));
        }
Esempio n. 6
0
        public Task RouteAsync(RouteContext context)
        {
            var requestPath = context.HttpContext.Request.Path.Value;

            string contentItemId;

            if (_entries.TryGetContentItemId(requestPath, out contentItemId))
            {
                context.RouteData.Values["area"]          = "Orchard.Contents";
                context.RouteData.Values["controller"]    = "Item";
                context.RouteData.Values["action"]        = "Display";
                context.RouteData.Values["contentItemId"] = contentItemId;

                context.RouteData.Routers.Add(_target);
                return(_target.RouteAsync(context));
            }

            return(Task.CompletedTask);
        }
        public Task <string> GetContentItemIdAsync(string alias)
        {
            if (alias.StartsWith("slug:", System.StringComparison.OrdinalIgnoreCase))
            {
                alias = alias.Substring(5);

                if (!alias.StartsWith("/"))
                {
                    alias = "/" + alias;
                }

                string contentItemId;
                if (_autorouteEntries.TryGetContentItemId(alias, out contentItemId))
                {
                    return(Task.FromResult(contentItemId));
                }
            }

            return(Task.FromResult <string>(null));
        }
        public Task RenderingAsync(TemplateContext context)
        {
            context.MemberAccessStrategy.Register <LiquidContentAccessor, LiquidPropertyAccessor>("Slug", obj =>
            {
                return(new LiquidPropertyAccessor(async alias =>
                {
                    if (!alias.StartsWith("/"))
                    {
                        alias = "/" + alias;
                    }

                    string contentItemId;
                    if (_autorouteEntries.TryGetContentItemId(alias, out contentItemId))
                    {
                        return FluidValue.Create(await _contentManager.GetAsync(contentItemId));
                    }

                    return NilValue.Instance;
                }));
            });

            return(Task.CompletedTask);
        }