public override AnalyzeResult Analyse(IPageData pageData) { var result = new AnalyzeResult(); var url = new Uri(pageData.Url); if (url.AbsolutePath == "" || url.AbsolutePath == "/") { result.AddResultRule("root_node", ResultType.Success); } else { var keywordUrl = pageData.Focuskeyword.UrlFriendly(); if (url.AbsolutePath.Contains(keywordUrl)) { result.AddResultRule("url_contains_keyword", ResultType.Success); } else { result.AddResultRule("url_doesnt_contain_keyword", ResultType.Hint); } } return(result); }
private void AnalyzeTitleTag(HtmlNode titleTag, AnalyzeResult result) { var titleValue = titleTag.InnerText; if (string.IsNullOrWhiteSpace(titleValue)) { result.AddResultRule("no_title_value", ResultType.Error); } else { titleValue = titleValue.Trim(); if (titleValue.Length > 60) { result.AddResultRule("title_too_long", ResultType.Warning); } if (titleValue.Length < 5) { result.AddResultRule("titleanalyzer_title_too_short", ResultType.Hint); } if (titleValue.Length <= 60 && titleValue.Length >= 5) { result.AddResultRule("title_success", ResultType.Success); } } }
public override AnalyzeResult Analyse(HtmlNode document, params object[] additionalValues) { var url = additionalValues[0].ToString(); string encoding = null; var request = (HttpWebRequest)WebRequest.Create(url); request.Method = "GET"; request.Headers.Add("Accept-Encoding", "gzip,deflate"); using (var response = request.GetResponse() as HttpWebResponse) { if (response != null) { encoding = response.ContentEncoding; } } var result = new AnalyzeResult { Alias = "gzipanalyzer" }; if (encoding == "gzip") { result.AddResultRule("gzipanalyzer_gzip_enabled", ResultType.Success); } else { result.AddResultRule("gzipanalyzer_gzip_disabled", ResultType.Hint); } return(result); }
public override AnalyzeResult Analyse(HtmlNode document, params object[] additionalValues) { var result = new AnalyzeResult { Alias = "imagetaganalyzer" }; var imageTags = HtmlHelper.GetElements(document, "img"); var imageTagCount = imageTags.Count(); var imagesWithAltTagCount = imageTags.Count(x => HtmlHelper.GetAttribute(x, "alt") != null && !string.IsNullOrWhiteSpace(HtmlHelper.GetAttribute(x, "alt").Value)); if (imageTagCount > imagesWithAltTagCount) { result.AddResultRule("imagetaganalyzer_missing_alt_tags", ResultType.Warning); } var imagesWithTitleTagCount = imageTags.Count(x => HtmlHelper.GetAttribute(x, "title") != null && !string.IsNullOrWhiteSpace(HtmlHelper.GetAttribute(x, "title").Value)); if (imageTagCount > imagesWithTitleTagCount) { result.AddResultRule("imagetaganalyzer_missing_title_tags", ResultType.Hint); } if (imageTagCount == imagesWithAltTagCount && imageTagCount == imagesWithTitleTagCount) { result.AddResultRule("imagetaganalyzer_alt_and_title_tags_present", ResultType.Success); } return(result); }
private void AnalyzeMetaDescriptionAttribute(HtmlAttribute metaDescriptionAttribute, AnalyzeResult result) { var descriptionValue = metaDescriptionAttribute.Value; if (string.IsNullOrWhiteSpace(descriptionValue)) { result.AddResultRule("no_description_value", ResultType.Error); } else { descriptionValue = descriptionValue.Trim(); if (descriptionValue.Length > 150) { result.AddResultRule("description_too_long", ResultType.Warning); } if (descriptionValue.Length < 20) { result.AddResultRule("description_too_short", ResultType.Warning); } if (descriptionValue.Length < 50) { result.AddResultRule("description_too_short", ResultType.Hint); } if (descriptionValue.Length <= 150 && descriptionValue.Length >= 20) { result.AddResultRule("description_perfect", ResultType.Success); } } }
private void AnalyzeMetaTags(IEnumerable <HtmlNode> metaTags, AnalyzeResult result) { var attributeValues = from metaTag in metaTags let attribute = metaTag.GetAttribute("name") where attribute != null where attribute.Value == "description" select metaTag.GetAttribute("content"); if (!attributeValues.Any()) { result.AddResultRule("no_meta_description_tag", ResultType.Error); } else if (attributeValues.Count() > 1) { result.AddResultRule("multiple_meta_description_tags", ResultType.Error); } else { var firstMetaDescriptionAttribute = attributeValues.FirstOrDefault(); if (firstMetaDescriptionAttribute != null) { AnalyzeMetaDescriptionAttribute(firstMetaDescriptionAttribute, result); } } }
private void AnalyzeMetaTags(IEnumerable <HtmlNode> metaTags, AnalyzeResult result) { var attributeValues = from metaTag in metaTags let attribute = metaTag.GetAttribute("name") where attribute != null where attribute.Value == "keywords" select metaTag.GetAttribute("content"); if (!attributeValues.Any()) { result.AddResultRule("no_meta_keywords_tag", ResultType.Hint); } else if (attributeValues.Count() > 1) { result.AddResultRule("multiple_meta_keywords_tags", ResultType.Warning); } else { var firstMetaKeywordsTag = attributeValues.FirstOrDefault(); if (firstMetaKeywordsTag != null) { AnalyzeMetaKeywordsAttribute(firstMetaKeywordsTag, result); } } }
public override AnalyzeResult Analyse(HtmlNode document, params object[] additionalValues) { var result = new AnalyzeResult { Alias = "keywordurlanalyzer" }; var keyword = additionalValues[0].ToString(); var urlString = additionalValues[1].ToString(); var url = new Uri(urlString); if (url.AbsolutePath == "" || url.AbsolutePath == "/") { result.AddResultRule("keywordurlanalyzer_root_node", ResultType.Success); } else { var keywordUrl = keyword.Alias(); if (url.AbsolutePath.Contains(keywordUrl)) { result.AddResultRule("keywordurlanalyzer_url_contains_keyword", ResultType.Success); } else { result.AddResultRule("keywordurlanalyzer_url_doesnt_contain_keyword", ResultType.Hint); } } return(result); }
public override AnalyzeResult Analyse(HtmlNode document, string focuskeyword, string urlString) { var result = new AnalyzeResult { Alias = "keywordurlanalyzer" }; var url = new Uri(urlString); if (url.AbsolutePath == "" || url.AbsolutePath == "/") { result.AddResultRule("keywordurlanalyzer_root_node", ResultType.Success); } else { var keywordUrl = focuskeyword.Alias(); if (url.AbsolutePath.Contains(keywordUrl)) { result.AddResultRule("keywordurlanalyzer_url_contains_keyword", ResultType.Success); } else { result.AddResultRule("keywordurlanalyzer_url_doesnt_contain_keyword", ResultType.Hint); } } return(result); }
public override AnalyzeResult Analyse(IPageData pageData) { var result = new AnalyzeResult(); var titleTag = _htmlTagHelper.GetTitleTag(pageData.Document, result); if (titleTag != null) { var titleText = titleTag.InnerText; var position = titleText.IndexOf(pageData.Focuskeyword, StringComparison.InvariantCultureIgnoreCase); if (position >= 0) { if (position < 10) { result.AddResultRule("title_contains_keyword", ResultType.Success); } else { result.AddResultRule("title_not_in_front", ResultType.Hint); } } else { result.AddResultRule("title_doesnt_contain_keyword", ResultType.Warning); } } return(result); }
private void AnalyzeMetaKeywordsAttribute(HtmlAttribute metaKeywordsTag, AnalyzeResult result) { var keywordsValue = metaKeywordsTag.Value; if (string.IsNullOrWhiteSpace(keywordsValue)) { result.AddResultRule("no_keywords_value", ResultType.Hint); } else { result.AddResultRule("keywords_set", ResultType.Success); } }
private static void AnalyzeTag(string tagValue, AnalyzeResult result, string tag) { if (tagValue.Contains("none")) { result.AddResultRule("metarobotsanalyzer_" + tag + "_none", ResultType.Error); } if (tagValue.Contains("noindex")) { result.AddResultRule("metarobotsanalyzer_" + tag + "_no_index", ResultType.Error); } if (tagValue.Contains("nofollow")) { result.AddResultRule("metarobotsanalyzer_" + tag + "_no_follow", ResultType.Warning); } if (tagValue.Contains("nosnippet")) { result.AddResultRule("metarobotsanalyzer_" + tag + "_no_snippet", ResultType.Information); } if (tagValue.Contains("noodp")) { result.AddResultRule("metarobotsanalyzer_" + tag + "_no_odp", ResultType.Information); } if (tagValue.Contains("noarchive")) { result.AddResultRule("metarobotsanalyzer_" + tag + "_no_archive", ResultType.Information); } if (tagValue.Contains("unavailable_after")) { result.AddResultRule("metarobotsanalyzer_" + tag + "_unavailable_after", ResultType.Information); } if (tagValue.Contains("noimageindex")) { result.AddResultRule("metarobotsanalyzer_" + tag + "_no_image_index", ResultType.Information); } }
public override AnalyzeResult Analyse(HtmlNode document, params object[] additionalValues) { var result = new AnalyzeResult { Alias = "keywordmetadescriptionanalyzer" }; var metaTags = HtmlHelper.GetElements(document, "meta"); var keyword = additionalValues[0].ToString(); if (!metaTags.Any()) { result.AddResultRule("keywordmetadescriptionanalyzer_no_meta_tags", ResultType.Error); } else { var attributeValues = from metaTag in metaTags let attribute = HtmlHelper.GetAttribute(metaTag, "name") where attribute != null where attribute.Value == "description" select HtmlHelper.GetAttribute(metaTag, "content"); if (!attributeValues.Any()) { result.AddResultRule("keywordmetadescriptionanalyzer_no_meta_description_tag", ResultType.Warning); } else if (attributeValues.Count() > 1) { result.AddResultRule("keywordmetadescriptionanalyzer_multiple_meta_description_tags", ResultType.Warning); } else { var firstMetaDescriptionTag = attributeValues.FirstOrDefault(); if (firstMetaDescriptionTag != null) { var descriptionValue = firstMetaDescriptionTag.Value; if (descriptionValue.IndexOf(keyword, StringComparison.InvariantCultureIgnoreCase) >= 0) { result.AddResultRule("keywordmetadescriptionanalyzer_meta_description_contains_keyword", ResultType.Success); } else { result.AddResultRule("keywordmetadescriptionanalyzer_meta_description_doesnt_contain_keyword", ResultType.Hint); } } } } return(result); }
public override AnalyzeResult Analyse(HtmlNode document, string focuskeyword, string url) { var result = new AnalyzeResult { Alias = "metakeywordanalyzer" }; var metaTags = HtmlHelper.GetElements(document, "meta"); if (!metaTags.Any()) { result.AddResultRule("metakeywordanalyzer_no_meta_tags", ResultType.Error); } else { var attributeValues = from metaTag in metaTags let attribute = HtmlHelper.GetAttribute(metaTag, "name") where attribute != null where attribute.Value == "keywords" select HtmlHelper.GetAttribute(metaTag, "content"); if (!attributeValues.Any()) { result.AddResultRule("metakeywordanalyzer_no_meta_keywords_tag", ResultType.Hint); } else if (attributeValues.Count() > 1) { result.AddResultRule("metakeywordanalyzer_multiple_meta_keywords_tags", ResultType.Warning); } else { var firstMetaKeywordsTag = attributeValues.FirstOrDefault(); if (firstMetaKeywordsTag != null) { var keywordsValue = firstMetaKeywordsTag.Value; if (string.IsNullOrWhiteSpace(keywordsValue)) { result.AddResultRule("metakeywordanalyzer_no_keywords_value", ResultType.Hint); } else { result.AddResultRule("metakeywordanalyzer_keywords_set", ResultType.Success); } } } } return(result); }
public override AnalyzeResult Analyse(HtmlNode document, string focuskeyword, string url) { var result = new AnalyzeResult { Alias = "metarobotsanalyzer" }; var metaTags = HtmlHelper.GetElements(document, "meta"); if (!metaTags.Any()) { result.AddResultRule("metarobotsanalyzer_no_meta_tags", ResultType.Error); } else { var robots = from metaTag in metaTags let attribute = HtmlHelper.GetAttribute(metaTag, "name") where attribute != null where attribute.Value == "robots" select HtmlHelper.GetAttribute(metaTag, "content"); var googlebot = from metaTag in metaTags let attribute = HtmlHelper.GetAttribute(metaTag, "name") where attribute != null where attribute.Value == "googlebot" select HtmlHelper.GetAttribute(metaTag, "content"); if (!robots.Any() && !googlebot.Any()) { result.AddResultRule("metarobotsanalyzer_no_robots_tag", ResultType.Success); } else { var firstRobotTag = robots.FirstOrDefault(); if (firstRobotTag != null) { AnalyzeTag(firstRobotTag.Value, result, "robots"); } var firstGooglebotTag = googlebot.FirstOrDefault(); if (firstGooglebotTag != null) { AnalyzeTag(firstGooglebotTag.Value, result, "googlebot"); } } } return(result); }
public override AnalyzeResult Analyse(HtmlNode document, params object[] additionalValues) { var result = new AnalyzeResult { Alias = "cssminificationanalyzer" }; var url = (Uri)additionalValues[0]; var localCssFiles = HtmlHelper.GetElementsWithAttribute(document, "link", "href"). Where(x => x.Attributes.Any(y => y.Name == "rel" && y.Value == "stylesheet") && x.Attributes.Any(y => y.Name == "href" && ((y.Value.StartsWith("/") && !y.Value.StartsWith("//")) || y.Value.StartsWith(url.Host) )) ); var webClient = new WebClient(); foreach (var localCssFile in localCssFiles) { var address = HtmlHelper.GetAttribute(localCssFile, "href"); if (address != null) { var fullPath = address.Value; if (fullPath.StartsWith("/")) { fullPath = string.Format("{0}://{1}{2}", url.Scheme, url.Host, fullPath); } try { var content = webClient.DownloadString(fullPath); var totalCharacters = content.Length; var lines = content.Count(x => x == '\n'); var ratio = totalCharacters / lines; if (ratio < 200) { var resultRule = new ResultRule(); resultRule.Alias = "cssminificationanalyzer_file_not_minified"; resultRule.Type = ResultType.Hint; resultRule.Tokens.Add(address.Value); result.ResultRules.Add(resultRule); } } catch (Exception) { } } } if (!result.ResultRules.Any()) { result.AddResultRule("cssminificationanalyzer_all_minified", ResultType.Success); } return(result); }
public override AnalyzeResult Analyse(HtmlNode document, string focuskeyword, string url) { var result = new AnalyzeResult { Alias = "deprecatedtaganalyzer" }; CheckTag(document, "acronym", result); CheckTag(document, "applet", result); CheckTag(document, "basefont", result); CheckTag(document, "big", result); CheckTag(document, "center", result); CheckTag(document, "dir", result); CheckTag(document, "font", result); CheckTag(document, "frame", result); CheckTag(document, "frameset", result); CheckTag(document, "noframes", result); CheckTag(document, "strike", result); CheckTag(document, "tt", result); if (!result.ResultRules.Any()) { result.AddResultRule("deprecatedtaganalyzer_no_deprecated_tags_found", ResultType.Success); } return(result); }
public override AnalyzeResult Analyse(IPageData pageData) { var result = new AnalyzeResult(); var bodyTag = _htmlTagHelper.GetBodyTag(pageData.Document, result); if (bodyTag != null) { var bodyText = bodyTag.InnerText.Trim(); var text = Regex.Replace(bodyText.ToLower(), @"\s+", " "); var matches = Regex.Matches(text, pageData.Focuskeyword); if (matches.Count == 0) { result.AddResultRule("content_doesnt_contain_keyword", ResultType.Warning); } else { var resultRule = new ResultRule { Alias = "content_contains_keyword", Type = ResultType.Success }; resultRule.Tokens.Add(matches.Count.ToString()); result.ResultRules.Add(resultRule); } } return(result); }
public override AnalyzeResult Analyse(HtmlNode document, string focuskeyword, string url) { var result = new AnalyzeResult { Alias = "anchorTagAnalyzer" }; var anchorTags = HtmlHelper.GetElements(document, "a"); var anchorTagCount = anchorTags.Count(); var anchorWithTitleTagCount = anchorTags.Count(x => HtmlHelper.GetAttribute(x, "title") != null && !string.IsNullOrWhiteSpace(HtmlHelper.GetAttribute(x, "title").Value)); if (anchorTagCount > anchorWithTitleTagCount) { var resultRule = new ResultRule { Alias = "anchorTagAnalyzer_missing_title_tags", Type = ResultType.Hint }; var numberOfTagsMissingTitle = anchorTagCount - anchorWithTitleTagCount; resultRule.Tokens.Add(numberOfTagsMissingTitle.ToString()); result.ResultRules.Add(resultRule); } else { result.AddResultRule("anchorTagAnalyzer_all_title_tags_present", ResultType.Hint); } return(result); }
public override AnalyzeResult Analyse(IPageData pageData) { var result = new AnalyzeResult(); // Check for h1, h2, h3 and h4 var headerTagCount = 0; for (var i = 1; i <= 4; i++) { var headerTag = pageData.Document.GetElements("h" + i); headerTagCount += headerTag.Count(x => x.InnerText.ToLower().Contains(pageData.Focuskeyword)); } if (headerTagCount > 0) { var resultRule = new ResultRule { Alias = "keyword_used_in_heading", Type = ResultType.Success }; resultRule.Tokens.Add(headerTagCount.ToString()); result.ResultRules.Add(resultRule); } else { result.AddResultRule("keyword_not_used_in_heading", ResultType.Hint); } return(result); }
public override AnalyzeResult Analyse(HtmlNode document, string focuskeyword, string url) { var result = new AnalyzeResult { Alias = "keywordcontentanalyzer" }; var bodyTags = HtmlHelper.GetElements(document, "body"); if (!bodyTags.Any()) { result.AddResultRule("keywordcontentanalyzer_no_body_tag", ResultType.Warning); } else if (bodyTags.Count() > 1) { result.AddResultRule("keywordcontentanalyzer_multiple_body_tags", ResultType.Warning); } else { var bodyTag = bodyTags.FirstOrDefault(); if (bodyTag != null) { var text = Regex.Replace(bodyTag.InnerText.Trim().ToLower(), @"\s+", " "); var matches = Regex.Matches(text, focuskeyword); if (matches.Count == 0) { result.AddResultRule("keywordcontentanalyzer_content_doesnt_contain_keyword", ResultType.Warning); } else { var resultRule = new ResultRule { Alias = "keywordcontentanalyzer_content_contains_keyword", Type = ResultType.Success }; resultRule.Tokens.Add(matches.Count.ToString()); result.ResultRules.Add(resultRule); } } } return(result); }
public override AnalyzeResult Analyse(IPageData pageData) { var encoding = _encodingHelper.GetEncodingFromUrl(pageData.Url); var result = new AnalyzeResult(); if (encoding == "gzip") { result.AddResultRule("gzip_enabled", ResultType.Success); } else { result.AddResultRule("gzip_disabled", ResultType.Hint); } return(result); }
private void CheckTag(HtmlNode htmlNode, string tagname, AnalyzeResult result) { var acronymTags = htmlNode.GetElements(tagname); if (acronymTags.Any()) { result.AddResultRule(string.Format("{0}_tag_found", tagname), ResultType.Warning); } }
private HtmlNode GetSingleTag(HtmlNode document, AnalyzeResult result, string tagName) { var tags = document.GetElements(tagName); if (!tags.Any()) { result.AddResultRule("no_" + tagName + "_tag", ResultType.Error); } else if (tags.Count() > 1) { result.AddResultRule("multiple_" + tagName + "_tags", ResultType.Error); } else { return(tags.FirstOrDefault()); } return(null); }
public void CountRestultRulesByType_OnExecute_ReturnsNumberOfResultsWithType() { var analyzeResult = new AnalyzeResult(); analyzeResult.AddResultRule("code", "type1"); analyzeResult.AddResultRule("code", "type1"); analyzeResult.AddResultRule("code", "type2"); analyzeResult.AddResultRule("code", "type2"); analyzeResult.AddResultRule("code", "type2"); var type1Counter = analyzeResult.CountRestultRulesByType("type1"); var type2Counter = analyzeResult.CountRestultRulesByType("type2"); var type3Counter = analyzeResult.CountRestultRulesByType("type3"); Assert.AreEqual(2, type1Counter); Assert.AreEqual(3, type2Counter); Assert.AreEqual(0, type3Counter); }
public void AddResultRule_OnExecute_SetsTheValue() { var analyzeResult = new AnalyzeResult(); analyzeResult.AddResultRule("code", "type"); Assert.IsNotNull(analyzeResult.ResultRules); Assert.IsTrue(analyzeResult.ResultRules.Any()); Assert.IsTrue(analyzeResult.ResultRules.Count() == 1); }
private void CheckTag(HtmlNode document, string tagname, AnalyzeResult result) { var acronymTags = HtmlHelper.GetElements(document, tagname); if (acronymTags.Any()) { result.AddResultRule(string.Format("deprecatedtaganalyzer_{0}_tag_found", tagname), ResultType.Warning); } }
public override AnalyzeResult Analyse(HtmlNode document, string focuskeyword, string url) { var result = new AnalyzeResult { Alias = "titleanalyzer" }; var headTag = HtmlHelper.GetElements(document, "head"); if (headTag.Any()) { var titleTags = HtmlHelper.GetElements(headTag.First(), "title"); if (!titleTags.Any()) { result.AddResultRule("titleanalyzer_no_title_tag", ResultType.Error); } else if (titleTags.Count() > 1) { result.AddResultRule("titleanalyzer_multiple_title_tags", ResultType.Error); } else { var firstTitleTag = titleTags.FirstOrDefault(); if (firstTitleTag != null) { var titleValue = firstTitleTag.InnerText; if (string.IsNullOrWhiteSpace(titleValue)) { result.AddResultRule("titleanalyzer_no_title_value", ResultType.Error); } else { titleValue = titleValue.Trim(); if (titleValue.Length > 60) { result.AddResultRule("titleanalyzer_title_too_long", ResultType.Warning); } if (titleValue.Length < 5) { result.AddResultRule("titleanalyzer_title_too_short", ResultType.Hint); } if (titleValue.Length <= 60 && titleValue.Length >= 5) { result.AddResultRule("titleanalyzer_title_success", ResultType.Success); } } } } } else { result.AddResultRule("titleanalyzer_no_head_tag", ResultType.Error); } return(result); }
public override AnalyzeResult Analyse(IPageData pageData) { var result = new AnalyzeResult(); var metaTags = _htmlTagHelper.GetMetaTags(pageData.Document, result); if (metaTags.Any()) { var attributeValues = from metaTag in metaTags let attribute = metaTag.GetAttribute("name") where attribute != null where attribute.Value == "description" select metaTag.GetAttribute("content"); if (!attributeValues.Any()) { result.AddResultRule("no_meta_description_tag", ResultType.Warning); } else if (attributeValues.Count() > 1) { result.AddResultRule("multiple_meta_description_tags", ResultType.Warning); } else { var firstMetaDescriptionTag = attributeValues.FirstOrDefault(); if (firstMetaDescriptionTag != null) { var descriptionValue = firstMetaDescriptionTag.Value; if (descriptionValue.IndexOf(pageData.Focuskeyword, StringComparison.InvariantCultureIgnoreCase) >= 0) { result.AddResultRule("meta_description_contains_keyword", ResultType.Success); } else { result.AddResultRule("meta_description_doesnt_contain_keyword", ResultType.Hint); } } } } return(result); }
public override AnalyzeResult Analyse(HtmlNode document, params object[] additionalValues) { var result = new AnalyzeResult { Alias = "keywordtitleanalyzer" }; var titleTags = HtmlHelper.GetElements(document, "title"); var keyword = additionalValues[0].ToString(); if (!titleTags.Any()) { result.AddResultRule("keywordtitleanalyzer_no_title_tag", ResultType.Error); } else if (titleTags.Count() > 1) { result.AddResultRule("keywordtitleanalyzer_multiple_title_tags", ResultType.Error); } else { var titleText = titleTags.First().InnerText; var position = titleText.IndexOf(keyword, StringComparison.InvariantCultureIgnoreCase); if (position >= 0) { if (position < 10) { result.AddResultRule("keywordtitleanalyzer_title_contains_keyword", ResultType.Success); } else { result.AddResultRule("keywordtitleanalyzer_title_not_in_front", ResultType.Hint); } } else { result.AddResultRule("keywordtitleanalyzer_title_doesnt_contain_keyword", ResultType.Warning); } } return(result); }