Example #1
0
        public ReturnValue AddOrEdit(Html html)
        {
            ReturnValue retValue = new ReturnValue();
            if (html == null || html.ArtID < 0)
            {
                retValue.IsExists = false;
                retValue.Message = "html 信息为空";
                return retValue;
            }
            Html old = this.Get(html.ArtID);

            using (HtmlDal dal = new HtmlDal())
            {
                if (old == null)
                {
                    if (dal.Add(html))
                    {
                        retValue.IsExists = true;
                        retValue.Message = "页面信息添加成功";
                    }
                    else
                    {
                        retValue.IsExists = false;
                        retValue.Message = "页面信息添加失败";
                    }
                }
                else//修改
                {
                    if (dal.Modify(html))
                    {
                        retValue.IsExists = true;
                        retValue.Message = "页面信息修改成功";
                    }
                    else
                    {
                        retValue.IsExists = false;
                        retValue.Message = "页面信息修改失败";
                    }
                }
            }
            return retValue;
        }
Example #2
0
        /// <summary>
        /// 生成静态页面信息
        /// </summary>
        /// <param name="article">文章信息</param>
        /// <param name="html">html页面信息</param>
        /// <returns></returns>
        protected bool CreateHtml(VwArticle article, Html html)
        {
            StringTemplate st = CodeNote.Common.TemplateWrap.GetSt("article_detail");
            if (st != null)
            {
                article.Body = CodeNote.Markdown.Default.Transform(article.Body);
                //markdown to html
                st.SetAttribute("update", html.Upda);
                st.SetAttribute("keywords", article.Tag);//搜索关键字
                st.SetAttribute("taglinks", TagInfoManager.TagLinks(article.Tag));
                st.SetAttribute("description", CodeNote.Common.StringFilter.ClearHtml(article.Body,200));
                st.SetAttribute("entity", article);

                return CodeNote.Common.IoWrap.WriteFile(CodeNote.Common.ConfigWrap.FiePath(STATIC_HTML_DIR) + html.Url, st.ToString());
            }
            else
            {
                log.Warn("Not find 'article_detail.st' template !");
            }
            return false;
        }
Example #3
0
 /// <summary>
 /// 创建文章的静态html页面
 /// </summary>
 /// <param name="article">文章实体</param>
 /// <returns></returns>
 public ReturnValue CreateHtml(VwArticle article)
 {
     ReturnValue retValue = new ReturnValue(false, "生成失败");
     if (article == null || article.ID < 0)
     {
         log.Info("CreateHtml article is null !");
         retValue.Message = "参数不正确";
         return retValue;
     }
     Html htm = this.Get(article.ID);
     if (htm == null)//没有静态页记录
     {
         htm = new Html();
         htm.ArtID = article.ID;
         htm.Url = CodeNote.Common.IDentity.CreateNew().AddStr("/").AddDate("yyyy").AddStr("/").AddDate("MM").AddStr("/").AddDate("ddHHmmssff").AddStr(5).StrID() + ".html";
         article.HtmlUrl = htm.Url;
         htm.Upda = article.ModDate;
     }
     else
     {
         htm.Upda = article.ModDate;
         log.Info("Modify: " + article.Subject + " => " + htm.Url);
     }
     if (CreateHtml(article, htm))
     {
         retValue = this.AddOrEdit(htm);
     }
     return retValue;
 }