Browse Source

SEO标签

懒得勤快 5 years ago
parent
commit
9dbb92cb14

+ 4 - 1
src/Masuit.MyBlogs.Core/Common/CommonHelper.cs

@@ -254,8 +254,9 @@ namespace Masuit.MyBlogs.Core.Common
         /// 将html的img标签的src属性名替换成data-original
         /// </summary>
         /// <param name="html"></param>
+        /// <param name="title"></param>
         /// <returns></returns>
-        public static string ReplaceImgAttribute(this string html)
+        public static string ReplaceImgAttribute(this string html, string title)
         {
             var doc = new HtmlDocument();
             doc.LoadHtml(html);
@@ -267,6 +268,8 @@ namespace Masuit.MyBlogs.Core.Common
                     string src = node.Attributes["src"].Value;
                     node.Attributes.Remove("src");
                     node.Attributes.Add("data-original", src);
+                    node.Attributes.Add("alt", SystemSettings["Title"]);
+                    node.Attributes.Add("title", title);
                 }
             }
 

+ 2 - 1
src/Masuit.MyBlogs.Core/Masuit.MyBlogs.Core.xml

@@ -103,11 +103,12 @@
             <param name="html"></param>
             <returns></returns>
         </member>
-        <member name="M:Masuit.MyBlogs.Core.Common.CommonHelper.ReplaceImgAttribute(System.String)">
+        <member name="M:Masuit.MyBlogs.Core.Common.CommonHelper.ReplaceImgAttribute(System.String,System.String)">
             <summary>
             将html的img标签的src属性名替换成data-original
             </summary>
             <param name="html"></param>
+            <param name="title"></param>
             <returns></returns>
         </member>
         <member name="T:Masuit.MyBlogs.Core.Common.HangfireHelper">

+ 1 - 1
src/Masuit.MyBlogs.Core/Views/Misc/Index.cshtml

@@ -53,7 +53,7 @@
 </div>
 <div class="container">
     <article class="content">
-        @Html.Raw(Model.Content.ReplaceImgAttribute())
+        @Html.Raw(Model.Content.ReplaceImgAttribute(Model.Title))
     </article>
 </div>
 <script src="~/Assets/UEditor/third-party/SyntaxHighlighter/scripts/shCore.min.js"></script>

+ 1 - 1
src/Masuit.MyBlogs.Core/Views/Notice/Details.cshtml

@@ -66,7 +66,7 @@
                 <main>
                     <section>
                         <article class="article" id="article">
-                            @Html.Raw(Model.Content.ReplaceImgAttribute())
+                            @Html.Raw(Model.Content.ReplaceImgAttribute(Model.Title))
                         </article>
                     </section>
                 </main>

+ 3 - 4
src/Masuit.MyBlogs.Core/Views/Post/CompareVersion.cshtml

@@ -1,5 +1,4 @@
-@using System.Web
-@using Masuit.MyBlogs.Core.Common
+@using Masuit.MyBlogs.Core.Common
 @using Masuit.MyBlogs.Core.Models.Entity
 @model Masuit.MyBlogs.Core.Models.Entity.PostHistoryVersion[]
 @{
@@ -81,7 +80,7 @@
                                     </div>
                                 </header>
                                 <article class="article" id="article">
-                                    @Html.Raw(Model[1].Content.ReplaceImgAttribute())
+                                    @Html.Raw(Model[1].Content.ReplaceImgAttribute(Model[0].Title))
                                 </article>
                             </section>
                             @if (ads.Any())
@@ -167,7 +166,7 @@
                                     </div>
                                 </header>
                                 <article class="article" id="article">
-                                    @Html.Raw(Model[2].Content.ReplaceImgAttribute())
+                                    @Html.Raw(Model[2].Content.ReplaceImgAttribute(Model[0].Title))
                                 </article>
                             </section>
                             @if (ads.Count > 1)

+ 2 - 2
src/Masuit.MyBlogs.Core/Views/Post/Details.cshtml

@@ -91,14 +91,14 @@
                             </div>
                         </header>
                         <article class="article" id="article">
-                            @Html.Raw(Model.Content.ReplaceImgAttribute())
+                            @Html.Raw(Model.Content.ReplaceImgAttribute(Model.Title))
                             @if (!string.IsNullOrEmpty(Model.ProtectContent))
                             {
                                 <div class="row protected">
                                     @if (!string.IsNullOrEmpty(Context.Session.Get<string>("AccessViewToken")) || Context.Request.Cookies["Email"].MDString3(AppConfig.BaiduAK).Equals(Context.Request.Cookies["PostAccessToken"]))
                                     {
                                         <p class="text-red text-center size20">↓↓↓以下是文章加密部分↓↓↓</p>
-                                        @Html.Raw(Model.ProtectContent.ReplaceImgAttribute())
+                                        @Html.Raw(Model.ProtectContent.ReplaceImgAttribute(Model.Title))
 
                                     }
                                     else

+ 2 - 2
src/Masuit.MyBlogs.Core/Views/Post/HistoryVersion.cshtml

@@ -68,7 +68,7 @@
                             </div>
                         </header>
                         <article class="article" id="article">
-                            @Html.Raw(Model.Content.ReplaceImgAttribute())
+                            @Html.Raw(Model.Content.ReplaceImgAttribute(Model.Title))
                             @if (!string.IsNullOrEmpty(Model.ProtectContent))
                             {
                                 <div class="row protected">
@@ -108,7 +108,7 @@
                                     else
                                     {
                                         <p class="text-red text-center size20">↓↓↓以下是文章加密部分↓↓↓</p>
-                                        @Html.Raw(Model.ProtectContent.ReplaceImgAttribute())
+                                        @Html.Raw(Model.ProtectContent.ReplaceImgAttribute(Model.Title))
                                     }
                                 </div>
                             }