Esempio n. 1
0
        /**
         * 发布文章
         *
         * @param contents 文章对象
         */
        public int publish(ContentInput contents)
        {
            if (null == contents.AuthorId)
            {
                throw new Exception("请登录后发布文章");
            }
            contents.Created  = DateTime.Now;
            contents.Modified = DateTime.Now;
            contents.Hits     = 0;
            if (contents.FmtType.IsNullOrWhiteSpace())
            {
                contents.FmtType = "markdown";
            }
            var tags       = contents.Tags;
            var categories = contents.Categories;

            var entity = new Contents();

            _mapper.Map(contents, entity);

            var cid = _repository.InsertOrUpdateAndGetId(entity);

            _metasService.saveMetas(cid, tags, Types.TAG);
            _metasService.saveMetas(cid, categories, Types.CATEGORY);

            return(cid);
        }
Esempio n. 2
0
        private bool InitContent()
        {
            var about = _contentsService.publish(new ContentInput
            {
                Title        = "关于",
                Slug         = "about",
                Created      = DateTime.Now,
                Modified     = DateTime.Now,
                Content      = "### Hello World\r\n\r\n这是我的关于页面\r\n\r\n### 当然还有其他\r\n\r\n具体你来写点什么吧",
                AuthorId     = _users.Id,
                Type         = "page",
                Status       = "publish",
                Categories   = "默认分类",
                Hits         = 0,
                CommentsNum  = 0,
                AllowComment = true,
                AllowPing    = true,
                AllowFeed    = true
            });

            var firstArticle = _contentsService.publish(new ContentInput
            {
                Title        = "第一篇文章",
                Created      = DateTime.Now,
                Modified     = DateTime.Now,
                Content      = "## Hello  World.\r\n\r\n> 第一篇文章总得写点儿什么?...\r\n\r\n----------\r\n\r\n\r\n<!--more-->\r\n\r\n```java\r\npublic static void main(string[] args){\r\n    System.out.println(\\\"Hello Tale.\\\");\r\n}\r\n```",
                AuthorId     = _users.Id,
                Type         = "post",
                Status       = "publish",
                Categories   = "默认分类",
                Hits         = 10,
                CommentsNum  = 0,
                AllowComment = true,
                AllowPing    = true,
                AllowFeed    = true
            });

            var linkContent = _contentsService.publish(new ContentInput
            {
                Title        = "友情链接",
                Slug         = "links",
                Created      = DateTime.Now,
                Modified     = DateTime.Now,
                Content      = "## 友情链接\r\n\r\n- :lock: [王爵的技术博客]()\r\n- :lock: [cyang.tech]()\r\n- :lock: [Bakumon''s Blog]()\r\n\r\n## 链接须知\r\n\r\n> 请确定贵站可以稳定运营\r\n> 原创博客优先,技术类博客优先,设计、视觉类博客优先\r\n> 经常过来访问和评论,眼熟的\r\n\r\n备注:默认申请友情链接均为内页(当前页面)\r\n\r\n## 基本信息\r\n\r\n                网站名称:Tale博客\r\n                网站地址:https://tale.biezhi.me\r\n\r\n请在当页通过评论来申请友链,其他地方不予回复\r\n\r\n暂时先这样,同时欢迎互换友链,这个页面留言即可。 ^_^\r\n\r\n还有,我会不定时对无法访问的网址进行清理,请保证自己的链接长期有效。'",
                AuthorId     = _users.Id,
                Type         = "page",
                Status       = "publish",
                Categories   = "默认分类",
                Hits         = 10,
                CommentsNum  = 0,
                AllowComment = true,
                AllowPing    = true,
                AllowFeed    = true
            });

            _metasService.saveMetas(firstArticle, "默认分类", "category");
            return(true);
        }