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; 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.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); })(); diff --git a/BlogEngine/BlogEngine.NET/post.aspx.cs b/BlogEngine/BlogEngine.NET/post.aspx.cs index ec8827dbf..b105a800c 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,27 +216,40 @@ 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; - 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", + 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")); + } + + /// + /// 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"; @@ -240,7 +257,7 @@ private void AddMetaKeywords() } } - public Post Post; + public Post Post; public static bool ShowBlogengineComments {