Esempio n. 1
0
        public IActionResult Details(int id)
        {
            var post = _postRepository.GetPublishedPostById(id);

            //this ensures the post will not be null when the readtime calculator runs
            if (post != null)
            {
                //generates an estimated readtime based on 265 words per minute
                post.Readtime = _readTimeCalculator.CalculateReadTime(post.Content);
            }

            if (post == null)
            {
                int userId = GetCurrentUserProfileId();
                post = _postRepository.GetUserPostById(id, userId);
                if (post != null)
                {
                    post.Readtime = _readTimeCalculator.CalculateReadTime(post.Content);
                }


                if (post == null)
                {
                    return(NotFound());
                }
            }
            return(View(post));
        }
Esempio n. 2
0
        public async ValueTask <FluidValue> ProcessAsync(FluidValue input, FilterArguments arguments, TemplateContext ctx)
        {
            var text = await GetTextAsync(input);

            var readTime = _readTimeCalculator.CalculateReadTime(text);

            return(NumberValue.Create(readTime));
        }