コード例 #1
0
        public async Task Create(
            string projectId,
            string userName,
            string password,
            IPost post,
            bool publish)
        {
            var permission = await security.ValidatePermissions(
                projectId,
                userName,
                password,
                CancellationToken
                ).ConfigureAwait(false);

            if (!permission.CanEditPosts)
            {
                return;
            }

            var settings = await projectService.GetProjectSettings(projectId).ConfigureAwait(false);

            await InitializeNewPosts(projectId, post, publish);

            var urlHelper            = urlHelperFactory.GetUrlHelper(actionContextAccesor.ActionContext);
            var imageAbsoluteBaseUrl = urlHelper.Content("~" + settings.LocalMediaVirtualPath);

            if (context != null)
            {
                imageAbsoluteBaseUrl = context.Request.AppBaseUrl() + settings.LocalMediaVirtualPath;
            }

            // open live writer passes in posts with absolute urls
            // we want to change them to relative to keep the files portable
            // to a different root url
            post.Content = await htmlProcessor.ConvertMediaUrlsToRelative(
                settings.LocalMediaVirtualPath,
                imageAbsoluteBaseUrl, //this shold be resolved from virtual using urlhelper
                post.Content);

            // olw also adds hard coded style to images
            post.Content = htmlProcessor.RemoveImageStyleAttribute(post.Content);

            var nonPublishedDate = new DateTime(1, 1, 1);

            if (post.PubDate == nonPublishedDate)
            {
                post.PubDate = DateTime.UtcNow;
            }

            await postCommands.Create(settings.Id, post).ConfigureAwait(false);

            await eventHandlers.HandleCreated(settings.Id, post).ConfigureAwait(false);
        }
コード例 #2
0
        public async Task Create(IPost post)
        {
            await EnsureBlogSettings().ConfigureAwait(false);

            //if(convertToRelativeUrls)
            //{
            //    await _blogUrlResolver.ConvertToRelativeUrls(post, _settings).ConfigureAwait(false);
            //}

            if (string.IsNullOrEmpty(post.Slug))
            {
                var slug      = CreateSlug(post.Title);
                var available = await SlugIsAvailable(slug);

                while (!available)
                {
                    slug      = slug + "-";
                    available = await SlugIsAvailable(slug);
                }
                if (available)
                {
                    post.Slug = slug;
                }
            }

            await _postCommands.Create(_settings.Id, post).ConfigureAwait(false);

            await _eventHandlers.HandleCreated(_settings.Id, post).ConfigureAwait(false);
        }