public async Task <string> GetContentItemIdFromRouteAsync(PathString url) { if (!url.HasValue) { url = "/"; } string contentItemId = null; if (url == "/") { // get contentItemId from homeroute var siteSettings = await _siteService.GetSiteSettingsAsync(); contentItemId = siteSettings.HomeRoute["contentItemId"]?.ToString(); } else { // Try to get from autorouteEntries. // This should not consider contained items, so will redirect to the parent item. if (_autorouteEntries.TryGetEntryByPath(url.Value, out var entry)) { contentItemId = entry.ContentItemId; } ; } if (string.IsNullOrEmpty(contentItemId)) { return(null); } return(contentItemId); }
public Task RenderingAsync(TemplateContext context) { context.MemberAccessStrategy.Register <LiquidContentAccessor, LiquidPropertyAccessor>("Slug", obj => { return(new LiquidPropertyAccessor(async alias => { if (!alias.StartsWith('/')) { alias = "/" + alias; } if (_autorouteEntries.TryGetEntryByPath(alias, out var entry)) { return FluidValue.Create(await _contentManager.GetAsync(entry.ContentItemId, entry.JsonPath)); } return NilValue.Instance; })); });
public override ValueTask <RouteValueDictionary> TransformAsync(HttpContext httpContext, RouteValueDictionary values) { if (_entries.TryGetEntryByPath(httpContext.Request.Path.Value, out var entry)) { var routeValues = new RouteValueDictionary(_options.GlobalRouteValues) { [_options.ContentItemIdKey] = entry.ContentItemId }; if (!string.IsNullOrEmpty(entry.JsonPath)) { routeValues[_options.JsonPathKey] = entry.JsonPath; } return(new ValueTask <RouteValueDictionary>(routeValues)); } return(new ValueTask <RouteValueDictionary>((RouteValueDictionary)null)); }
public Task <string> GetContentItemIdAsync(string alias) { if (alias.StartsWith("slug:", System.StringComparison.OrdinalIgnoreCase)) { alias = alias.Substring(5); if (!alias.StartsWith('/')) { alias = "/" + alias; } if (_autorouteEntries.TryGetEntryByPath(alias, out var entry)) { // TODO this requires more work, and interface changes to support contained content items. // as it will require returning the id and jsonPath. return(Task.FromResult(entry.ContentItemId)); } } return(Task.FromResult <string>(null)); }
public override ValueTask <RouteValueDictionary> TransformAsync(HttpContext httpContext, RouteValueDictionary values) { if (_entries.TryGetEntryByPath(httpContext.Request.Path.Value, out var entry)) { var routeValues = new RouteValueDictionary(_options.GlobalRouteValues) { [_options.ContentItemIdKey] = entry.ContentItemId }; if (!string.IsNullOrEmpty(entry.JsonPath)) { routeValues[_options.JsonPathKey] = entry.JsonPath; } // Prevents the original values from being re-added to the dynamic ones. values.Clear(); return(new ValueTask <RouteValueDictionary>(routeValues)); } return(new ValueTask <RouteValueDictionary>((RouteValueDictionary)null)); }