예제 #1
0
        /// <summary>
        /// Invokes the router.
        /// </summary>
        /// <param name="api">The current api</param>
        /// <param name="url">The requested url</param>
        /// <param name="hostname">The optional hostname</param>
        /// <returns>The piranha response, null if no matching page was found</returns>
        public static IRouteResponse Invoke(IApi api, string url, Guid siteId)
        {
            if (string.IsNullOrWhiteSpace(url) || url == "/")
            {
                var page = api.Pages.GetStartpage <Models.PageInfo>(siteId);

                if (page != null)
                {
                    if (page.ContentType == "Page")
                    {
                        var site         = api.Sites.GetById(siteId);
                        var lastModified = !site.ContentLastModified.HasValue || page.LastModified > site.ContentLastModified
                            ? page.LastModified : site.ContentLastModified.Value;

                        return(new RouteResponse
                        {
                            PageId = page.Id,
                            Route = page.Route ?? "/page",
                            QueryString = "id=" + page.Id + "&startpage=true&piranha_handled=true",
                            IsPublished = page.Published.HasValue && page.Published.Value <= DateTime.Now,
                            CacheInfo = new HttpCacheInfo
                            {
                                EntityTag = Utils.GenerateETag(page.Id.ToString(), lastModified),
                                LastModified = lastModified
                            }
                        });
                    }
                    else if (page.ContentType == "Blog")
                    {
                        return(ArchiveRouter.Invoke(api, $"/{page.Slug}", siteId));
                    }
                }
            }
            return(null);
        }
예제 #2
0
        /// <summary>
        /// Invokes the router.
        /// </summary>
        /// <param name="api">The current api</param>
        /// <param name="url">The requested url</param>
        /// <param name="hostname">The optional hostname</param>
        /// <returns>The piranha response, null if no matching page was found</returns>
        public static async Task <IRouteResponse> InvokeAsync(IApi api, string url, Guid siteId)
        {
            if (string.IsNullOrWhiteSpace(url) || url == "/")
            {
                var page = await api.Pages.GetStartpageAsync <Models.PageInfo>(siteId)
                           .ConfigureAwait(false);

                if (page != null)
                {
                    var type = App.PageTypes.GetById(page.TypeId);

                    if (type != null)
                    {
                        if (!type.IsArchive)
                        {
                            var site = await api.Sites.GetByIdAsync(siteId).ConfigureAwait(false);

                            var lastModified = !site.ContentLastModified.HasValue || page.LastModified > site.ContentLastModified
                                ? page.LastModified : site.ContentLastModified.Value;

                            return(new RouteResponse
                            {
                                PageId = page.Id,
                                Route = page.Route ?? "/page",
                                QueryString = "id=" + page.Id + "&startpage=true&piranha_handled=true",
                                IsPublished = page.Published.HasValue && page.Published.Value <= DateTime.Now,
                                CacheInfo = new HttpCacheInfo
                                {
                                    EntityTag = Utils.GenerateETag(page.Id.ToString(), lastModified),
                                    LastModified = lastModified
                                }
                            });
                        }
                        else
                        {
                            return(await ArchiveRouter.InvokeAsync(api, $"/{page.Slug}", siteId).ConfigureAwait(false));
                        }
                    }
                }
            }
            return(null);
        }
예제 #3
0
        /// <summary>
        /// Invokes the router.
        /// </summary>
        /// <param name="api">The current api</param>
        /// <param name="url">The requested url</param>
        /// <param name="hostname">The optional hostname</param>
        /// <returns>The piranha response, null if no matching page was found</returns>
        public static IRouteResponse Invoke(IApi api, string url, string hostname)
        {
            if (string.IsNullOrWhiteSpace(url) || url == "/")
            {
                Data.Site site = null;

                if (!string.IsNullOrWhiteSpace(hostname))
                {
                    site = api.Sites.GetByHostname(hostname);
                }
                if (site == null)
                {
                    site = api.Sites.GetDefault();
                }

                var page = api.Pages.GetStartpage(site.Id);

                if (page != null)
                {
                    if (page.ContentType == "Page")
                    {
                        return(new RouteResponse()
                        {
                            Route = page.Route ?? "/page",
                            QueryString = "id=" + page.Id + "&startpage=true&piranha_handled=true",
                            IsPublished = page.Published.HasValue && page.Published.Value <= DateTime.Now,
                            CacheInfo = new HttpCacheInfo()
                            {
                                EntityTag = Utils.GenerateETag(page.Id.ToString(), page.LastModified),
                                LastModified = page.LastModified
                            }
                        });
                    }
                    else if (page.ContentType == "Blog")
                    {
                        return(ArchiveRouter.Invoke(api, $"/{page.Slug}", hostname));
                    }
                }
            }
            return(null);
        }