From 8837db7e95e9b3cef6688b6326a38a8fc7dc6f44 Mon Sep 17 00:00:00 2001 From: Fredrik Arvidsson Date: Thu, 8 Apr 2021 19:45:46 +0200 Subject: [PATCH 1/5] change to https links --- BlogEngine/BlogEngine.Core/Web/Scripting/Helpers.cs | 2 +- BlogEngine/BlogEngine.NET/Account/account.master | 2 +- .../BlogEngine.NET/admin/themes/standard/layout.cshtml | 2 +- BlogEngine/BlogEngine.NET/page.aspx | 6 +++--- BlogEngine/BlogEngine.NET/post.aspx | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/BlogEngine/BlogEngine.Core/Web/Scripting/Helpers.cs b/BlogEngine/BlogEngine.Core/Web/Scripting/Helpers.cs index 71a14cf21..14ed76b07 100644 --- a/BlogEngine/BlogEngine.Core/Web/Scripting/Helpers.cs +++ b/BlogEngine/BlogEngine.Core/Web/Scripting/Helpers.cs @@ -120,7 +120,7 @@ public static void AddTrackingScript(System.Web.UI.Page page) sb.Append("if(links[i].href.indexOf('#comment') >= 0) { "); sb.Append("query += 'url' + i + '=' + encodeURIComponent(links[i].href) + '&'; "); sb.Append("}}"); - sb.Append("document.write(' diff --git a/BlogEngine/BlogEngine.NET/admin/themes/standard/layout.cshtml b/BlogEngine/BlogEngine.NET/admin/themes/standard/layout.cshtml index 6213dc8ea..bd9fca4c8 100644 --- a/BlogEngine/BlogEngine.NET/admin/themes/standard/layout.cshtml +++ b/BlogEngine/BlogEngine.NET/admin/themes/standard/layout.cshtml @@ -24,7 +24,7 @@ @BlogSettings.Instance.Name (@Security.CurrentMembershipUser.UserName) - + @Styles.Render("~/Content/admincss") diff --git a/BlogEngine/BlogEngine.NET/page.aspx b/BlogEngine/BlogEngine.NET/page.aspx index 1a5bcd6b7..18c1d69ae 100644 --- a/BlogEngine/BlogEngine.NET/page.aspx +++ b/BlogEngine/BlogEngine.NET/page.aspx @@ -14,12 +14,12 @@ var disqus_developer = '<%= BlogSettings.Instance.DisqusDevMode ? 1 : 0 %>'; (function() { var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true; - dsq.src = 'http://<%=BlogSettings.Instance.DisqusWebsiteName %>.disqus.com/embed.js'; + dsq.src = 'https://<%=BlogSettings.Instance.DisqusWebsiteName %>.disqus.com/embed.js'; (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq); })(); - - blog comments powered by Disqus + + blog comments powered by Disqus <%} %> diff --git a/BlogEngine/BlogEngine.NET/post.aspx b/BlogEngine/BlogEngine.NET/post.aspx index 376353d93..716c134dd 100644 --- a/BlogEngine/BlogEngine.NET/post.aspx +++ b/BlogEngine/BlogEngine.NET/post.aspx @@ -35,7 +35,7 @@ var disqus_developer = '<%= BlogSettings.Instance.DisqusDevMode ? 1 : 0 %>'; (function() { var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true; - dsq.src = '<%=Request.Url.Scheme %>://<%= BlogSettings.Instance.DisqusWebsiteName %>.disqus.com/embed.js'; + dsq.src = 'https://<%= BlogSettings.Instance.DisqusWebsiteName %>.disqus.com/embed.js'; (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq); })(); From 044f16d0767cac943abf004ecec877da20616974 Mon Sep 17 00:00:00 2001 From: Fredrik Arvidsson Date: Thu, 8 Apr 2021 19:46:18 +0200 Subject: [PATCH 2/5] use simple post descriptions without page title --- BlogEngine/BlogEngine.NET/post.aspx.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/BlogEngine/BlogEngine.NET/post.aspx.cs b/BlogEngine/BlogEngine.NET/post.aspx.cs index ec8827dbf..40fd1218a 100644 --- a/BlogEngine/BlogEngine.NET/post.aspx.cs +++ b/BlogEngine/BlogEngine.NET/post.aspx.cs @@ -220,7 +220,8 @@ private void InitNavigationLinks() /// private void AddMetaDescription() { - var desc = BlogSettings.Instance.Name + " - " + BlogSettings.Instance.Description + " - " + Post.Description; + //var desc = BlogSettings.Instance.Name + " - " + BlogSettings.Instance.Description + " - " + Post.Description; + var desc = Post.Description; base.AddMetaTag("description", Server.HtmlEncode(desc)); } From aa6f8c8be3561ad6d1ccdcd2303c6d2e455e1e9c Mon Sep 17 00:00:00 2001 From: Fredrik Arvidsson Date: Thu, 8 Apr 2021 23:33:24 +0200 Subject: [PATCH 3/5] add better seo --- .../Web/Controls/BlogBasePage.cs | 21 +++ BlogEngine/BlogEngine.NET/post.aspx.cs | 144 ++++++++++-------- 2 files changed, 99 insertions(+), 66 deletions(-) diff --git a/BlogEngine/BlogEngine.Core/Web/Controls/BlogBasePage.cs b/BlogEngine/BlogEngine.Core/Web/Controls/BlogBasePage.cs index e2732b182..f73614520 100644 --- a/BlogEngine/BlogEngine.Core/Web/Controls/BlogBasePage.cs +++ b/BlogEngine/BlogEngine.Core/Web/Controls/BlogBasePage.cs @@ -92,6 +92,9 @@ protected virtual void AddMetaContentType() /// /// The tag value. /// + /// + /// The property name + /// protected virtual void AddMetaTag(string name, string value) { if (string.IsNullOrEmpty(name) || string.IsNullOrEmpty(value)) @@ -101,6 +104,24 @@ protected virtual void AddMetaTag(string name, string value) Header.Controls.Add(new LiteralControl(string.Format(tag, name, value))); } + protected virtual void AddMetaProperty(string property, string value) + { + if (string.IsNullOrEmpty(property) || string.IsNullOrEmpty(value)) + return; + + const string tag = "\n\t"; + Header.Controls.Add(new LiteralControl(string.Format(tag, property, value))); + } + + protected virtual void AddMetaProperty(string name, string property, string value) + { + if (string.IsNullOrEmpty(name) || string.IsNullOrEmpty(property) || string.IsNullOrEmpty(value)) + return; + + const string tag = "\n\t"; + Header.Controls.Add(new LiteralControl(string.Format(tag, name, property, value))); + } + /// /// Raises the event. /// diff --git a/BlogEngine/BlogEngine.NET/post.aspx.cs b/BlogEngine/BlogEngine.NET/post.aspx.cs index 40fd1218a..e63e76740 100644 --- a/BlogEngine/BlogEngine.NET/post.aspx.cs +++ b/BlogEngine/BlogEngine.NET/post.aspx.cs @@ -34,7 +34,7 @@ protected override void OnInit(EventArgs e) // If there's more than one post that has the same RelativeLink // this post has then don't do a 301 redirect. - if (Post.Posts.FindAll(delegate(Post p) + if (Post.Posts.FindAll(delegate (Post p) { return p.RelativeLink.Equals(post.RelativeLink); } ).Count < 2) { @@ -100,10 +100,14 @@ protected override void OnInit(EventArgs e) Page.Title = encodedPostTitle; AddMetaKeywords(); - AddMetaDescription(); - base.AddMetaTag("author", Server.HtmlEncode(Post.AuthorProfile == null ? Post.Author : Post.AuthorProfile.FullName)); - - List visiblePosts = Post.Posts.FindAll(delegate(Post p) { return p.IsVisible; }); + AddMetaData(); + var author = Server.HtmlEncode( + Post.AuthorProfile == null + ? Post.Author + : Post.AuthorProfile.FullName); + base.AddMetaProperty("author", "article:author", author); + + List visiblePosts = Post.Posts.FindAll(delegate (Post p) { return p.IsVisible; }); if (visiblePosts.Count > 0) { AddGenericLink("last", visiblePosts[0].Title, visiblePosts[0].RelativeLink); @@ -150,43 +154,43 @@ protected override void OnInit(EventArgs e) } - /// - /// Gets the next post filtered for invisible posts. - /// - private Post GetNextPost(Post post) - { - if (post.Next == null) - return null; - - if (post.Next.IsVisible) - return post.Next; - - return GetNextPost(post.Next); - } - - /// - /// Gets the prev post filtered for invisible posts. - /// - private Post GetPrevPost(Post post) - { - if (post.Previous == null) - return null; - - if (post.Previous.IsVisible) - return post.Previous; - - return GetPrevPost(post.Previous); - } - - /// - /// Inits the navigation links above the post and in the HTML head section. - /// - private void InitNavigationLinks() - { - if (BlogSettings.Instance.ShowPostNavigation) - { - Post next = GetNextPost(Post); - Post prev = GetPrevPost(Post); + /// + /// Gets the next post filtered for invisible posts. + /// + private Post GetNextPost(Post post) + { + if (post.Next == null) + return null; + + if (post.Next.IsVisible) + return post.Next; + + return GetNextPost(post.Next); + } + + /// + /// Gets the prev post filtered for invisible posts. + /// + private Post GetPrevPost(Post post) + { + if (post.Previous == null) + return null; + + if (post.Previous.IsVisible) + return post.Previous; + + return GetPrevPost(post.Previous); + } + + /// + /// Inits the navigation links above the post and in the HTML head section. + /// + private void InitNavigationLinks() + { + if (BlogSettings.Instance.ShowPostNavigation) + { + Post next = GetNextPost(Post); + Post prev = GetPrevPost(Post); if ((next != null && !next.Deleted) || (prev != null && !prev.Deleted)) { @@ -195,13 +199,13 @@ private void InitNavigationLinks() // Try to load PostNavigation from theme folder var template = BlogSettings.Instance.IsRazorTheme ? "PostNavigation.cshtml" : "PostNavigation.ascx"; - var path =$"{Utils.ApplicationRelativeWebRoot}Custom/Themes/{BlogSettings.Instance.Theme}/{template}"; + var path = $"{Utils.ApplicationRelativeWebRoot}Custom/Themes/{BlogSettings.Instance.Theme}/{template}"; if (!System.IO.File.Exists(Server.MapPath(path))) path = Utils.ApplicationRelativeWebRoot + "Custom/Controls/Defaults/PostNavigation.ascx"; else path = Utils.ApplicationRelativeWebRoot + "Custom/Themes/" + BlogSettings.Instance.GetThemeWithAdjustments(null) + "/PostNavigation.ascx"; - + var navView = (PostNavigationBase)LoadControl(path); navView.CurrentPost = this.Post; phPostNavigation.Controls.Add(navView); @@ -212,28 +216,36 @@ private void InitNavigationLinks() Utils.Log("Error loading PostNavigation template", ex); } } - } - } - - /// - /// Adds the post's description as the description metatag. - /// - private void AddMetaDescription() - { - //var desc = BlogSettings.Instance.Name + " - " + BlogSettings.Instance.Description + " - " + Post.Description; - var desc = Post.Description; - base.AddMetaTag("description", Server.HtmlEncode(desc)); - } - - /// - /// Adds the post's tags as meta keywords. - /// - private void AddMetaKeywords() - { + } + } + + /// + /// Adds the post's description as the description metatag. + /// + private void AddMetaData() + { + base.AddMetaProperty("title", "og:title", Post.Title); + base.AddMetaProperty("description", "og:description", Server.HtmlEncode(Post.Description)); + base.AddMetaProperty("og:site_name", BlogSettings.Instance.Name); + base.AddMetaProperty("og:url", Post.AbsoluteLink.AbsoluteUri); + base.AddMetaProperty("image", "og:image", + Utils.AbsoluteWebRoot.AbsoluteUri + + Post.FirstImgSrc.TrimStart('/')); + base.AddMetaProperty("og:type", "article"); + base.AddMetaProperty("article:published_time", Post.DateCreated.ToString("O")); + base.AddMetaProperty("article:modified_time", Post.DateModified.ToString("O")); + } + + /// + /// Adds the post's tags as meta keywords. + /// + private void AddMetaKeywords() + { if (Post.Tags.Count > 0) - { - base.AddMetaTag("keywords", Server.HtmlEncode(string.Join(",", Post.Tags.ToArray()))); - } + { + var tags = Server.HtmlEncode(string.Join(",", Post.Tags.ToArray())); + base.AddMetaProperty("keywords", "article:tag", tags); + } if (ShowFacebookComments) { var tag = "\n\t"; @@ -241,7 +253,7 @@ private void AddMetaKeywords() } } - public Post Post; + public Post Post; public static bool ShowBlogengineComments { From cf87257cf8d25f574d81b0a3acb37c5a6d5e7a51 Mon Sep 17 00:00:00 2001 From: Fredrik Arvidsson Date: Thu, 8 Apr 2021 23:33:38 +0200 Subject: [PATCH 4/5] detect https behind a proxy --- BlogEngine/BlogEngine.Core/Blog.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BlogEngine/BlogEngine.Core/Blog.cs b/BlogEngine/BlogEngine.Core/Blog.cs index 62810443f..ae3ab1114 100644 --- a/BlogEngine/BlogEngine.Core/Blog.cs +++ b/BlogEngine/BlogEngine.Core/Blog.cs @@ -699,7 +699,7 @@ public Uri AbsoluteWebRoot } uri.Path = RelativeWebRoot; - uri.Scheme = context.Request.Url.Scheme; // added for https support + uri.Scheme = context.Request.Headers["x_forwarded_proto"] ?? context.Request.Url.Scheme; // added for https support absoluteWebRoot = uri.Uri; context.Items[contextItemKey] = absoluteWebRoot; From 9070b91df9b8d475067d11935d6e2006fbbda4ea Mon Sep 17 00:00:00 2001 From: Fredrik Arvidsson Date: Thu, 8 Apr 2021 23:46:27 +0200 Subject: [PATCH 5/5] support image metadata tags where the image is an absolute url --- BlogEngine/BlogEngine.NET/post.aspx.cs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/BlogEngine/BlogEngine.NET/post.aspx.cs b/BlogEngine/BlogEngine.NET/post.aspx.cs index e63e76740..b105a800c 100644 --- a/BlogEngine/BlogEngine.NET/post.aspx.cs +++ b/BlogEngine/BlogEngine.NET/post.aspx.cs @@ -228,9 +228,13 @@ private void AddMetaData() base.AddMetaProperty("description", "og:description", Server.HtmlEncode(Post.Description)); base.AddMetaProperty("og:site_name", BlogSettings.Instance.Name); base.AddMetaProperty("og:url", Post.AbsoluteLink.AbsoluteUri); - base.AddMetaProperty("image", "og:image", - Utils.AbsoluteWebRoot.AbsoluteUri + - Post.FirstImgSrc.TrimStart('/')); + base.AddMetaProperty( + "image", "og:image", + Post.FirstImgSrc.TrimStart() + .StartsWith("http", StringComparison.InvariantCultureIgnoreCase) + ? Post.FirstImgSrc.Trim() + : Utils.AbsoluteWebRoot.AbsoluteUri + + Post.FirstImgSrc.TrimStart('/')); base.AddMetaProperty("og:type", "article"); base.AddMetaProperty("article:published_time", Post.DateCreated.ToString("O")); base.AddMetaProperty("article:modified_time", Post.DateModified.ToString("O"));