Пример #1
0
        public override async Task PublishedAsync(PublishContentContext context, AutoroutePart part)
        {
            // Remove entry if part is disabled.
            if (part.Disabled)
            {
                await _entries.RemoveEntryAsync(part.ContentItem.ContentItemId, part.Path);
            }

            // Add parent content item path, and children, only if parent has a valid path.
            if (!String.IsNullOrWhiteSpace(part.Path) && !part.Disabled)
            {
                var entriesToAdd = new List <AutorouteEntry>
                {
                    new AutorouteEntry(part.ContentItem.ContentItemId, part.Path)
                };

                if (part.RouteContainedItems)
                {
                    _contentManager ??= _serviceProvider.GetRequiredService <IContentManager>();

                    var containedAspect = await _contentManager.PopulateAspectAsync <ContainedContentItemsAspect>(context.PublishingItem);

                    await PopulateContainedContentItemRoutes(entriesToAdd, part.ContentItem.ContentItemId, containedAspect, context.PublishingItem.Content as JObject, part.Path, true);
                }

                await _entries.AddEntriesAsync(entriesToAdd);
            }

            if (!String.IsNullOrWhiteSpace(part.Path) && !part.Disabled && part.SetHomepage)
            {
                await SetHomeRoute(part, homeRoute => homeRoute[_options.ContentItemIdKey] = context.ContentItem.ContentItemId);
            }

            // Evict any dependent item from cache
            await RemoveTagAsync(part);
        }