Beispiel #1
0
        public async Task <IActionResult> OnGetAsync(CancellationToken cancellationToken, [FromQuery] int page = 1, [FromQuery] string category = null)
        {
            var result = await _mediator.Send(new GetPagedPostListQuery { Page = page, Category = category }, cancellationToken);

            PostList = result.Value;
            Title    = result.Value.Blog.Title;

            Metadata = new Models.MetadataModel
            {
                Description = PostList.Blog.Description,
                Title       = PostList.Blog.Title,
                Type        = "website",
                Url         = Request.GetEncodedUrl()
            };

            Metadata.Image = PostList.Blog.CoverUrl;
            if (PostList.Blog.CoverUrl != null && !PostList.Blog.CoverUrl.StartsWith("http", System.StringComparison.OrdinalIgnoreCase))
            {
                Metadata.Image = $"{Request.Scheme}://{Request.Host}{PostList.Blog.CoverUrl}";
            }

            PageCover = new Models.PageCoverModel
            {
                PostListType = PostList.PostListType,
                Category     = PostList.Category,
                Title        = PostList.Blog.Title,
                CoverUrl     = PostList.Blog.CoverUrl,
                CoverCaption = PostList.Blog.CoverCaption,
                CoverLink    = PostList.Blog.CoverLink,
            };

            return(Page());
        }
Beispiel #2
0
        public async Task <IActionResult> OnGetAsync(string slug, CancellationToken cancellationToken)
        {
            if (slug.EndsWith('/'))
            {
                // remove the '/' at the end of the slug to make it valid
                slug = slug.TrimEnd('/');
            }

            var result = await _mediator.Send(new GetPostQuery { Slug = slug }, cancellationToken);

            if (!result.IsSuccess)
            {
                return(Error(result));
            }

            Post  = result.Value;
            Title = result.Value.Post.Title;

            BlogTitle = Post.Blog.Title;

            Metadata = new Models.MetadataModel
            {
                Author      = Post.Post.Author.DisplayName,
                Description = Post.Post.Description,
                Published   = Post.Post.Published,
                Title       = Post.Post.Title,
                Type        = "article",
                Url         = Request.GetEncodedUrl()
            };

            Metadata.Image = Post.Post.CoverUrl;
            if (Post.Post.CoverUrl != null && !Post.Post.CoverUrl.StartsWith("http", System.StringComparison.OrdinalIgnoreCase))
            {
                Metadata.Image = $"{Request.Scheme}://{Request.Host}{Post.Post.CoverUrl}";
            }
            if (!string.IsNullOrWhiteSpace(Post.Post.Categories))
            {
                Metadata.Keywords = Post.Post.Categories?.Split(',');
            }

            PageCover = new Models.PageCoverModel
            {
                Title        = Post.Post.Title,
                CoverUrl     = Post.Post.CoverUrl,
                CoverCaption = Post.Post.CoverCaption,
                CoverLink    = Post.Post.CoverLink
            };

            return(Page());
        }
Beispiel #3
0
        private IActionResult GetPage(Result <PostListModel> result)
        {
            PostList   = result.Value;
            Title      = result.Value.Blog.Title;
            ShowSearch = _options.Value.EnableSearch;

            if (PostList.PostListType == PostListType.Search)
            {
                BlogTitle   = result.Value.Blog.Title;
                SearchQuery = PostList.SearchQuery;
            }

            Metadata = new Models.MetadataModel
            {
                Description = PostList.Blog.Description,
                Title       = PostList.Blog.Title,
                Type        = "website",
                Url         = Request.GetEncodedUrl()
            };

            Metadata.Image = PostList.Blog.CoverUrl;
            if (PostList.Blog.CoverUrl != null && !PostList.Blog.CoverUrl.StartsWith("http", System.StringComparison.OrdinalIgnoreCase))
            {
                Metadata.Image = $"{Request.Scheme}://{Request.Host}{PostList.Blog.CoverUrl}";
            }

            PageCover = new Models.PageCoverModel
            {
                PostListType = PostList.PostListType,
                Category     = PostList.Category,
                Title        = PostList.Blog.Title,
                CoverUrl     = PostList.Blog.CoverUrl,
                CoverCaption = PostList.Blog.CoverCaption,
                CoverLink    = PostList.Blog.CoverLink,
            };

            return(Page());
        }